apptekstudios / ASCollectionView

A SwiftUI collection view with support for custom layouts, preloading, and more.
MIT License
1.36k stars 160 forks source link

iOS 15, ASCollectionView causes .sheet() to pop unexpectedly #223

Open andrei115 opened 3 years ago

andrei115 commented 3 years ago

in ios 15, NavigationLinks inside ASCollectionView are popped when a modal is displayed from the destination view.

struct Test: View {
    var body: some View {
        NavigationView {
            ASCollectionView {
                NavigationLink("navigation link") {
                    TestDestination()
                }
            }
        }
    }
}

struct TestDestination: View {
    @State private var showModal = false

    var body: some View {
        VStack {
            Text("destination view")
            Button("click for modal", action: { showModal = true })
                .sheet(isPresented: $showModal, content: { Text("Modal view") })
        }
    }
}
seboslaw commented 3 years ago

@andrei115 have you found a solution to this problem? A temp solution for me has been to use the tag/selection version of NavigationLink and use a ZStack. But implementing this throughout the app is super cumbersome.

andrei115 commented 3 years ago

@seboslaw I'm not familiar with the tag/selection version of the NavigationLink. The solution for me was to conditionally use LazyGrid for ios14/15 and fallback to ASCollectionView for ios 13. We eventually plan on dropping support for ios 13 as it's really buggy and it does not work well with other libraries(like for example KingFisher for image caching, if you've used)

seboslaw commented 3 years ago

@andrei115 that sounds like the right decision. The tag/selection version is basically described here: https://stackoverflow.com/a/57837007 You create the NavigationLinks with EmptyViews and set a tag to each. You then assign a State var to capture the selection. And lastly you you a button in your view to set this State var to the tag value you want to navigate to.