Hi, everyone!
I hereby give up my prolonged lone struggle to comprehend how to handle this unwanted in this situation SwiftUI behavior which has led me no further than to consolidating what I know and exploring what I haven't practiced enough yet, which is still great. Yet the ongoing lack of a feasible solution is really frustrating. And I humbly ask for your help.
I have an Item
object that consists of properties like isItemNew
and amount
. Whenever the user adds a new item, it shows up in List
. I have a cell text animation set up to occur once a new Item
cell appears; it works by changing the values of my @State
properties, offset
and letterCount
, from within .onAppear(perform:)
. After the change, once the animation finishes, isItemNew
gets toggled with the help of asyncAfter(deadline:execute:)
to prevent animation from reoccuring.
The problem is the animation occurs every time SwiftUI reinvokes the view (closing and reopening the app, reloading Canvas in Xcode). If the user manipulated the amount
property of a newly added item, the animation is never reinvoked again, and that's asbolutely wanted.
How can I make the compiler remember right after the first animation happens that it shouldn't animate anymore after isItemNew
toggles to false
? I have that condition coded in my implicit .restrictedAnimation
custom view modifier, but the view is being refreshed along with the animation nontheless.
I've even created a custom .onFirstAppear
view modifier, not to mention prior trials with less extensive conditional statements, but to no avail. I reckon this has to do with the way SwiftUI handles view invocation, but I'm not sure how to deal with it in this situation. I feel as if the solution is childlishly simple, and it slips through my fingers, but here I am...
Any help would be very much appreciated!