gh123man / SwiftUI-LazyPager

A SwiftUI, lazy loaded, paging, panning, and zooming view for images and more
MIT License
164 stars 15 forks source link

LazyPager content closures can't respond to variable updates within the closure context #3

Closed zkamisama closed 1 year ago

zkamisama commented 1 year ago

LazyPager content closures can't respond to variable updates within the closure context


@State var count: Int = 0

var body: some View {

            ZStack {
                  LazyPager(data: medias, page: $currentIndex ) { media in
                      WebImage(url: media.wrappedCoverImage)
                          .resizable()
                          .aspectRatio(contentMode: .fit)
                          .matchedGeometryEffect(id: media.id!.uuidString, in: transition)
                          .overlay {
                              Text("Count \(count)")
                                  .font(.title)
                          }
                  }
            }
            .onChange(of: currentIndex) { newValue in
                count = count + 1
                print(count)
            }
}

When the sliding view switches pages, the variable count is updated, but the count value inside the content closure is not updated.

gh123man commented 1 year ago

Hi! Thanks so much for the report. Fixed and released in 1.0.4