NEW: Learn SwiftData for free with my all-new book! >>

Pro SwiftUI Twitter animation example problem

Forums > Books

Hello, I have a question about Pro SwiftUI. I understand how "like" animation works, but I don't understand why it remains visible after user toggles to the "unlike" state afterwards.

If transition code is removed, the states change in this order: 1) Outline heart 2) Filled heart 3) Outline heart

However, if animation is enabled, the last state is different: 1) Outline heart 2) Filledheart 3) Outline heart above filled heart

Can someone explain why?

Btw, to anyone reading this thread and possibly wondering how to make the animation restart multiple times - add id(UUID()) to dismiss the identity of animated object.

   

It starts behaving as it should if I add id(UUID()) to the button itself - well then button gets recreated completely and that makes sense. However, why the contents of the overlay remain visible without this change even though images have different IDs remains mistery to me.

   

Hacking with Swift is sponsored by Judo

SPONSORED Let’s face it, SwiftUI previews are limited, slow, and painful. Judo takes a different approach to building visually—think Interface Builder for SwiftUI. Build your interface in a completely visual canvas, then drag and drop into your Xcode project and wire up button clicks to custom code. Download the Mac App and start your free trial today!

Try now

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.