I have a view in which I would like to use the offset transition. It is my understanding that I can use the .animation function on AnyTransition to override the animation parameters of an explicit animation.
In this simple example, I would like the Rectangle transition to be 10x longer than the text moving.
It works when using AnyTransition.opacity
It does not work when using AnyTransition.offset
struct MyTestView: View {
@State var rectangleExists = false
var body: some View {
VStack {
if rectangleExists {
Rectangle().fill().foregroundColor(.red).padding()
//.transition(AnyTransition.opacity
.transition(AnyTransition.offset(x: 100, y: 0)
.animation(.linear(duration: 5)))
}
Text("Tap Me").onTapGesture {
withAnimation(.linear(duration: 0.5)) {
rectangleExists.toggle()
}
}
}
}
}