A SwiftUI pager view for programmatic navigation with customizable transitions. Ideal for onboarding screens and multi-step forms requiring fine-grained control.
- ποΈ Programmatic navigation via index binding
- π Customizable forward/backward transitions
- π Optional looping
- π§© Dynamic content handling
- π Fine-grained navigation control
- π¨ Customizable indicator styling and gestures
- Can't disable drag gesture
- Can't customize page indicator
- Limited transition customization
- Complex navigation logic for conditional views
- Poor interaction with nested vertical scroll views
- π Simple index-based navigation
- π Effortless conditional view support
- β¨ Custom SwiftUI transitions and animations
- π± Ideal for guided user flows
dependencies: [
.package(url: "https://github.com/JPToroDev/ProgrammaticPageView.git", from: "1.0.0")
]Or add it via Xcode by going to File > Add Packages⦠and entering the repository URL.
import SwiftUI
import ProgrammaticPageView
struct OnboardingView: View {
@State private var pageIndex = 0
@State private var hasAcceptedTerms = false
var body: some View {
PageView(index: $pageIndex) {
VStack {
Text("Welcome!")
Button("Next") { pageIndex += 1 }
.buttonStyle(.borderedProminent)
}
List {
Text("Please accept terms and conditions.")
Toggle("Accept Terms", isOn: $hasAcceptedTerms)
Section {
Button("Next") { pageIndex += 1 }
.disabled(!hasAcceptedTerms)
}
}
VStack {
Text("All Set!")
Button("Get Started") {
// Proceed to main app
}
}
}
.pageViewIndicatorVisibility(.visible)
.pageViewIndicatorIndexSymbol("square.fill", size: .large)
.pageViewIndicatorStyle(.progressBar)
.pageViewIndicatorBackgroundStyle(.blue)
.pageViewIndicatorOffset(20)
}
}public init(
index: Binding<Int>,
loops: Bool = false,
@ViewBuilder content: () -> Content
)
public init(
index: Binding<Int>,
loops: Bool = false,
@ViewBuilder content: () -> Content,
@ViewBuilder indicator: @escaping (PageViewIndicator) -> Indicator
)index: A binding to the current page index.loops: Set totrueto enable looping from the last page to the first.content: A view builder that returns the views for each page.indicator: A view builder that takes aPageViewIndicatorand returns a custom indicator view. Use this to directly modify or replace the default indicator.
The first initializer creates a PageView with default indicator behavior controlled by pageViewIndicatorVisibility().
The second initializer allows for a custom indicator view to be provided.
pageTransition(forward: AnyTransition, backward: AnyTransition, animation: Animation? = .default) -> SelfSets custom transitions for page changes and an optional animation.
forward: The transition to use when moving to the next page.backward: The transition to use when moving to the previous page.animation: An optional animation to apply to the page transitions.
pageTransition(_ transition: AnyTransition? = nil, animation: Animation? = .default) -> SelfSets a single transition for both forward and backward page changes and an optional animation.
transition: The transition to use for both forward and backward page changes. Ifnil, the default transition is used.animation: An optional animation to apply to the page transition.
defaultPage(_ page: Page) -> SelfSets the default page without animation. This will be overridden if index is not zero.
page:.firstor.last.
pageViewFeedback(_ feedback: SensoryFeedback?) -> SelfSets the haptic feedback for page transitions in the page view.
feedback: The haptic feedback to play when the current page changes. Set tonilto disable feedback.
pageViewIndicatorVisibility(_ visibility: Visibility) -> SelfConfigures the page view indicator's visibility.
visibility: Determines whether the indicator is visible.
pageViewIndicatorStyle(_ style: PageViewIndicatorStyle) -> SelfSets the visual style of the page view indicator.
style: The style to apply to the page view indicator.
pageViewIndicatorDragNavigation(_ draggability: PageViewIndicatorDraggability) -> SelfConfigures drag navigation for the page view indicator.
draggability: A value that determines whether drag navigation is enabled or disabled.
pageViewIndicatorIndexSymbol(_ symbol: String = "circle.fill", size: PageViewIndexSize = .regular, spacing: PageViewIndicatorSymbolSpacing = .automatic) -> SelfConfigures the page view indicator's symbol, size, and spacing.
symbol: The SF Symbol name to use for page indicators. Default is "circle.fill".size: The size of the page indicator symbols. Default is.regular.spacing: The spacing between page indicator symbols. Default is.automatic.
pageViewIndicatorBackgroundStyle<S: ShapeStyle>(_ style: S) -> SelfSets a custom background style for the page view indicator.
style: A shape style to be used as the background for the indicator.
pageViewIndicatorBackgroundStyle(_ style: ExpressibleByNilLiteral?) -> SelfRemoves the background style from the page view indicator.
style: Passnilto remove the background.
pageViewIndicatorOffset(_ offset: CGFloat) -> SelfSets the vertical offset of the page view indicator from the bottom of the view.
offset: The distance in points to offset the indicator from the bottom.
pageViewIndicatorTapAction(_ action: @escaping () -> Void) -> SelfConfigures a tap action for the page view indicator.
action: A closure to be executed when the page view indicator is tapped.
pageViewIndicatorLongPressAction(_ action: @escaping () -> Void) -> SelfConfigures a long press action for the page view indicator.
action: A closure to be executed when the page view indicator is long-pressed.
This project is licensed under the MIT License.
Contributions are welcome! Please open an issue or submit a pull request.
For questions or suggestions, please open an issue on GitHub.
