DoorDash Jul 21, 2022

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

Critical Insight

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.

The article includes full code samples and hints at follow-up posts covering SwiftUI animation support and advanced snapping behavior that goes beyond Apple's implementation.

About This Article

Problem

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.

Solution

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.

Impact

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.

Recent from DoorDash

Related Articles