fix(store): read scrollOffset from ScrollView background to prevent geometry loss during cell recycling
This commit is contained in:
@@ -59,7 +59,6 @@ struct StoreDetailView: View {
|
||||
|
||||
ScrollView(showsIndicators: false) {
|
||||
LazyVStack(spacing: 0) {
|
||||
ScrollOffsetReader(offsetY: $scrollOffset)
|
||||
topSection
|
||||
Section {
|
||||
sectionedProducts
|
||||
@@ -68,8 +67,22 @@ struct StoreDetailView: View {
|
||||
.opacity(Double(1 - stickyProgress))
|
||||
}
|
||||
}
|
||||
.background(
|
||||
GeometryReader { geometry in
|
||||
Color.clear.preference(
|
||||
key: ScrollOffsetPreferenceKey.self,
|
||||
value: geometry.frame(in: .named(StoreDetailScrollCoordinateSpace.name)).minY
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
.coordinateSpace(name: StoreDetailScrollCoordinateSpace.name)
|
||||
.onPreferenceChange(ScrollOffsetPreferenceKey.self) { minY in
|
||||
let normalizedOffset = max(0, -minY)
|
||||
if abs(scrollOffset - normalizedOffset) > 0.5 {
|
||||
scrollOffset = normalizedOffset
|
||||
}
|
||||
}
|
||||
.refreshable {
|
||||
await loadStoreData(forceRefresh: true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user