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
426 stars 17 forks source link

Toolbar flash issue when using custom detents with nested NavigationStack #66

Open ailu2533 opened 4 days ago

ailu2533 commented 4 days ago

Description

When using a custom detent with PresentationLink and the sheet content contains a NavigationStack, the sheet's toolbar briefly appears in the parent view's navigation bar. This issue doesn't occur when using constant detents.

Reproduction Steps

  1. Create a sheet using PresentationLink with custom detents
  2. Add NavigationStack to both parent view and sheet content
  3. Add toolbar items to the sheet's NavigationStack
  4. Open the sheet
  5. Observe the toolbar items briefly appearing in the parent view

Minimal Reproduction Code


@main
struct DemoApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

// MARK: - ContentView

struct ContentView: View {
    // MARK: Internal

    var body: some View {
        NavigationStack {
            VStack {
                PresentationLink(
//                    transition: .sheet(detents: [.constant("constant", height: 250)])

                    transition: .sheet(detents: [.custom("custom", resolver: { context in context.maximumDetentValue * 0.25 })])
                ) {
                    SheetContent()
                } label: {
                    Text("Sheet (constant Detent)")
                }
            }
        }
    }

    // MARK: Private

    @State private var showSheet = false
}

// MARK: - SheetContent

struct SheetContent: View {
    // MARK: Internal

    var body: some View {
        NavigationStack {
            VStack {
                Text("Sheet Content")
            }
            .toolbar {
                ToolbarItemGroup(placement: .topBarTrailing) {
                    Button {
                        dismiss()
                    } label: {
                        Text("Done")
                    }
                }
            }
        }
    }

    // MARK: Private

    @Environment(\.dismiss) private var dismiss
}

https://github.com/user-attachments/assets/95fd14ec-79d9-4ac4-8862-11beeca9268e

nathantannar4 commented 3 days ago

Not able to repo, tested on device/simulator on iOS 18, simulator on iOS 17/18.

Are you able to repo in a particular simulator? Can you please share your Xcode version and iOS sim version

ailu2533 commented 3 days ago

Not able to repo, tested on device/simulator on iOS 18, simulator on iOS 17/18.

Are you able to repo in a particular simulator? Can you please share your Xcode version and iOS sim version

Thanks for checking. Here's my environment info:

nathantannar4 commented 13 hours ago

Ok, bug seems to be with the toolbar modifier applying it to the NavigationStack in the ContentView. As a workaround, I found that you can wrap your NavigationStack that is in the ContentView within a VStack