From e448a04999e57e5f8ea8d6b86f442ccf4e8f99bb Mon Sep 17 00:00:00 2001 From: Pavel Holec Date: Fri, 23 Aug 2024 18:06:42 +0200 Subject: [PATCH] Fix horizontalScrollPosition index preference key update --- Sources/Orbit/Components/HorizontalScroll.swift | 1 + Sources/Orbit/Support/Layout/HorizontalScrollPosition.swift | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Sources/Orbit/Components/HorizontalScroll.swift b/Sources/Orbit/Components/HorizontalScroll.swift index bae326f2273..ed38cd3e6f9 100644 --- a/Sources/Orbit/Components/HorizontalScroll.swift +++ b/Sources/Orbit/Components/HorizontalScroll.swift @@ -105,6 +105,7 @@ public struct HorizontalScroll: View { guard let scrollTarget else { return } + scrolledItemID = scrollTarget.id scrollTo(id: scrollTarget.id, geometry: geometry, animated: scrollTarget.animated) } .onReceive(timer) { output in diff --git a/Sources/Orbit/Support/Layout/HorizontalScrollPosition.swift b/Sources/Orbit/Support/Layout/HorizontalScrollPosition.swift index 234430a7e2b..baff53d7b66 100644 --- a/Sources/Orbit/Support/Layout/HorizontalScrollPosition.swift +++ b/Sources/Orbit/Support/Layout/HorizontalScrollPosition.swift @@ -63,6 +63,8 @@ struct HorizontalScrollPositionModifierPreviews: PreviewProvider { PreviewWrapper { StateWrapper(0) { $id in VStack(alignment: .leading, spacing: .medium) { + Text("Current scroll index \(id)") + Heading("Snapping", style: .title3) HorizontalScroll(spacing: .medium, itemWidth: .ratio(0.95)) { @@ -98,6 +100,9 @@ struct HorizontalScrollPositionModifierPreviews: PreviewProvider { } } .screenLayout() + .onAppear { + id = 2 + } } } }