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 + } } } }