I recently got downvoted into oblivion for explaining why someone's List animation was glitching, perhaps because the solution is so simple it seems stupid.

On the left is swipeAction with a Button. On the right is the exact same Button, but now the animation is smooth.

The difference? I set the Button's role to destructive. SwiftUI uses the role to infer what animation to use. gist.github.com/phillipcaudell

This doesn't seem that intuitive at first, but if you think about it, how would SwiftUI anticipate what action will be performed on your model?

In iOS 17 the animation has been improved considerably if you don't explicitly set the role, but for best results you still need to set it.

@phill I still find the animation to be wrong when I use a confirmationDialog for the destructive action in the swipeAction. When I do that in SwiftUI, it seems to different that what we can find in Messages app for example when deleting a conversation.

Have you encountered this too?

@alpennec AFAIK there is no equivalent of UIContextualAction's handler in SwiftUI. Messages is likely using that to defer the editing commit until the user has confirmed. Since there is no callback on swipeAction I'm not sure how it would be possible.

@phill I see. Currently, the row disappears then reappears when the confirmationDialog is presented... which is ugly but I guess I can’t do better for now 😞

Follow

@alpennec in this instance I would say it's actually better to not denote it with the destructive role. At least then it'll defer the delete animation until confirmation.

Edit: video loop makes it look jumpy, but it’s completely glitch free 😛

· Edited · · Ivory for Mac · 1 · 0 · 3

@phill oh I’ve never thought about that! Thanks for the tip. I will loose the accessibility stuff but the visual aspect feels better.

Sign in to participate in the conversation
The Not So Big Company

The home of The Not So Big Company on Mastodon.