### PageView Basic Setup with Closures (SwiftUI) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Demonstrates the basic setup of PageView for dynamic page generation using next/previous closure functions. It defines a state variable for selection and builds page content dynamically. Requires SwiftUI and BigUIPaging. Handles basic integer-based page transitions. ```swift import SwiftUI import BigUIPaging struct ContentView: View { @State private var selection: Int = 1 var body: some View { PageView(selection: $selection) { value in // Return next page value (nil if no next page) value + 1 } previous: { value in // Return previous page value (nil if no previous page) value > 1 ? value - 1 : nil } content: { // Build the page content Text("Page \(value)") .font(.largeTitle) .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.blue) } .pageViewStyle(.scroll) // Enable swipe gestures } } ``` -------------------------------- ### Swift: Custom PageView Style Implementation Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Allows creation of custom page transitions and interactions by implementing the `PageViewStyle` protocol. This example demonstrates a carousel-like effect with scaled and offset previous and next pages. It requires defining a struct conforming to `PageViewStyle` and applying it to a `PageView` instance. ```swift struct CarouselPageViewStyle: PageViewStyle { func makeBody(configuration: Configuration) -> some View { GeometryReader { geometry in ZStack { let current = configuration.selection.wrappedValue // Show previous page (scaled down, behind, to the left) if let previous = configuration.previous(current) { configuration.content(previous) .scaleEffect(0.8) .offset(x: -geometry.size.width * 0.4) .opacity(0.5) .zIndex(-1) .onTapGesture { withAnimation { configuration.selection.wrappedValue = previous } } } // Current page (centered, full size) configuration.content(current) .scaleEffect(1.0) .zIndex(0) // Show next page (scaled down, behind, to the right) if let next = configuration.next(current) { configuration.content(next) .scaleEffect(0.8) .offset(x: geometry.size.width * 0.4) .opacity(0.5) .zIndex(-1) .onTapGesture { withAnimation { configuration.selection.wrappedValue = next } } } } } } } // Apply the custom style struct CarouselExampleView: View { @State private var selection: Int = 1 var body: some View { PageView(selection: $selection) { value in value + 1 } previous: { value in value > 1 ? value - 1 : nil } content: { value in Text("Item \(value)") .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.blue) .cornerRadius(20) } .pageViewStyle(CarouselPageViewStyle()) } } ``` -------------------------------- ### SwiftUI PageView Integration within NavigationStack Source: https://context7.com/notsobigcompany/biguipaging/llms.txt This Swift code demonstrates the integration of BigUIPaging's PageView within SwiftUI's NavigationStack. It showcases how to embed a PageView in a detail view that is presented via a NavigationLink, ensuring smooth functionality within a complex navigation hierarchy. The example includes a sample `Project` data structure and views for listing and detailing projects, with PageView displaying images for each project. ```swift struct AppMainView: View { var body: some View { NavigationStack { ProjectListView() } } } struct ProjectListView: View { @State private var projects: [Project] = Project.sampleProjects var body: some View { List(projects) { project in NavigationLink(project.name) { ProjectDetailView(project: project) } } .navigationTitle("Projects") } } struct ProjectDetailView: View { let project: Project @State private var selectedImage: Int = 0 var body: some View { VStack { // PageView works correctly inside NavigationStack PageView(selection: $selectedImage) { ForEach(Array(project.images.enumerated()), id: \.offset) { index, imageName in Image(imageName) .resizable() .aspectRatio(contentMode: .fit) } } .pageViewStyle(.scroll) .frame(height: 300) #if os(iOS) PageIndicator(selection: $selectedImage, total: project.images.count) .padding() #endif ScrollView { Text(project.description) .padding() } } .navigationTitle(project.name) .toolbar { ToolbarItem { PageViewNavigationButton() } } .pageViewEnvironment() // Enable toolbar navigation } } struct Project: Identifiable { let id: UUID = UUID() let name: String let description: String let images: [String] static let sampleProjects: [Project] = [ Project( name: "Architecture", description: "Beautiful building designs from around the world.", images: ["arch1", "arch2", "arch3"] ) ] } ``` -------------------------------- ### PageView Scroll Style with Orientation (SwiftUI) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Configures PageView with a scrollable style and allows setting the navigation orientation to horizontal or vertical. It also demonstrates adjusting the spacing between pages. This example uses an array of articles for content. Requires SwiftUI and BigUIPaging. ```swift struct NewsReaderView: View { @State private var currentArticle: Int = 0 let articles: [Article] = Article.sampleData var body: some View { PageView(selection: $currentArticle) { ForEach(Array(articles.enumerated()), id: \.element.id) { index, article in ScrollView { VStack(alignment: .leading, spacing: 16) { Text(article.title) .font(.title) .bold() Text(article.content) .font(.body) } .padding() } } } .pageViewStyle(.scroll) .pageViewOrientation(.vertical) // Swipe up/down instead of left/right .pageViewSpacing(20) // Gap between pages } } struct Article: Identifiable { let id: UUID = UUID() let title: String let content: String static let sampleData: [Article] = [ Article(title: "Breaking News", content: "Lorem ipsum..."), Article(title: "Technology", content: "Dolor sit amet...") ] } ``` -------------------------------- ### Add BigUIPaging Swift Package to Project Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Integrate the BigUIPaging library into your project by adding its Swift Package repository URL. This is the recommended method for dependency management. ```swift .package(url: "https://github.com/notsobigcompany/BigUIPaging.git", from: "0.0.1") ``` -------------------------------- ### Create PageView with ForEach (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Initializes a PageView using a ForEach loop to generate content for multiple pages. It requires a binding for the selection state and iterates through a range to create child views. ```swift @State private var selection: Int = 1 var body: some View { PageView(selection: $selection) { ForEach(1...10, id: \.self) { Text("Page \(value)") } } .pageViewStyle(.scroll) } ``` -------------------------------- ### Swift: Programmatic Page Navigation with Toolbar Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Enables programmatic page navigation within a PageView using toolbar buttons. It leverages environment variables like `.navigatePageView` and `.canNavigatePageView` for custom navigation controls, allowing forward and backward navigation. Dependencies include the PageView and SwiftUI. ```swift struct DocumentViewerView: View { @State private var currentPage: Int = 1 let document: [PageData] = PageData.sampleDocument var body: some View { NavigationStack { PageView(selection: $currentPage) { ForEach(document) { page in DocumentPageView(page: page) } } .pageViewStyle(.scroll) .toolbar { ToolbarItem(placement: .navigationBarTrailing) { // Built-in navigation button PageViewNavigationButton() } ToolbarItem(placement: .navigationBarLeading) { // Custom navigation control CustomPageNavigation() } } // Enable navigation environment for toolbar items .pageViewEnvironment() } } } struct CustomPageNavigation: View { @Environment(\.navigatePageView) private var navigate @Environment(\.canNavigatePageView) private var canNavigate var body: some View { HStack { Button { navigate(.backwards) } label: { Image(systemName: "arrow.left") } .disabled(!canNavigate.contains(.backwards)) Button { navigate(.forwards) } label: { Image(systemName: "arrow.right") } .disabled(!canNavigate.contains(.forwards)) } } } struct PageData: Identifiable { let id: UUID = UUID() let title: String let content: String static let sampleDocument: [PageData] = [ PageData(title: "Introduction", content: "Welcome..."), PageData(title: "Chapter 1", content: "First chapter...") ] } struct DocumentPageView: View { let page: PageData var body: some View { ScrollView { VStack(alignment: .leading) { Text(page.title).font(.title) Text(page.content).font(.body) } .padding() } } } ``` -------------------------------- ### Implement Custom PageViewStyle (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Defines a custom visual style and interaction for a PageView by conforming to the PageViewStyle protocol. The makeBody(configuration:) method is implemented to define the view's appearance and behavior. ```swift public struct PlainPageViewStyle: PageViewStyle { public init() { } public func makeBody(configuration: Configuration) -> some View { ZStack { configuration.content(configuration.selection.wrappedValue) } } } ``` -------------------------------- ### PageView with ForEach Data Source (SwiftUI) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Illustrates using a collection of data (e.g., photos) as the page source for PageView. It binds the selection to a photo ID and displays images asynchronously. Relies on SwiftUI and BigUIPaging. Suitable for displaying lists of items where each item is a page. ```swift struct PhotoGalleryView: View { @State private var selectedPhotoID: UUID let photos: [Photo] var body: some View { PageView(selection: $selectedPhotoID) { ForEach(photos) { photo in AsyncImage(url: photo.url) { image in image .resizable() .aspectRatio(contentMode: .fit) } placeholder: { ProgressView() } } } .pageViewStyle(.scroll) .pageViewOrientation(.horizontal) } } struct Photo: Identifiable { let id: UUID let url: URL } ``` -------------------------------- ### Create PageView with Relative Values (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Initializes a PageView using closure-based logic for determining the next and previous page values relative to the current selection. This is useful for dynamic content where page numbers are not sequential. ```swift @State private var selection: Int = 1 var body: some View { PageView(selection: $selection) { value in value + 1 } previous: { value in value > 1 ? value - 1 : nil } content: { Text("Page \(value)") } } ``` -------------------------------- ### Navigate PageView Using Environment Action (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Navigates a PageView programmatically using the environment's PageViewNavigateAction. This allows external controls, like buttons, to trigger forward or backward page transitions. It also shows how to check navigation availability with canNavigatePageView. ```swift @Environment(\.navigatePageView) private var navigate @Environment(\.canNavigatePageView) private var canNavigate var body: some View { Button { navigate(.forwards) } label: { Text("Next") } .disabled(!canNavigate.contains(.forwards)) } ``` -------------------------------- ### Apply PageView Style (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Applies a visual style and interaction behavior to a PageView. Styles like '.scroll', '.book', and '.cardDeck' define the navigation gestures and transitions. A style must be applied for the PageView to be interactive. ```swift PageView(selection: $selection) { ... } .pageViewStyle(.bookStack) ``` -------------------------------- ### PageIndicator Custom Icons (Swift - iOS) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Demonstrates using custom system images for specific pages within a PageIndicator. This allows for unique visual cues on each page, such as a location icon for the first page. Requires iOS. ```swift #if os(iOS) struct WeatherPagesView: View { @State private var currentLocation: Int = 0 let locations: [Location] = Location.allLocations var body: some View { VStack { PageView(selection: $currentLocation) { ForEach(Array(locations.enumerated()), id: \.offset) { index, location in WeatherPageView(location: location) } } .pageViewStyle(.scroll) .ignoresSafeArea() PageIndicator( selection: $currentLocation, total: locations.count ) { page, selected in // First page shows location icon (current location) if page == 0 { Image(systemName: "location.fill") } // Other pages show filled/unfilled based on selection else if selected { Image(systemName: "circle.fill") } else { Image(systemName: "circle") } } .pageIndicatorBackgroundStyle(.prominent) .padding(.bottom) } } } struct Location { let name: String let isCurrentLocation: Bool let temperature: Int static let allLocations: [Location] = [ Location(name: "Current Location", isCurrentLocation: true, temperature: 72), Location(name: "New York", isCurrentLocation: false, temperature: 68), Location(name: "London", isCurrentLocation: false, temperature: 55) ] } struct WeatherPageView: View { let location: Location var body: some View { VStack(spacing: 20) { if location.isCurrentLocation { Image(systemName: "location.fill") .font(.title) } Text(location.name) .font(.largeTitle) Text("\(location.temperature)°") .font(.system(size: 80)) } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.blue.gradient) .foregroundColor(.white) } } #endif ``` -------------------------------- ### Create PageIndicator Control (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Initializes a PageIndicator view, which displays a series of dots representing pages. It requires a binding to the current selection and the total number of pages. This control bridges to UIKit's UIPageControl on iOS. ```swift @State private var selection = 1 var body: some View { PageIndicator(selection: $selection, total: 5) } ``` -------------------------------- ### PageIndicator Basic Usage (iOS Only) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Demonstrates the basic usage of the PageIndicator view on iOS to display a horizontal series of dots representing pages in a TabView. It requires the `os(iOS)` conditional compilation directive. Inputs include the current page selection and total number of pages. Outputs are visual dots indicating page progress. ```swift #if os(iOS) struct OnboardingView: View { @State private var currentPage: Int = 0 let totalPages: Int = 5 var body: some View { VStack { TabView(selection: $currentPage) { ForEach(0.. 1 ? page - 1 : nil } content: { BookPageContent(pageNumber: page) } .pageViewStyle(.book) // 3D page curl effect .ignoresSafeArea() } } struct BookPageContent: View { let pageNumber: Int var body: some View { VStack { Text("Chapter \(pageNumber / 5 + 1)") .font(.headline) Spacer() Text("Page content for page \(pageNumber)...") .padding() Spacer() Text("Page \(pageNumber)") .font(.caption) .foregroundColor(.secondary) } .padding() .background(Color(.systemBackground)) } } #endif ``` -------------------------------- ### Add PageView Navigation Buttons (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Includes standardized navigation controls (forward and backward) for a PageView using PageViewNavigationButton. These buttons automatically adapt to the page view's orientation and can be configured within the toolbar. ```swift PageView { ... } .toolbar { ToolbarItem { PageViewNavigationButton() .pageViewOrientation(.vertical) } } .pageViewEnvironment() ``` -------------------------------- ### PageIndicator Customization (iOS Only) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Shows how to customize the appearance of the PageIndicator view on iOS with custom colors, background styles, and interaction behaviors. Requires the `os(iOS)` directive. Allows setting colors for selected and unselected dots, background styles, and controlling interaction. Depends on SwiftUI. ```swift #if os(iOS) struct StyledIndicatorView: View { @State private var currentPage: Int = 0 let pages: [PageContent] = PageContent.samples var body: some View { VStack { PageView(selection: $currentPage) { ForEach(Array(pages.enumerated()), id: \.offset) { index, page in page.view } } .pageViewStyle(.scroll) PageIndicator( selection: $currentPage, total: pages.count ) .pageIndicatorColor(.purple.opacity(0.3)) // Unselected dot color .pageIndicatorCurrentColor(.purple) // Selected dot color .pageIndicatorBackgroundStyle(.prominent) // Full background .allowsContinuousInteraction(true) // Enable drag along dots .singlePageVisibility(.hidden) // Hide when only 1 page } } } struct PageContent { let title: String let color: Color var view: some View { ZStack { color.ignoresSafeArea() Text(title) .font(.largeTitle) .foregroundColor(.white) } } static let samples: [PageContent] = [ PageContent(title: "Red", color: .red), PageContent(title: "Blue", color: .blue), PageContent(title: "Green", color: .green) ] } #endif ``` -------------------------------- ### PageView Custom Style with Lazy Loading Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Implements a custom PageView style that displays multiple surrounding pages with a lazy loading effect. It uses a ScrollView and Hstack to arrange content, efficiently retrieves surrounding page values, and applies visual effects based on selection. Requires SwiftUI. ```swift struct MultiPageStyle: PageViewStyle { let visibleRange: Int = 2 // Show 2 pages on each side func makeBody(configuration: Configuration) -> some View { ScrollView(.horizontal, showsIndicators: false) { HStack(spacing: 20) { let current = configuration.selection.wrappedValue // Get surrounding values efficiently let surroundingValues = configuration.values( surrounding: current, limit: visibleRange ) ForEach(Array(surroundingValues.enumerated()), id: \.element) { index, value in configuration.content(value) .frame(width: 300, height: 400) .scaleEffect(value == current ? 1.0 : 0.85) .opacity(value == current ? 1.0 : 0.6) .onTapGesture { withAnimation(.spring(response: 0.3)) { configuration.selection.wrappedValue = value } } } } .padding() } } } struct MultiPageExampleView: View { @State private var selection: Int = 5 var body: some View { PageView(selection: $selection) { ForEach(1...100, id: \.self) { index in ZStack { RoundedRectangle(cornerRadius: 16) .fill(Color.blue.opacity(Double(index % 10) / 10)) Text("\(index)") .font(.system(size: 60, weight: .bold)) .foregroundColor(.white) } } } .pageViewStyle(MultiPageStyle(visibleRange: 3)) } } ``` -------------------------------- ### Customize Page Indicator Appearance in Swift Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Control the visual style of the page indicator using various modifiers. These include setting the tint color for regular and current pages, enabling continuous user interaction, defining the background style, and managing visibility for single-page scenarios. ```swift /// The tint color to apply to the page indicator. .pageIndicatorColor(.purple) /// The tint color to apply to the current page indicator. .pageIndicatorCurrentColor(.pink) /// A Boolean value that determines whether the page control allows continuous interaction. .allowsContinuousInteraction(true) /// The preferred background style. .pageIndicatorBackgroundStyle(.prominent) /// Controls whether the page indicator is hidden when there is only one page. .singlePageVisibility(.hidden) ``` -------------------------------- ### PageIndicator Auto-Advance Timer (Swift - iOS 17+) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Enables automatic advancement of pages in a PageIndicator after a specified duration, ideal for slideshows. This feature requires iOS 17.0 or later and allows for user interaction to pause the auto-advance. ```swift #if os(iOS) @available(iOS 17.0, *) struct SlideshowView: View { @State private var currentSlide: Int = 0 let slides: [SlideContent] = SlideContent.allSlides var body: some View { VStack { PageView(selection: $currentSlide) { ForEach(Array(slides.enumerated()), id: \.offset) { index, slide in SlideView(content: slide) } } .pageViewStyle(.scroll) HStack { PageIndicator( selection: $currentSlide, total: slides.count ) .pageIndicatorDuration(3.0) // Auto-advance every 3 seconds .pageIndicatorCurrentColor(.white) .pageIndicatorColor(.white.opacity(0.5)) Spacer() Button("Pause") { // User interaction pauses auto-advance } } .padding() } .background(Color.black) } } struct SlideContent { let title: String let subtitle: String let image: String static let allSlides: [SlideContent] = [ SlideContent(title: "Welcome", subtitle: "Get Started", image: "star.fill"), SlideContent(title: "Features", subtitle: "What's New", image: "sparkles"), SlideContent(title: "Finish", subtitle: "All Done", image: "checkmark.circle.fill") ] } struct SlideView: View { let content: SlideContent var body: some View { VStack(spacing: 30) { Image(systemName: content.image) .font(.system(size: 100)) .foregroundColor(.white) Text(content.title) .font(.largeTitle) .bold() .foregroundColor(.white) Text(content.subtitle) .font(.title3) .foregroundColor(.white.opacity(0.8)) } .frame(maxWidth: .infinity, maxHeight: .infinity) } } #endif ``` -------------------------------- ### PageView Card Deck Style - Swift (iOS) Source: https://context7.com/notsobigcompany/biguipaging/llms.txt Displays pages as a stackable card deck with support for drag gestures, designed for iOS. This view utilizes SwiftUI and includes customizable properties for card appearance such as corner radius and shadow. A PageIndicator is provided for navigation. ```swift #if os(iOS) struct FlashcardDeckView: View { @State private var currentCard: Int = 1 let totalCards: Int = 10 var body: some View { VStack { PageView(selection: $currentCard) { ForEach(1...totalCards, id: \.self) { cardNumber in FlashcardView(number: cardNumber) .aspectRatio(0.7, contentMode: .fit) } } .pageViewStyle(.cardDeck) .scaleEffect(0.9) // Show edges of stacked cards .pageViewCardCornerRadius(45.0) // Rounded corners .pageViewCardShadow(.visible) // Drop shadow .onTapGesture { print("Tapped card \(currentCard)") } PageIndicator( selection: Binding( get: { currentCard - 1 }, set: { currentCard = $0 + 1 } ), total: totalCards ) .pageIndicatorColor(.secondary.opacity(0.3)) .pageIndicatorCurrentColor(.blue) } } } struct FlashcardView: View { let number: Int var body: some View { ZStack { RoundedRectangle(cornerRadius: 45) .fill(Color.blue) VStack { Text("Flashcard \(number)") .font(.largeTitle) .bold() Text("Question or content here") .font(.title3) } .foregroundColor(.white) } } } #endif ``` -------------------------------- ### Customize Page Indicator Icons in Swift Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Dynamically change the icons displayed in the page indicator based on the page index or the selection state. This allows for visual cues like the Weather app's use of a location icon on the first page. ```swift // Vary icons depending on page PageIndicator(selection: $selection, total: total) { (page, selected) in if page == 0 { Image(systemName: "location.fill") } } // Vary icons depending on selection state PageIndicator(selection: $selection, total: total) { (page, selected) in if selected { Image(systemName: "folder.fill") } else { Image(systemName: "folder") } } ``` -------------------------------- ### Set Auto-Advance Duration for Page Indicator in Swift Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Configure the page indicator to automatically advance to the next page after a specified duration. This feature can also synchronize with a PageView if they share the same selection binding. ```swift PageIndicator... .pageIndicatorDuration(3.0) ``` -------------------------------- ### Configure PageView Orientation (SwiftUI) Source: https://github.com/notsobigcompany/biguipaging/blob/master/README.md Sets the navigation orientation for PageView styles that support it, such as '.scroll' and '.book'. This modifier can be applied to the PageView or controls like PageViewNavigationButton to adjust their layout and behavior. ```swift .pageViewOrientation(.vertical) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.