Hi folks,
I’ve been trying to use the new .animation(_:body:)
overload without success. I’m attempting to animate multiple properties of a view, each with different animations. This overload seems to be the perfect candidate to achieve that.
Here's the code I'm using:
struct ContentView: View {
@State private var isAnimating = false
var body: some View {
Text("Hello World")
.font(.largeTitle)
.animation(.easeOut(duration: 1)) {
$0.foregroundStyle(isAnimating ? .red : .blue)
}
.animation(.linear(duration: 10)) {
$0.offset(x: isAnimating ? -100 : 0)
}
.onAppear {
isAnimating = true
}
}
}
Pretty straightforward, but I don’t get any animations at all.
Of course, I could wrap isAnimating = true
in a withAnimation
closure, but the WWDC session about those APIs mentions this is not needed. Furthermore, if I do that, the animations I provide in .animation(_:body:)
are not being used.
I’m really confused by this new API, and I’m starting to think it doesn’t work as advertised.