notsobigcompany / BigUIPaging

A collection of SwiftUI views for handling pages of content
252 stars 14 forks source link

Card style in a LazyVStack breaks scrolling #3

Open daprice opened 8 months ago

daprice commented 8 months ago

Here’s a minimal example that creates a vertically scrolling LazyVStack of 100 views, each containing a PageView with the cardDeck style and 3 children, plus a numeric text label so you can see where you’ve scrolled to.

If you scroll down far enough and then try to scroll back up, the entire scroll view contents start jerking around both vertically and horizontally making it completely unusable.

I do see that setting a fixed size on the PageView using .frame(width:height:) prevents the issue from happening, but I’d like to be able to let it size dynamically based on the content.

import SwiftUI
import BigUIPaging

struct ContentView: View {
    var body: some View {
        ScrollView(.vertical) {
            LazyVStack {
                ForEach(1...100, id: \.self) { value in
                    VStack {
                        Text("\(value)")
                        PageView(selection: .constant(0)) {
                            ForEach(0...3, id: \.self) { card in
                                Color.red
                                    .aspectRatio(0.7, contentMode: .fit)
                            }
                        }
                        .pageViewStyle(.cardDeck)
                    }
                }
            }
        }
    }
}

Screen recording from my device running iOS 17.2.1 (warning – there’s some severe flashing that some might be sensitive to):

https://github.com/notsobigcompany/BigUIPaging/assets/3615519/1f1a0387-9fe7-412c-aa99-46557c72ce61