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
A battle-tested SwiftUI pagination pattern that separates state management from content rendering and keeps working even when users navigate away.
About This Article
Thomas Ricouard's team needed to add infinite scroll pagination to Medium's iOS search interface across multiple tabs. The challenge was preventing duplicate data fetches and keeping loads smooth when users switched between tabs.
They created a generic SearchResultListView container using List's lazy loading. A progress indicator with .onAppear triggers data fetches, while state transitions to loadingNextPage stop fetch tasks from retriggering during scroll.
Since SwiftUI's launch, this pattern has stayed production-ready and works across different features in Medium's iOS app. Teams no longer need separate pagination implementations for each feature or tab.