nachonavarro / Pages

📖 A lightweight, paging view solution for SwiftUI
MIT License
556 stars 53 forks source link

How dynamic add pages #4

Closed chinyaev closed 4 years ago

chinyaev commented 4 years ago

Hello! thank you for your solution, but I cannot use it with dinamic array.

My code ` import SwiftUI import Pages

struct Car { var model: String }

struct CarsView: View { @State var cars = [Car(model: "Ford"), Car(model: "Ferrari")] @State var index: Int = 0

var body: some View {
    VStack {
        GeometryReader { g in
            ModelPages(self.cars, currentPage: self.$index) {index, car in
                VStack(alignment: .leading) {
                    Text(car.model).font(.title)

                    Button(action: {
                        self.cars.append(Car(model: "BMW"))
                    }) {
                        Text("Add").font(.title)
                    }
                }
            }

        }
    }
}

} `

When I added element it stop work and element doesn't add.

nachonavarro commented 4 years ago

Update your version of Pages, it should be fixed now.