PagerKit Skill
Overview
This skill provides expert guidance on PagerKit, a powerful SwiftUI library for creating highly customizable and cross-platform page-based navigation. It covers everything from basic usage and dynamic page generation to advanced customization of page indicators, event handling, and best practices. Use this skill to help developers effectively implement flexible and visually rich paging experiences in their SwiftUI applications across all Apple platforms.
Agent Behavior (Follow These Rules)
- Clarify Paging Requirements: Always ascertain the user's specific needs regarding page content, indicator style, navigation flow, and platform targets before offering solutions.
- Prioritize idiomatic SwiftUI: Favor PagerKit's
PKPageBuilder and ForEach for declarative page construction, aligning with SwiftUI's design principles.
- Platform-Specific Advice: When discussing indicator images, progress, or
UIPageViewController options, always specify platform availability and correct type (UIImage vs. Image, UIPageControlProgress).
- Emphasize Modifiers: Direct users to the relevant
PKPagesView or PKPage modifiers for customization, using full modifier signatures (e.g., .pkPageNavigationOrientation(_:)).
- Contextual Code Examples: Provide concise code snippets that illustrate the recommended usage within a
PKPagesView or PKPage context.
- Highlight Cross-Platform: When possible, remind users of PagerKit's cross-platform consistency and how to handle platform-specific differences using
#if os(...) directives.
Project Settings
PagerKit's behavior is influenced by the project's deployment targets and Swift version.
- Deployment Targets: PagerKit supports iOS 14.0+, iPadOS 14.0+, macOS 14.0+, tvOS 14.0+, visionOS 1.0+, and watchOS 10.0+. Some features (e.g.,
UIPageControlProgress) are only available on specific platforms and OS versions.
- Swift Version: Requires Swift 5.9+.
If these are unknown, ask the developer to confirm them, especially when discussing platform-specific features.
Quick Decision Tree
When a developer needs PagerKit guidance, follow this decision tree:
Setting up a new pager?
- For basic installation and concepts →
references/PagerKit.md
- To define the overall pager structure →
references/PKPagesView.md
- To create individual page content →
references/PKPage.md
Generating pages dynamically from data?
- Using a collection of items →
references/ForEach.md
Controlling page flow or structure?
- Adding conditional pages (if/else) →
references/PKPageBuilder.md
- Setting horizontal or vertical navigation →
references/PKPagesView.md (.pkPageNavigationOrientation)
Customizing the page indicator (dots)?
- Changing color (active/inactive) →
references/PKPagesView.md (.pkPageControlIndicatorTintColor, .pkPageControlIndicatorCurrentIndicatorTintColor)
- Changing background style (minimal, prominent, automatic) →
references/PKPageControlBackgroundStyle.md
- Adjusting position or spacing →
references/PKPagesView.md (.pkPageControlIndicatorAlignment, .pkPageControlPadding)
- Setting layout direction (e.g., vertical alignment) →
references/PKPageControlDirection.md
- Using custom images (global or per-page) →
references/PKPagesView.md, references/PKPage.md
- Hiding the indicator (always or for single page) →
references/PKPagesView.md
Handling page change events or state?
- Binding to the current page index →
references/PKPagesView.md (.pkCurrentPageIndex)
- Reacting to manual page changes →
references/PKPagesView.md (.pkOnManualPageChange)
- Reacting to automatic page changes →
references/PKPagesView.md (.pkOnAutoPageChange)
- Identifying page transition direction →
references/PKPageDirection.md
- Actions on transition start/end →
references/PKPagesView.md
Customizing individual page behavior?
- Setting automatic transition duration →
references/PKPage.md (.pkPageDuration)
- Adding a custom footer to a page →
references/PKPage.md (.pkPageFooter)
Triage-First Playbook
- "My pages are not showing or look incorrect."
- Verify
PKPagesView contains valid PKPage instances. Refer to references/PKPagesView.md, references/PKPage.md.
- If using dynamic content, check
ForEach implementation. Refer to references/ForEach.md.
- "The page indicator is not positioned or styled correctly."
- Examine
.pkPageControlIndicatorAlignment, .pkPageControlIndicatorBackgroundStyle, .pkPageControlIndicatorDirection modifiers on PKPagesView. Refer to references/PKPagesView.md, references/PKPageControlBackgroundStyle.md, references/PKPageControlDirection.md.
- "I want to change the color of the active dot, but it's not working."
- Ensure
.pkPageControlIndicatorCurrentIndicatorTintColor(_:) is used on PKPagesView. Refer to references/PKPagesView.md.
- "Pages are not transitioning automatically."
- Check if
.pkPageDuration(_:) is applied to the individual PKPages with a non-nil duration. Refer to references/PKPage.md.
- "My conditional logic (
if statements) inside PKPagesView is giving compiler errors."
- Review
PKPageBuilder concepts, ensuring all branches return valid PKPage components. Refer to references/PKPageBuilder.md.
- "How can I tell if the user swiped forward or backward?"
- Use the
PKPageDirection parameter in .pkOnManualPageChange. Refer to references/PKPagesView.md, references/PKPageDirection.md.
Core Patterns Reference
Basic Pager Setup
PKPagesView {
PKPage { Text("Page A").font(.title) }
PKPage { Text("Page B").font(.title) }
PKPage { Text("Page C").font(.title) }
}
.pkCurrentPageIndex(index: $currentPage) // Bind to @State
.pkPageNavigationOrientation(.horizontal)
Dynamic Pages with ForEach
struct Item: Identifiable {
let id = UUID()
let title: String
}
// ... inside a View
let items = [Item(title: "Item 1"), Item(title: "Item 2")]
PKPagesView {
ForEach(items) { item in
PKPage { Text(item.title) }
.pkPageFooter { Text("Footer for \(item.title)") }
}
}
Custom Page Indicator Styling
.pkPageControlIndicatorAlignment(spacing: 10, alignment: .bottomTrailing)
.pkPageControlIndicatorBackgroundStyle(.prominent)
.pkPageControlIndicatorDirection(.topToBottom) // Vertical dots
.pkPageControlIndicatorTintColor(.gray)
.pkPageControlIndicatorCurrentIndicatorTintColor(.blue)
// Custom images
#if os(iOS)
.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image: UIImage(systemName: "star.fill"))
#else
.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image: Image(systemName: "star.fill"))
#endif
Handling Page Change Events
.pkOnManualPageChange { currentIndex, direction in
print("User navigated to page \(currentIndex) by going \(direction).")
}
.pkOnAutoPageChange { previousIndex, currentIndex in
print("Auto change from \(previousIndex) to \(currentIndex).")
}
.pkOnTransitionEnd { previous, current in
print("Transition ended. Was on \(previous), now on \(current).")
}
Integration Quick Guide
PagerKit is integrated via Swift Package Manager.
- Add Package Dependency: In Xcode, go to File > Add Package Dependency and enter
https://github.com/SzpakKamil/PagerKit.git.
- Import:
import PagerKit in your Swift files.
- Deployment Targets: Ensure your project targets iOS 14.0+, iPadOS 14.0+, macOS 14.0+, tvOS 14.0+, visionOS 1.0+, or watchOS 10.0+ (Swift 5.9+).
For detailed setup, see references/PagerKit.md.
Reference Files
Load these files as needed for specific topics:
PagerKit.md - General overview, setup, and core benefits.
PKPagesView.md - Detailed information on the main pager container and its global modifiers.
PKPage.md - Information on individual page creation and page-specific modifiers.
ForEach.md - How to generate pages from collections of data.
PKPageBuilder.md - Understanding the declarative content building for PKPagesView.
PKPageControlBackgroundStyle.md - Options for the background style of the page indicator.
PKPageControlDirection.md - Options for the layout direction of the page indicator dots.
PKPageDirection.md - Understanding the direction of page transitions.
_index.md - A comprehensive index for all PagerKit reference documentation.
Best Practices Summary
- Embrace Declarative UI: Use
PKPageBuilder with ForEach for flexible and maintainable page construction.
- Customize Thoughtfully: Leverage the extensive modifier API to match native platform aesthetics and app branding, avoiding over-customization that hinders usability.
- Manage Pager State: Always bind
pkCurrentPageIndex to external state (@State or @Binding) for programmatic control and observation.
- Implement Event Handling: Utilize callbacks (e.g.,
.pkOnManualPageChange, .pkOnTransitionEnd) for analytics, haptic feedback, or custom logic in response to navigation.
- Mind Platform Differences: Be aware of modifiers and features that behave differently or are only available on specific Apple platforms and OS versions.
- Prioritize Accessibility: Ensure custom indicators and footers remain accessible (e.g., with VoiceOver support).
Note: This skill is based on the comprehensive documentation for PagerKit. For further details, visit the official documentation at documentation.kamilszpak.com/documentation/pagerkit/ or the project website at kamilszpak.com/pl/pagerkit.
1---2name: pagerkit3description: Expert guidance on PagerKit, a SwiftUI library for advanced, customizable page-based navigation. Use when developers mention: (1) PagerKit, PKPagesView, PKPage, (2) custom page controls, indicators, or paging behavior, (3) cross-platform SwiftUI paging, (4) dynamic page generation, (5) integrating page views into custom layouts, (6) specific PagerKit modifiers or enums, (7) page view controller options, (8) event handling for page changes.4---5# PagerKit Skill
6
7## Overview
8
9This skill provides expert guidance on `PagerKit`, a powerful SwiftUI library for creating highly customizable and cross-platform page-based navigation. It covers everything from basic usage and dynamic page generation to advanced customization of page indicators, event handling, and best practices. Use this skill to help developers effectively implement flexible and visually rich paging experiences in their SwiftUI applications across all Apple platforms.
10
11## Agent Behavior (Follow These Rules)
12
131. **Clarify Paging Requirements:** Always ascertain the user's specific needs regarding page content, indicator style, navigation flow, and platform targets before offering solutions.
142. **Prioritize idiomatic SwiftUI:** Favor PagerKit's `PKPageBuilder` and `ForEach` for declarative page construction, aligning with SwiftUI's design principles.
153. **Platform-Specific Advice:** When discussing indicator images, progress, or `UIPageViewController` options, always specify platform availability and correct type (`UIImage` vs. `Image`, `UIPageControlProgress`).
164. **Emphasize Modifiers:** Direct users to the relevant `PKPagesView` or `PKPage` modifiers for customization, using full modifier signatures (e.g., `.pkPageNavigationOrientation(_:)`).
175. **Contextual Code Examples:** Provide concise code snippets that illustrate the recommended usage within a `PKPagesView` or `PKPage` context.
186. **Highlight Cross-Platform:** When possible, remind users of PagerKit's cross-platform consistency and how to handle platform-specific differences using `#if os(...)` directives.
19
20## Project Settings
21
22PagerKit's behavior is influenced by the project's deployment targets and Swift version.
23
24- **Deployment Targets:** PagerKit supports iOS 14.0+, iPadOS 14.0+, macOS 14.0+, tvOS 14.0+, visionOS 1.0+, and watchOS 10.0+. Some features (e.g., `UIPageControlProgress`) are only available on specific platforms and OS versions.
25- **Swift Version:** Requires Swift 5.9+.
26
27If these are unknown, ask the developer to confirm them, especially when discussing platform-specific features.
28
29## Quick Decision Tree
30
31When a developer needs PagerKit guidance, follow this decision tree:
32
331. **Setting up a new pager?**
34 * For basic installation and concepts → `references/PagerKit.md`
35 * To define the overall pager structure → `references/PKPagesView.md`
36 * To create individual page content → `references/PKPage.md`
37
382. **Generating pages dynamically from data?**
39 * Using a collection of items → `references/ForEach.md`
40
413. **Controlling page flow or structure?**
42 * Adding conditional pages (if/else) → `references/PKPageBuilder.md`
43 * Setting horizontal or vertical navigation → `references/PKPagesView.md` (`.pkPageNavigationOrientation`)
44
454. **Customizing the page indicator (dots)?**
46 * Changing color (active/inactive) → `references/PKPagesView.md` (`.pkPageControlIndicatorTintColor`, `.pkPageControlIndicatorCurrentIndicatorTintColor`)
47 * Changing background style (minimal, prominent, automatic) → `references/PKPageControlBackgroundStyle.md`
48 * Adjusting position or spacing → `references/PKPagesView.md` (`.pkPageControlIndicatorAlignment`, `.pkPageControlPadding`)
49 * Setting layout direction (e.g., vertical alignment) → `references/PKPageControlDirection.md`
50 * Using custom images (global or per-page) → `references/PKPagesView.md`, `references/PKPage.md`
51 * Hiding the indicator (always or for single page) → `references/PKPagesView.md`
52
535. **Handling page change events or state?**
54 * Binding to the current page index → `references/PKPagesView.md` (`.pkCurrentPageIndex`)
55 * Reacting to manual page changes → `references/PKPagesView.md` (`.pkOnManualPageChange`)
56 * Reacting to automatic page changes → `references/PKPagesView.md` (`.pkOnAutoPageChange`)
57 * Identifying page transition direction → `references/PKPageDirection.md`
58 * Actions on transition start/end → `references/PKPagesView.md`
59
606. **Customizing individual page behavior?**
61 * Setting automatic transition duration → `references/PKPage.md` (`.pkPageDuration`)
62 * Adding a custom footer to a page → `references/PKPage.md` (`.pkPageFooter`)
63
64## Triage-First Playbook
65
66- **"My pages are not showing or look incorrect."**
67 * Verify `PKPagesView` contains valid `PKPage` instances. Refer to `references/PKPagesView.md`, `references/PKPage.md`.
68 * If using dynamic content, check `ForEach` implementation. Refer to `references/ForEach.md`.
69- **"The page indicator is not positioned or styled correctly."**
70 * Examine `.pkPageControlIndicatorAlignment`, `.pkPageControlIndicatorBackgroundStyle`, `.pkPageControlIndicatorDirection` modifiers on `PKPagesView`. Refer to `references/PKPagesView.md`, `references/PKPageControlBackgroundStyle.md`, `references/PKPageControlDirection.md`.
71- **"I want to change the color of the active dot, but it's not working."**
72 * Ensure `.pkPageControlIndicatorCurrentIndicatorTintColor(_:)` is used on `PKPagesView`. Refer to `references/PKPagesView.md`.
73- **"Pages are not transitioning automatically."**
74 * Check if `.pkPageDuration(_:)` is applied to the individual `PKPage`s with a non-nil duration. Refer to `references/PKPage.md`.
75- **"My conditional logic (`if` statements) inside `PKPagesView` is giving compiler errors."**
76 * Review `PKPageBuilder` concepts, ensuring all branches return valid `PKPage` components. Refer to `references/PKPageBuilder.md`.
77- **"How can I tell if the user swiped forward or backward?"**
78 * Use the `PKPageDirection` parameter in `.pkOnManualPageChange`. Refer to `references/PKPagesView.md`, `references/PKPageDirection.md`.
79
80## Core Patterns Reference
81
82### Basic Pager Setup
83
84```swift
85PKPagesView {
86 PKPage { Text("Page A").font(.title) }
87 PKPage { Text("Page B").font(.title) }
88 PKPage { Text("Page C").font(.title) }
89}
90.pkCurrentPageIndex(index: $currentPage) // Bind to @State
91.pkPageNavigationOrientation(.horizontal)
92```
93
94### Dynamic Pages with ForEach
95
96```swift
97struct Item: Identifiable {
98 let id = UUID()
99 let title: String
100}
101
102// ... inside a View
103let items = [Item(title: "Item 1"), Item(title: "Item 2")]
104
105PKPagesView {
106 ForEach(items) { item in
107 PKPage { Text(item.title) }
108 .pkPageFooter { Text("Footer for \(item.title)") }
109 }
110}
111```
112
113### Custom Page Indicator Styling
114
115```swift
116.pkPageControlIndicatorAlignment(spacing: 10, alignment: .bottomTrailing)
117.pkPageControlIndicatorBackgroundStyle(.prominent)
118.pkPageControlIndicatorDirection(.topToBottom) // Vertical dots
119.pkPageControlIndicatorTintColor(.gray)
120.pkPageControlIndicatorCurrentIndicatorTintColor(.blue)
121// Custom images
122#if os(iOS)
123.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image: UIImage(systemName: "star.fill"))
124#else
125.pkPageControlIndicatorPreferredCurrentPageIndicatorImage(image: Image(systemName: "star.fill"))
126#endif
127```
128
129### Handling Page Change Events
130
131```swift
132.pkOnManualPageChange { currentIndex, direction in
133 print("User navigated to page \(currentIndex) by going \(direction).")
134}
135.pkOnAutoPageChange { previousIndex, currentIndex in
136 print("Auto change from \(previousIndex) to \(currentIndex).")
137}
138.pkOnTransitionEnd { previous, current in
139 print("Transition ended. Was on \(previous), now on \(current).")
140}
141```
142
143## Integration Quick Guide
144
145PagerKit is integrated via Swift Package Manager.
146
1471. **Add Package Dependency**: In Xcode, go to **File > Add Package Dependency** and enter `https://github.com/SzpakKamil/PagerKit.git`.
1482. **Import**: `import PagerKit` in your Swift files.
1493. **Deployment Targets**: Ensure your project targets iOS 14.0+, iPadOS 14.0+, macOS 14.0+, tvOS 14.0+, visionOS 1.0+, or watchOS 10.0+ (Swift 5.9+).
150
151For detailed setup, see `references/PagerKit.md`.
152
153## Reference Files
154
155Load these files as needed for specific topics:
156
157- **`PagerKit.md`** - General overview, setup, and core benefits.
158- **`PKPagesView.md`** - Detailed information on the main pager container and its global modifiers.
159- **`PKPage.md`** - Information on individual page creation and page-specific modifiers.
160- **`ForEach.md`** - How to generate pages from collections of data.
161- **`PKPageBuilder.md`** - Understanding the declarative content building for `PKPagesView`.
162- **`PKPageControlBackgroundStyle.md`** - Options for the background style of the page indicator.
163- **`PKPageControlDirection.md`** - Options for the layout direction of the page indicator dots.
164- **`PKPageDirection.md`** - Understanding the direction of page transitions.
165- **`_index.md`** - A comprehensive index for all PagerKit reference documentation.
166
167## Best Practices Summary
168
1691. **Embrace Declarative UI**: Use `PKPageBuilder` with `ForEach` for flexible and maintainable page construction.
1702. **Customize Thoughtfully**: Leverage the extensive modifier API to match native platform aesthetics and app branding, avoiding over-customization that hinders usability.
1713. **Manage Pager State**: Always bind `pkCurrentPageIndex` to external state (`@State` or `@Binding`) for programmatic control and observation.
1724. **Implement Event Handling**: Utilize callbacks (e.g., `.pkOnManualPageChange`, `.pkOnTransitionEnd`) for analytics, haptic feedback, or custom logic in response to navigation.
1735. **Mind Platform Differences**: Be aware of modifiers and features that behave differently or are only available on specific Apple platforms and OS versions.
1746. **Prioritize Accessibility**: Ensure custom indicators and footers remain accessible (e.g., with VoiceOver support).
175
176
177**Note**: This skill is based on the comprehensive documentation for PagerKit. For further details, visit the official documentation at [documentation.kamilszpak.com/documentation/pagerkit/](https://documentation.kamilszpak.com/documentation/pagerkit/) or the project website at [kamilszpak.com/pl/pagerkit](https://kamilszpak.com/pl/pagerkit).