When I use matched geometry view modifier I always get a warning
Multiple inserted views in matched geometry group Pair<String, ID>(first: "id1", second: SwiftUI.Namespace.ID(id: 8)) have isSource: true, results are undefined.
While the animation stills works, I'd like to understand why I get this warning and how can I fix the problem.
This is the animation I built, any ideas how to get rid of the warning?
Using the following code
struct ContentView: View {
@State var details = false
@Namespace var animation
var body: some View {
ZStack {
HStack {
Rectangle()
.frame(width: 100, height: 100)
.matchedGeometryEffect(id: "id1", in: animation)
.onTapGesture {
withAnimation {
details.toggle()
}
}
Spacer()
}
.zIndex(1)
if details == true {
AnotherView(details: $details, animation: animation)
.zIndex(2)
}
}
}
}
struct AnotherView: View {
@Binding var details: Bool
var animation: Namespace.ID
var body: some View {
ZStack {
Color.red
Rectangle()
.frame(width: 300, height: 300)
.matchedGeometryEffect(id: "id1", in: animation)
.onTapGesture {
withAnimation {
details.toggle()
}
}
}
}
}


