fermoya / SwiftUIPager

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

[BUG] To many pageView request #311

Open kelalaka153 opened 1 year ago

kelalaka153 commented 1 year ago

Describe the bug

I'm running a simplified example to test for my purpose;

    var body: some View {
            GeometryReader { proxy in
                VStack(spacing: 10) {
                    Pager(page: self.page1,
                          data: self.data1,
                          id: \.self) {
                            self.pageView($0)
                    }
                    .contentLoadingPolicy(.lazy(recyclingRatio: 2)) // more problem with the eager policy 
                    .pagingPriority(.simultaneous)
                    .sensitivity(.high)
                    .itemSpacing(10)
                }
            }
    }

with additionally printing page requests

func pageView(_ page: Int) -> some View {

        print("Page request for \(page)")

gettting

App State: inactive
Page request for 0
Page request for 0
Page request for 1
Page request for 1
App State: active
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 0
Page request for 1
Page request for 2
Page request for 2

Expected behavior

It seams that the slower the page transitions the more page request exist. I want a single call since each of the pages get data from the database, for each call, the database query will be executed again.

Environment:

Additional context

Is there a way to only load/prepare the neighbor pages with only one call per page?