apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collection view hidden when embedded in ScrollView

joeycarmello opened this issue · comments

Describe the bug

I'm attempting to use the tags example from the demo in a simple ScrollView. The demo renders successfully without the ScrollView, but renders nothing at all when embedded within a ScrollView. I've tried variations of settings explicit frames on the collection view and items.

To Reproduce

Minimal example preview:

struct TagExample_Previews: PreviewProvider {
    struct DataItem: Identifiable {
        let id = UUID()
        let name: String
    }
    
    static var previews: some View { 
        let data: [DataItem] = [
            .init(name: "one"),
            .init(name: "second"),
            .init(name: "three"),
            .init(name: "four"),
        ]
        
        return Group {
            ScrollView {
                VStack {
                    ASCollectionView(
                        section: ASCollectionViewSection(
                            id: 0,
                            data: data,
                            contentBuilder: { (item, _) in
                                Text(item.name)
                        })
                        .selfSizingConfig { _ in
                            ASSelfSizingConfig(canExceedCollectionWidth: false)
                        }
                    )
                    .layout {
                        let fl = AlignedFlowLayout()
                        fl.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
                        return fl
                    }
                    .shrinkToContentSize(isEnabled: true, dimension: .vertical)
                }
            }
        }
    }
}

Expected behaviour

The collection view should render correctly within a ScrollView using self-sizing items.

Screenshots

Without ScrollView:

Screen Shot 2020-06-03 at 11 36 17 AM

Xcode Version:

  • 11.5

Simulator, Device, Both?

  • Simulator

Thanks for reporting the bug @joeycarmello - this is a regression of an old bug in SwiftUI, so I have reinstated an old workaround in 1.7.1. Should now be working 🎉

Bug: SwiftUI isn't calling viewDidAppear when we nest a UIViewControllerRepresentable inside a scrollView.

Awesome. I can confirm 1.7.1 fixed it. Thank you!