Post

Replies

Boosts

Views

Activity

Reply to SwiftUI view state resetting after alert is shown
I am jumping in late to this discussion, and I am ignoring a couple details at this point until can I re-read a few times, but I did experience the same issue when attempting to attach a sheet to Buttons inside a List. It was about the same behaviour, with the sheet closing the first time it was opened, then it behaved reliably afterward. I spent time looking into making sure the items had a stable identity, but never found a way around the issue. I don't like the usage as much, but I ended up just moving the sheet outside the custom component and above the List, and everything is working as expected now. I was thinking there was something going on with 2-way binding and race conditions, and maybe something being managed based on animation completions (imagining something in a bridging layer to UIKit), but didn't dig into the thought too much. Also, I still know much more about React and other reactive JS setups than SwiftUI, though that's trending in the right direction. As a side note, I am curious about the package dependency that you're using and whether there are alternatives there. Again, not sure how helpful this is, but it might be something they're going to need to change if the view is used commonly inside Lists or other lazy containers. If you end up forking the package to attempt to adjust for your purposes, I would be interested in seeing it. I suppose it's just my long-winded way of saying you're not alone in the issue. I fought with the same problem for about a week before just accepting the muddier (though maybe better) state ownership and re-organizing the sheets/alerts/etc to exist outside the container.
Topic: UI Frameworks SubTopic: SwiftUI
2d