fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.3k stars 172 forks source link

[BUG] - Content is blinking when loopPages and contentLoadingPolicy are active #269

Closed Catah97 closed 2 years ago

Catah97 commented 2 years ago

Describe the bug Content is blinking when user scrolling through the list. It happends only when

view
.loopPages()
.contentLoadingPolicy(.eager)

If you use just .loopPages() without .contentLoadingPolicy(.eager) the problem disappear.

To Reproduce Simulated on the code below.

struct InfiniteExampleView: View {

    @StateObject var page1 = Page.withIndex(2)
    @StateObject var page2 = Page.first()
    @State var data1 = Array(0..<7)
    @State var isPresented: Bool = false
    var data2 = Array(0..<20)

    var body: some View {
        Pager(page: self.page2,
              data: self.data2,
              id: \.self) {
                self.pageView($0)
        }
              .contentLoadingPolicy(ContentLoadingPolicy.eager)
              .loopPages()
    }

    func pageView(_ page: Int) -> some View {
        ZStack {
            if page % 2 == 0 {
                Color.red
            } else {
                Color.blue
            }
        }
        .cornerRadius(5)
        .shadow(radius: 5)
    }
}

Environment:

fermoya commented 2 years ago

@Catah97 this is a known issue, loopPages and .eager policy.

Why do you need it to be eager? Remove the contentLoadingPolicy for a better performance

Catah97 commented 2 years ago

We would like to use Pager to shown ads in out app. Ad mean pictures that will cycling forever in the loop. These pictures are downloading from web and it could be nice to preload them all at once. The count of ads is low something between 3 to 10 so this should not be performance issue.

Catah97 commented 2 years ago

But it seem that default behavior that preload 5 ads will be enough for us. So I apologize for spam.