How to pop a NavigationButton programmatically?

So you can put a NavigationButton in a NavigationView and use the button destination to push a new View on the stack. Cool.


You can click the "back" button in the nav bar to go back. Also cool.


But how in the world do you "pop" the view programatically, say, like when a user hits a submit button and you've validated his entry?

I have the same question. There doesn't seem to be a way to explicitly control the navigation stack.

And how to return data, like with unWind segue and/or delegate pattern?

If you use Enviroment, Bindable and so on you will never need to return anything

It's true I can bind a value on screen B such that the original value on screen A is automatically updated (say, a selection list), but I have no way of programatically popping screen B so I go back to screen A.

I have run into the same problem when using a PresentationButton. Although in most cases you can swipe down to dismiss the presented view, in my case, I had a MapView in that window, and the scroll view was intercepting the swipe down event. I created a wrapper View that had a button in it, but I'm not sure what that button should do exactly... I tried calling self.hidden() in its action closure, but that didn't do anything. The best I could do for now was disable user interaction on the MapView so that the swipe gesture works, but I would love to know how to dismiss a modally presented view programatically.

If, as stated during the WWDC, everything in SwiftUI from scrollView contentOffset to Button highlight status is strictly related to the concept of Source-of-Truth and State/Binding, then there should be somewhere a State property (or something similar) that could be changed in order to alter the state of the Navigation. My two cents.

Hi guys, I'm new to Apple development world, and I'm learning SwiftUI, looking for navigation things I found this thread.

Looking further I've noticed the EditMode used with the EditButton, and it uses the Environment of EditMode to toggles it.

I looked in the autocomplete of the available Environment properties and found an interesting one, "isPresented".

@Environment(\.isPresented) var isPresented


With this property inside my detail view, I could close programmatically a Presentation View, by just calling

isPresented?.animation().value = false


Now we need some lights with the NavigationButton 😁.

I faced the same problem, how could we pop out the view from stack programmingly , because I need to hide the back button

How to pop a NavigationButton programmatically?
 
 
Q