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

matchedGeometryEffect doesn't work inside DestinationLink #26

Closed PhilipDukhov closed 2 months ago

PhilipDukhov commented 8 months ago

When I click the second button, I expect the underlying view to move with animation from the first button to the second. Instead it disappears/appears with fade animation.

It works as expected without .destination.

struct ContentView: View {
    var body: some View {
        NavigationView {
            // NavigationLink { // works fine
            DestinationLink {
                ScreenView()
            } label: {
                Text("Push")
            }
        }
    }
}

struct ScreenView: View {
    @State private var selected = 0

    @Namespace private var namespace

    var body: some View {
        HStack {
            ForEach(Array(0..<2), id: \.self) { i in
                Button {
                    withAnimation {
                        selected = i
                    }
                } label: {
                    SelectableView(title: "View \(i)", isSelected: selected == i, namespace: namespace)
                }
            }
        }
    }
}

struct SelectableView: View {
    var title: String
    var isSelected: Bool
    var namespace: Namespace.ID

    var body: some View {
        Text(title)
            .background(alignment: .bottom) {
                if isSelected {
                    Rectangle()
                        .frame(height: 3)
                        .matchedGeometryEffect(id: "id", in: namespace)
                }
            }
    }
}
nathantannar4 commented 8 months ago

This is expected. matchedGeometryEffect only works within the same UIHostingController. NavigationLink also has this limitation.

PhilipDukhov commented 8 months ago

This is expected. matchedGeometryEffect only works within the same UIHostingController. NavigationLink also has this limitation.

but I'm getting namespace inside navigation link, both Namespace and matchedGeometryEffect are declared inside one UIHostingController, unless I'm missing something?

PhilipDukhov commented 2 months ago

@nathantannar4 could we reopen this one? I have updated my code a little bit, it works as expected with NavigationLink but not with DestinationLink

nathantannar4 commented 2 months ago

Thanks, drilled down into this and found that it was also broken for PresentationLink! Fixed in 1.3.2