fermoya / SwiftUIPager

Native Pager in SwiftUI
MIT License
1.27k stars 168 forks source link

[BUG] Pager inside a list blocks vertical scrolling #243

Closed alinless closed 2 years ago

alinless commented 2 years ago

First of all, thanks for such an amazing library. It is really nice!

I use Pager inside a list view. Pager has only a horizontal scroll. Then I try to scroll the list, it gets stuck almost every second swipe or touch. I have to use list and I cant just use vStack with scrollView If I disable Dragging - everything works nice. Any other options didn't help me at all.

May I somehow disable vertical scrolling on Pager at all? Or there are any ideas on how to fix this problem?

fermoya commented 2 years ago

Hi @alinless , the scenario you describe is tricky because of the combination of gestures in Pager and List. Do you think you could share a sample ContentView with a similar scenario as yours? The simpler the better. I can take a look and see if there's something that I can do.

alinless commented 2 years ago

Thank you for such a fast answer! Here is an example of this bug

import SwiftUI
import SwiftUIPager

struct ContentView: View {

   var models = [makeStack(), makeStack(), makeStack(), makeStack(), makeStack()]

    var body: some View {
       List {
          ForEach((1...10), id: \.self) { _ in
             Pager(page: .first(), data: models, id: \.self) { page in
                VStack(spacing: 0) {
                   ForEach(page) { model in
                        CellView(model: model)
                   }
                   }
             }
                .preferredItemSize(CGSize(width: UIScreen.main.bounds.size.width, height: 150))
                .alignment(.start(20))
                .itemSpacing(15)
                .horizontal()
                .frame(height: 150)
          }
       }
    }

   static func makeStack() -> [CellModel] {
      let stack = [CellModel(), CellModel(), CellModel(),
                   CellModel(), CellModel(), CellModel(),
                   CellModel(), CellModel()
                  ]
      return stack
   }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

struct CellView: View {

   let model: CellModel

    var body: some View {
       HStack {
          Text(model.id)
       }
       .background(model.color)
       .frame(height: 50)
    }
}

struct CellModel: Equatable, Hashable, Identifiable {
   let id = UUID().uuidString
   let color = Color.random

}

extension Color {
    static var random: Color {
        return Color(
            red: .random(in: 0...1),
            green: .random(in: 0...1),
            blue: .random(in: 0...1)
        )
    }
}
fermoya commented 2 years ago

Hi @alinless , apologies for the late response. This is expected unless you use .pagingPriority(.simultaneous) from the docs:

https://user-images.githubusercontent.com/75254955/145688572-e68e362a-1f6a-451d-9527-c01263ce6bd2.mp4