My home view contains a CustomView
that opens a detailed view via a NavigationLink
when tapped. The detailed view also contains the CustomView
, just in a different location.
Can I use the match geometry effect to transition/animate the location of the CustomView
when the navigation link is clicked?
struct HomeView: View {
@Namespace var namespace
var body: some View {
NavigationStack {
VStack {
Text("Top")
NavigationLink {
DetailView(namespace: namespace)
} label: {
CustomView()
.matchedGeometryEffect(id: "testId", in: namespace)
}
Text("Bottom")
}
}
}
}
struct DetailView: View {
var namespace: Namespace.ID
var body: some View {
VStack {
CustomView()
.matchedGeometryEffect(id: "testId", in: namespace)
Text("Details")
Spacer()
}
}
}