Home

Awesome

<p align="center"> <img src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/banner.png" height=58 width=182/> </p> <p align="center"> <strong><a href="#getting-started">Getting Started</a></strong> | <strong><a href="#customization">Customization</a></strong> | <strong><a href="#installation">Installation</a></strong> </p> <p align="center"> <img src="https://api.travis-ci.com/nachonavarro/Pages.svg?branch=master" alt="CI" /> <img src="https://img.shields.io/badge/platform-iOS-blue.svg?style=flat" alt="Platforms" /> <img src="https://img.shields.io/badge/Swift-5-orange.svg" /> <a href="https://github.com/nachonavarro/Pages/blob/master/LICENSE"><img src="http://img.shields.io/badge/license-MIT-blue.svg?style=flat" alt="License: MIT" /></a> </p> <br/> <p align="middle"> <img src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/art-demo.gif" data-canonical-src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/art-demo.gif" width="200"/> <img src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/onboarding-demo.gif" data-canonical-src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/onboarding-demo.gif" width="200"/> <img src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/book-preview.gif" data-canonical-src="https://github.com/nachonavarro/PagesDemo/blob/master/Screenshots/book-preview.gif" width="200"/> </p>

Getting Started

Basic usage

Using Pages is as easy as:


import Pages

struct WelcomeView: View {

    @State var index: Int = 0

    var body: some View {
        Pages(currentPage: $index) {
             Text("Welcome! This is Page 1")
             Text("This is Page 2")
             Text("...and this is Page 3")
             Circle() // The 4th page is a Circle
        }
    }
}

One can also use Pages with dynamic content:


import Pages

struct Car {
    var model: String
}

struct CarsView: View {
    let cars = [Car(model: "Ford"), Car(model: "Ferrari")]
    @State var index: Int = 0
    
    var body: some View {
        ModelPages(cars, currentPage: $index) { pageIndex, car in
            Text("The \(pageIndex) car is a \(car.model)")
                .padding(50)
                .foregroundColor(.white)
                .background(Color.blue)
                .cornerRadius(10)
        }
    }
}

How it works

Pages uses a function builder to accomplish a SwiftUI feel while using a UIPageViewController under the hood. As in VStack or HStack, the current limit of pages to add in a static way using the Pages view is 10. If more are needed use a ModelPages instead. The Pages view will take up all the available space it is given.

Note: The Pages view needs more than one page. Otherwise the compiler treats what's inside Pages as a closure.

Customization

The following aspects of Pages can be customized:

Pages(navigationOrientation: .vertical) {
    Text("Page 1")
    Text("Page 2")
}
Pages(
    navigationOrientation: .vertical,
    transitionStyle: .pageCurl
) {
    Text("Page 1")
    Text("Page 2")
}
Pages(
    navigationOrientation: .vertical,
    transitionStyle: .pageCurl,
    bounce: false
) {
    Text("Page 1")
    Text("Page 2")
}
Pages(
    navigationOrientation: .vertical,
    transitionStyle: .pageCurl,
    bounce: false,
    wrap: true
) {
    Text("Page 1")
    Text("Page 2")
}
Pages(
    navigationOrientation: .vertical,
    transitionStyle: .pageCurl,
    bounce: false,
    wrap: true,
    hasControl: false
) {
    Text("Page 1")
    Text("Page 2")
}
Pages(
    navigationOrientation: .vertical,
    transitionStyle: .pageCurl,
    bounce: false,
    wrap: true,
    control: MyPageControl()
) {
    Text("Page 1")
    Text("Page 2")
}
Pages(
    navigationOrientation: .vertical,
    transitionStyle: .pageCurl,
    bounce: false,
    wrap: true,
    controlAlignment: .topLeading
) {
    Text("Page 1")
    Text("Page 2")
}

FAQ

Demos

All of the demos shown on the GIF can be checked out on the demo repo.

Installation

Pages is available using the Swift Package Manager:

Using Xcode 11, go to File -> Swift Packages -> Add Package Dependency and enter https://github.com/nachonavarro/Pages

Running the tests

Once you select an iPhone destination on Xcode, press ⌘U to run the tests. Alternatively run xcodebuild test -destination 'name=iPhone 11' -scheme 'Pages' on the terminal.

Requirements

TODOs

Contributing

Feel free to contribute to Pages!

  1. Fork Pages
  2. Create your feature branch with your changes
  3. Create pull request

License

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