nachonavarro / Pages

📖 A lightweight, paging view solution for SwiftUI
MIT License
586 stars 55 forks source link

setCurrentItem: positionIndex in ModalPages #1

Closed csdal closed 4 years ago

csdal commented 4 years ago

For example, we open a book, stopped reading at page number 33. The book resumes at page 1 and we have to flip page by page until page number 33. If the book resumes at page 33, it would be great.

nachonavarro commented 4 years ago

I agree, let me look at how I can include it and I'll come back to you on this.

nachonavarro commented 4 years ago

Hey,

I added the feature that will solve this problem. Now the user has the ability to maintain the state of the current page themselves to do whatever they want with the state:

import Pages

struct ContentView: View {

    @State var index: Int = 0

    var body: some View {
        Pages(currentPage: $index) {
            Text("Page 1")
            Button(action: {
                self.index = 3
            }) {
                Text("This button will go to page 4")
            }
            Text("Page 3")
            Text("Page 4")
        }

    }

}