I'm implementing a horizontal carousel in iOS 26 Beta 3 using SwiftUI ScrollView with LazyHStack. The goal is to programmatically scroll to a specific card on view load.
What I'm trying to do:
- Display a horizontal carousel of cards using ScrollView + LazyHStack
- Automatically scroll to the "current" card when the view appears
- Use iOS 26's new ScrollPosition object for programmatic scrolling
Current behavior:
- The ScrollPosition object receives scroll commands (confirmed via console logs)
- The scrollTo(id⚓ ) method executes without errors
- However, the ScrollView does not actually scroll - it remains at position 0
- Manual scrolling and scrollTargetBehavior(.viewAligned) work perfectly
Code snippet:
@State private var scrollPositionObject = ScrollPosition()
ScrollView(.horizontal) { LazyHStack(spacing: 16) { ForEach(cards, id: .id) { card in CardView(card: card) .id(card.id) } } .scrollTargetLayout() } .scrollPosition($scrollPositionObject) .scrollTargetBehavior(.viewAligned) .onAppear { let targetId = cards[currentIndex].id DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { scrollPositionObject.scrollTo(id: targetId, anchor: .center) } }
Workaround that works:
Using the iOS 17 scrollPosition(id:) binding instead of the ScrollPosition object:
@State private var scrollPosition: UUID?
.scrollPosition(id: $scrollPosition) .onAppear { scrollPosition = cards[currentIndex].id }
Environment:
- iOS 26 Beta 3
- Xcode 26 Beta 3
- Physical device (iPhone 16 Pro Max)
Is this a known issue with ScrollPosition in Beta 3, or am I missing something in the implementation? The older binding approach works fine, but I'd prefer to use the new ScrollPosition API if possible.