I have a view that uses the .matchedGeometryEffect
to make moving transitions. I’d like to be able to switch this effect off if the user objects to this type of animation.
I could create two almost identical views, one with the .matchedGeometry modifier and one without, and invoke either of them using an @AppStorage parameter. However, I’m hoping there’s a more elegant way of disabling the modifier.
Example code here for matchedGeometry here: SwiftUI: Creating a custom segmented control using .matchedGeometry()
I found a promising article from TwoStraws but I cannot specify .matchedGeometryEffect
instead of .linear
as a type of animation like this:
Button("Ping pong") {
var transaction = Transaction(animation: .matchedGeometryEffect)
transaction.disablesAnimations = true
withTransaction(transaction) {
isFlipped.toggle()
}
}
Error message:
Type ‘Animation?’ has no member ‘_MatchedGeometryEffect’
Is there any other way to disable the .matchedGeometryEffect or am I doomed to write 2 almost identical views?