ASCollectionView icon indicating copy to clipboard operation
ASCollectionView copied to clipboard

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

Open andrei115 opened this issue 3 years ago • 3 comments

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") })
        }
    }
}

andrei115 avatar Oct 01 '21 18:10 andrei115

@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.

seboslaw avatar Nov 11 '21 13:11 seboslaw

@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)

andrei115 avatar Nov 11 '21 13:11 andrei115

@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.

seboslaw avatar Nov 11 '21 13:11 seboslaw