Dismissing NavigationLinks and fullScreenCovers with IfLetStore programmatically #1030
Unanswered
thebarndog
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Hey @thebarndog do you have a small reproducible example? It could be similar to #953 (reply in thread) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@stephencelis I found an interesting issue, one I'd like to get your thoughts on. I posted about a related issue here #996 and I figured I would create another discussion to expand on this issue.
My application does not use the standard
viewStore.binding
mechanism when dealing with NavigationLinks or.fullScreenCover
. That is to say, my navigation links are entirely programmatic and are hidden from the user (because they're not a tappable link) so I'm faced with a situation where a true value is never sent to the binding because it's not tappable. To get around that, I use a.constant
binding in the form.constant(viewStore.presentPurchasePage)
. Then, when the optional sub-state changes in my reducer i.e.state.purchase = .init()
, the binding evaluates totrue
and the navigation link is presented. An example of what that might look like is:The problem comes in on dismissal. I have a custom dismiss button that fires off an action that essentially amounts to setting that substate to nil, i.e.
state.purchase = nil
. When that happens however, theIfLetStore
immediately evaluates tonil
and the entire destination view disappears from the view hierarchy before the navigation link animation occurs, leaving an incredibly jarring user experience. This is also true when usingfullScreenCover
.I actually did find a workaround to this issue but I don't love it. In the presented view, when the dismiss button is pressed, I dispatch
viewStore.send(.dismiss, animation: .easeIn)
. Adding an animation causes the view dismissal transition to happen correctly and the navigation link dismisses correctly without the destination view disappearing prematurely. The reason I don't like it is because now I have to add animations to every single dispatch that causes dismissal animations to happen and the chance for user error is high. Also, the animation I pass is completely irrelevant as navigation links and full screen covers already have their own dismissal.Have you ever seen anything like this before? Maybe it's all just user error and I would love to know how to correctly programmatically present a navigation link or full-screen cover.
Beta Was this translation helpful? Give feedback.
All reactions