Navigation using buttons

I am struggling with accommodation of programmatic NavigationLinks and Buttons. In a gist I have three views that represent a flow. First two views have a button that create a child state to be presented in the next view.

I present the next view using NavigationLink with isActive parameter that contains a binding created by view store.

Here's the confusion: the binding is created using getter for child state and sender of events. Even though it works ok (I had to come up with events for dismissal), I don't want to send any events in NavigationLink's binding part. I want it to be a "read-only" binding that gets its value changed in different places.

You can use the .constant binding which is read only. This will block swipe to dismiss and children using the environment to pop. It's often better to let the system handle the pop but use a binding derived from your store to act accordingly (cancel effect etc..).

1 Like

Thanks for your reply. I haven't tried your suggestion yet, and I wonder if using constant is soutable, because it's unchangable. I still need that binding to change from other place so that the child view could be dismissed.

A constant binding uses the value you pass in but never emits. Think of it as a read only binding.

Constant binding is constant. But I need it to change its value from other place.

I think “constant” may be a bit of a misnomer and it might be inappropriately named, as it’s not constant in the traditional sense; if the view hierarchy recomputes, the value of the binding will still be affected and change to reflect any updated values (I believe... please correct me if I am wrong here).

I guess only real code testing will tell the truth then :sweat_smile:

Terms of Service

Privacy Policy

Cookie Policy