Before SwiftUI
came along, UIPageControl
was the obvious choice for putting together a typical paginated onboarding sequence. We can still integrate UIKit
classes into SwiftUI
easily enough, but having a first party implementation within the framework is preferable.
We sought to keep things as simple as possible with our implementation, but as you can see there’s still a fair amount of tricky state management to take care of.
At a high level, our PaginatedView
just contains an HStack
, which contains each constituent “page” of our page control. We attach a DragGesture
to the PaginatedView
, which it uses to set the appropriate index of the current page. Finally, the PaginatedView
passes data down to a DotsComponent
, which highlights the appropriate dot.