How to do pagination in SwiftUI
Article Summary
Medium's iOS team rebuilt their search feature in SwiftUI and needed infinite scroll. Here's the elegant pagination pattern they landed on after years of iteration.
Thomas Ricouard from Medium Engineering shares the production-ready pagination technique they use across the Medium iOS app. It's a generic, reusable approach that handles loading states, error cases, and prevents duplicate requests.
Key Takeaways
- Uses List's lazy loading with .onAppear on a progress indicator
- State management prevents duplicate fetches during scroll
- Chose .onAppear over .task to continue loading across tab switches
- Generic container view handles all states: loading, empty, error, next page
- Works with List and LazyVStack but NOT plain ScrollView
Critical Insight
A battle-tested SwiftUI pagination pattern that separates state management from content rendering and keeps working even when users navigate away.