How to get the correct animation when inserting/removing a row in a SwiftUI List from a swipeAction?
Hello,
In my app, I have a List with two sections.
The first section contains favourited items.
The second section contains all the items.
I use a swipeAction to favorite / undo favorite an item. An item can be in the first section and in the second section.
But when I use the swipeAction to perform the action, the row animation is conflicting with the List animation for insertion / removal (I think). It’s not synchronised and it leads to an ugly UX. GeometryGroup on the Section does not help.
One solution is to delay the action so the swipe has enough time to go back to its original position but it’s hacky and depends too much on manual timing, etc.
If I favorite / undo from a tap on the row (no swipe action), the animation is correct (obviously, as the row doesn’t need to animate to its original position).
I experimented with a ScrollView + swipeActionsContainer() + swipeActions on iOS 27, and it works very nicely. But this solution only works for iOS 27 and my app targets iOS 18. So I would love to have a native implementation for iOS 18+ if possible.
Am I missing something to get the correct animation with a List?
You can check the attached code: https://gist.github.com/alpennec/f9de25cda29b515eb45af6b368a89ed8
Video: https://www.dropbox.com/scl/fi/sqitivihm4pbu8htxicap/ListSectionsSwipeActions.mov?rlkey=08wl708g82rmyy6nkf75725bv&st=0qb7rhdd&dl=0
I also filed a feedback with a video: FB23661327
Regards,
Axel
1
1
30