Post

Replies

Boosts

Views

Activity

So... AnimatableModifier is now deprecated, but how to "use Animatable directly"?
I am aiming to achieve a callback when an animation of offset change is finished. So, I found a workaround online which uses the AnimatableModifier to check when the animatableData equals the target value. But it turns out AnimatableModifier is now deprecated. And I cannot find an alternative to it. I am aware that GeometryEffect will work for this case of offset change, where you could use ProjectionTransform to do the trick. But I am more concerned about the official recommendation to "use Animatable directly". Seriously, the only tutorial about the Animatable protocol I can find online is examples of using the Shape struct which implicitly implements the Animatable protocol. And the following code I improvised with the Animatable protocol doesn't even do the "animating". Thanks for your kind reading, and maybe oncoming answers!
3
1
1.7k
Jan ’22
SwiftUI opacity animation fails in Gesture's onEnded method
As shown in the gif below, the second tap on the purple rectangle does not trigger the animation for the blue rectangle to fade in. Is this a Bug or an obscure Feature? Thanks for your kind reply! trying to toggle the opacity of the big blue rectangle with animation: https://i.stack.imgur.com/teMq3.gif struct FadeTestView: View {  @State var fade: Bool = false  var body: some View {   VStack{    Rectangle().fill(.blue).frame(width: 100, height: 100, alignment: .center)     .opacity(fade ? 0 : 1)         Button(action: {     withAnimation(.easeInOut(duration: 2)){ fade.toggle() }    }){     Circle().fill(.yellow).frame(width: 50, height: 50, alignment: .center)    }         Rectangle().fill(.purple).frame(width: 50, height: 50, alignment: .center)     .gesture(TapGesture().onEnded{      withAnimation(.easeInOut(duration: 2)){ fade.toggle() }     })   }  } }
1
0
2.9k
Jan ’22