TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Difference between implicit and explicit animations?

Forums > 100 Days of SwiftUI

I am on day 33 of a 100 days with swiftui and I am not sure I understand the differences between explicit and implicit animations. Can someone break it down in layman's terms?

2      

Hey @morpheus. I think it kind of goes like this. It might be helpful of thinking of the animated views (i.e. what is being animated) and the animation triggers (i.e. what caused the state change which resulted in the view change). Implicit / explicit is thinking of the animation from the perspective of the animation trigger.

  • Implicit animations are where animation is specified on the animated views. You mark those views as if "hey, if you ever are animated, here's what to do". When a state change is triggered somewhere else the thing changing the state has no idea that this animation will happen, it just does because you told that view element what to do. The action code does not know the animation, so it's implicit.
  • Explicit animations are where the animation is specified by the animation trigger. You wrap the action in a withAnimation, and then can specify there at the point of the state change what the animation should be. The action code knows the animation, so it's explicit.

I think that's right, although I live to be corrected :-). I hope that helps, if it is a different way to describe it.

Al

3      

hi @alfraser,

i think you got this right, at least from what i understand.

after @morpheus posted this, i went looking to see if there was more, and apparently there's some subtlety in how animations will be applied, depending on whether they are implicit or explicit. see the one below, for example.

  • holyswift.app/difference-between-implicit-and-explicit-animations-in-swiftui/

hope that helps ... i know i learned something from it,

DMG

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.