SwiftUI: matchedGeometryEffect doesn't work during navigation

138 Views Asked by At

I'd like to navigate to another screen and have my view animate to its new position on the new screen smoothly (like Hero does). This article suggests it can be done. However this doesn't work at all, I get a regular navigation animation (xcode 15.0 ios17):

struct ContentView: View {
    var imageNames = ["circle", "cloud"]

    @Namespace var n

    var body: some View {
        NavigationStack {
            List {
                ForEach(imageNames) { name in
                    NavigationLink {
                        ZStack {
                            Color.blue.opacity(0.3)
                            Image(systemName: name)
                                .resizable()
                                .frame(width: 200, height: 200)
                                .matchedGeometryEffect(id: name, in: n)
                        }
                    } label: {
                        Image(systemName: name)
                            .resizable()
                            .frame(width: 50, height: 50)
                            .padding()
                            .matchedGeometryEffect(id: name, in: n)
                    }
                    
                }
            }
        }
   }
}

extension String: Identifiable {
    public var id: String { self }
}

Is it a bug or maybe I'm missing something?..

P.S. I understand in this case I don't need an actual second screen, but the real example is much more complicated.

0

There are 0 best solutions below