Programmatic Scrolling with SwiftUI ScrollView
Article Summary
Zoltan Lippai from DoorDash cracked a problem that stumped early SwiftUI adopters: how do you programmatically scroll when Apple didn't give you the tools? His team built their own solution for iOS 13.
When DoorDash committed to SwiftUI in 2019, they hit a wall. The framework's first release lacked any API for programmatic scrolling, a core feature for forms, linked carousels, and countless UX patterns. Rather than fall back to UIKit, the team engineered a backward-compatible solution by accessing the underlying UIScrollView.
Key Takeaways
- SwiftUI 1.0 had zero programmatic scrolling support until iOS 14's ScrollViewReader
- Solution uses UIViewRepresentable to locate hidden UIScrollView in generated hierarchy
- Custom scrollAnchor modifier mimics Apple's .id() API for target identification
- Enables scroll-to-view with anchor points and pixel-perfect offset control
- Foundation unlocked snapping behavior and modal sheet gesture collaboration
DoorDash built a production-ready programmatic scrolling system for SwiftUI 1.0 by bridging to UIKit's scroll APIs, enabling complex UX patterns a year before Apple's official solution.
About This Article
SwiftUI 1.0 didn't include programmatic scrolling APIs, so DoorDash had to decide whether to go back to UIKit or build something custom to work with iOS 13.
Zoltan Lippai's team used UIViewRepresentable to access the underlying UIScrollView. They built a ScrollReader with ScrollProxyProtocol and added a scrollAnchor modifier to mark target views.
The solution worked in production and let them scroll to specific anchor points with precise offset control. It handled complex patterns like form validation scrolling and linked carousels without waiting for iOS 14's ScrollViewReader.