|
I am trying to open a sheet with the summary of a times tables quiz for the day 35 challenge. But whenever it opens it closes immediately. Thankyou in advance: PlayView (This opens the sheet)
SummaryView(What the sheet opens)
|
|
Your state value change right before showing the sheet is causing a redraw on the View, thus resetting the state Bool to false, methinks. Try decoupling the state changes you make before it, or DispatchQueue.main.async{...}'ing the Bool change to show. In short, though, your best time spent is some redesign work, and ensure that your button push's only real responsibility is to set that Bool to true to show the Sheet. That's your biggest issue - making state changes, then showing a Sheet (or anything else) right on the heels of that while the View is redraw(n / ing) |
|
All of this....
... is your problem. Maybe consider making the State changes (that cause the View redraw) as the after-the-sheet-is-dismissed functionality.
Like... deal with all the stuff involving THIS question here and now, THEN prep, calculate scores (etc), for the View draw on the next question. So to expand on your ideal here, ask the question, get the the answer, show the subview with parent view's data + new values without changing the old values, then on dismiss, update the old values, pluck the new question, redraw. Doing your user-visibile View updates after the sheet goes away is perfectly fine since (in theory, not having seen your sheet content), the Sheet covers the current View (or at least obscures it enough) that the updates having later don't matter - and may make for a more cohesive workflow anyway. $.02 (the design just needs more thought put into it, in terms of flow and how the data informs the draw) |
|
To expand... state, and all incoming information should inform the View how to draw itself, rather than being some fungible pool of bits that each view can swizzle around at a whim. If you go into SwiftUI with the mindset that "every single thing I touch will make this View draw again", you can start to see why extra-View data manipulation, and pre-View ducks-in-a-row setup becomes an early-in-the-design consideration, long before you start writing the code. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.