nathantannar4 / Transmission

Bridges UIKit presentation APIs to a SwiftUI API so you can use presentation controllers, interactive transitions and more.
BSD 2-Clause "Simplified" License
378 stars 13 forks source link

Nested NavigationStack inside sheet doesn't work with presentation modifier #9

Closed PhilipDukhov closed 10 months ago

PhilipDukhov commented 10 months ago

When I push item into childNavigationPath, somehow it gets pushed to the root NavigationStack instead of the sheet one.

It's probably related to the fact that nested NavigationStacks doesn't work in general, but somehow system sheet modifier handles it.

Steps to reproduce:

  1. Click Show sheet
  2. Inside the sheet click Push Next

Expected behavior: new view pushed inside the sheet Actual behavior: looks like nothing happens, but when sheet is closed there's the pushed screen

struct ContentView: View {
    @State var childNavigationPath = NavigationPath()
    @State var isSheetShown = false

    var body: some View {
        NavigationStack {
            Button {
                withAnimation {
                    isSheetShown = true
                }
            } label: {
                Text("Show sheet")
            }
            .presentation(
                transition: .slide(
                    options: .init(
                        edge: .bottom,
                        prefersScaleEffect: true,
                        isInteractive: true,
                        options: .init(
                            shouldAutomaticallyDismissDestination: false,
                            modalPresentationCapturesStatusBarAppearance: true,
                            preferredPresentationBackgroundColor: .gray
                        )
                    )
                ),
                isPresented: $isSheetShown
            ) {
                NavigationStack(path: $childNavigationPath) {
                    Button {
                        childNavigationPath.append("Some")
                    } label: {
                        Text("Push Next")
                    }
                    .navigationDestination(for: String.self) { item in
                        Text(item)
                    }
                }
                .frame(maxHeight: .infinity, alignment: .top)
            }
        }
    }
}
nathantannar4 commented 10 months ago

Hmm, seems like a SwiftUI edge case that perhaps .sheet explicitly accounts for. I'll have to investigate if I can add similar edge case handling.

nathantannar4 commented 10 months ago

Ok I think I can provide a workaround! I have a prototype I just need to test more.

PhilipDukhov commented 10 months ago

Ok I think I can provide a workaround! I have a prototype I just need to test more.

Wow, great news 🎉

nathantannar4 commented 10 months ago

Fixed in 1.0.0