Skip to content

danielsaidi/PageView

Repository files navigation

Project Icon

Version Swift 6.0 Swift UI Documentation MIT License Sponsor my work

PageView

PageView is a custom SwiftUI page view that works on all major Apple platforms.

PageView is a custom SwiftUI page view that works on all major Apple platforms. It mimics a paged TabView and can be set up with a list of pages, a list of items, or a PageViewState value.

Installation

PageView can be installed with the Swift Package Manager:

https://github.com/danielsaidi/PageView.git

Support My Work

You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.

Getting started

You can create a PageView with a collection of page views, an array of page items, or a PageViewState.

struct MyView: View {

    @State var state = PageViewState(pages: Array(0...5))

        var body: some View {
        PageView(state) { page in
            VStack(spacing: 20) {
                Text("Page \(page)")
                Button(buttonTitle, action: nextPageOrRestart)
                    .padding(50)
                    .buttonStyle(.borderedProminent)
            }
        }
        .pageViewAnimation(.bouncy)
        .pageViewIndicatorDisplayMode(.automatic)
        .pageViewIndicatorStyle(.init(
            dotColor: .blue,
            currentDotColor: .yellow
        ))
        .background(
            color(for: state.pageIndex)
                .ignoresSafeArea()
                .animation(.easeOut, value: state.pageIndex)
        )
    }

    func color(for index: Int) -> Color {
        switch index {
        case 0: .red
        case 1: .green
        case 2: .blue
        case 3: .orange
        case 4: .pink
        case 5: .mint
        default: .purple
        }
    }

    func nextPageOrRestart() {
        if state.isLastPage {
            state.pageIndex = 0
        } else {
            state.showNextPage()
        }
    }
}

You can customize the page view animation with the pageViewAnimation(_:) view modifier, the page indicator display mode with pageViewIndicatorDisplayMode(_:) and its style with pageViewIndicatorStyle(_:).

Documentation

The online documentation has more information, articles, code examples, etc.

Demo Application

The Demo folder has an app that lets you test the library.

Contact

Feel free to reach out if you have questions or if you want to contribute in any way:

License

PageView is available under the MIT license. See the LICENSE file for more info.

About

A SwiftUI page view that works on all major Apple platforms.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project