I'm trying to fix an animation that stop working with IOS 14 update and I traced the issue to a code similar to:
struct ContentView: View {
var body: some View {
VStack {
Test()
Test()
Test()
}
}
}
struct ContentViewPreviews: PreviewProvider {
static var previews: some View {
ContentView().environmentObject(PublisherTest())
}
}
class PublisherTest: ObservableObject {
@Published var finished = Bool.random()
}
struct Test: View {
@EnvironmentObject var publicador: PublisherTest
@State var angle = Angle()
var body: some View {
Text("Test")
.rotationEffect(angle)
.onReceive(publicador.$finished) { in
withAnimation(Animation.default.speed(0.1)) {
angle.degrees = 180
}
}
}
}
I don't understand why the first Test() is rotated without animation and the others Test() are animated.
Thank very much for your advice.
struct ContentView: View {
var body: some View {
VStack {
Test()
Test()
Test()
}
}
}
struct ContentViewPreviews: PreviewProvider {
static var previews: some View {
ContentView().environmentObject(PublisherTest())
}
}
class PublisherTest: ObservableObject {
@Published var finished = Bool.random()
}
struct Test: View {
@EnvironmentObject var publicador: PublisherTest
@State var angle = Angle()
var body: some View {
Text("Test")
.rotationEffect(angle)
.onReceive(publicador.$finished) { in
withAnimation(Animation.default.speed(0.1)) {
angle.degrees = 180
}
}
}
}
I don't understand why the first Test() is rotated without animation and the others Test() are animated.
Thank very much for your advice.