nathantannar4 / Transmission

Bridges UIKit presentation APIs to a SwiftUI API so you can use presentation controllers, interactive transitions and more.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

matchedGeometryEffect doesn't work inside DestinationLink

PhilipDukhov opened this issue · comments

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

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

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?

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