Contents

szpakkamil/pagerkit

Page-based navigation for SwiftUI. A layout-aware alternative to native tab views with control over transitions, indicators, and lifecycle events.

Table of Contents

Core Architecture

  • Wraps UIPageViewController on iOS/visionOS/tvOS; uses custom SwiftUI on macOS/watchOS.
  • Configure transition durations and lifecycle events declaratively.
  • Construct pages with PKPageBuilder, which supports conditionals and platform logic.
  • Customize indicator style, alignment, orientation, and images.

Layout Control

Pages reliably within small, embedded containers without full-screen takeovers.

  • Place the pager anywhere in the view hierarchy.
  • Style page indicators with custom assets.
  • Set horizontal or vertical navigation flow programmatically.

Implementation

PagerKit components and modifiers are prefixed with PK.

Basic Usage

Minimal setup for a functional page view:

import SwiftUI
import PagerKit

struct ContentView: View {
    var body: some View {
        PKPagesView {
            PKPage { Text("First Page") }
            PKPage { Text("Second Page") }
            PKPage { Text("Third Page") }
        }
    }
}

Advanced Configuration

Enhanced configuration with custom indicators and lifecycle events:

import SwiftUI
import PagerKit

struct ContentView: View {
    @State private var currentIndex = 0

    var body: some View {
        PKPagesView {
            PKPage { Color.red }.pkPageIndicatorImage(Image(systemName: "flame"))
            PKPage { Color.blue }.pkPageIndicatorImage(Image(systemName: "drop"))
            PKPage { Color.green }.pkPageIndicatorImage(Image(systemName: "leaf"))
        }
        .pkCurrentPageIndex($currentIndex)
        .pkPageNavigationOrientation(.vertical)
        .pkPageControlIndicatorAlignment(.trailing)
        .pkPageControlIndicatorBackgroundStyle(.prominent)
        .pkPageControlIndicatorCurrentIndicatorTintColor(.white)
        .pkOnManualPageChange { index, direction in
            print("Navigated to page \(index) via \(direction)")
        }
    }
}

Modifiers

Style

  • pkPageControlIndicatorAlignment(_:): Set alignment for the page indicator control.
  • pkPageControlIndicatorBackgroundStyle(_:): Configure the background style.
  • pkPageControlIndicatorDirection(_:): Define the layout direction (horizontal/vertical).
  • pkPageIndicatorImage(_:): Provide a custom image for a page's indicator.

Logic

  • pkCurrentPageIndex(_:): Bind the current page index to a state variable.
  • pkPageNavigationOrientation(_:): Set paging orientation (horizontal/vertical).
  • pkOnManualPageChange(_:): Execute closure on manual swipes.
  • pkOnAutoPageChange(_:): Execute closure on programmatic transitions.
  • pkOnTransitionStart(:) / pkOnTransitionEnd(:): Sync UI with paging animation lifecycle.

Resources

Installation

Swift Package Manager

Add PagerKit as a package dependency in your Package.swift file. The current stable version is 1.1.1.

dependencies: [
    .package(url: "https://github.com/SzpakKamil/PagerKit.git", from: "1.1.1")
]

Agent Skill

Install the Agent Skill for AI-assisted workflows.

npx skills add https://github.com/SzpakKamil/AgentSkills --skill PagerKit

Requirements

  • Platforms: iOS 14.0+, macOS 14.0+, tvOS 14.0+, watchOS 10.0+, visionOS 1.0+
  • Tools: Swift 5.9+, Xcode 15.0+

License

PagerKit is released under the MIT license.

Package Metadata

Repository: szpakkamil/pagerkit

Default branch: main

README: README.md