Popping back multiple levels?

I have a UI where you can navigate/push views like this: Root view > List of things > View thing > Edit thing


The "Edit thing" view can also delete it. After a delete, I want it to pop back to the "List of things".


Best I've got now is to call `presentationMode.wrappedValue.dismiss()` on the "Edit thing" view, and then again in the "View thing" view, but that time inside DispatchQueue.main.async { }. It works but the double animation is kind of clunky.


Is there a better way?

Looks like that may have to do...


https://stackoverflow.com/questions/56513568/ios-swiftui-pop-or-dismiss-view-programmatically


At least/until SUI puts more meat on bones.

hi,


"what KMT said." wait for Swift 2.0.


for what it's worth, perhaps the functionality of View thing > Edit thing could be redesigned into a single View?


i have a simple project that i put out in public (while i am still learning SwiftUI and have no real idea where it will lead) where i have joined these functionalities. there is also a button in the combined View/Edit thing that deletes the object and returns to the list of things.


it uses CoreData for persistence -- which means that some things are a little magical because of the use of @FetchRequest and the fact that CoreData objects are already ObservableObjects -- but the concept is right, i think.


look at h ttps://github.com/DelawareMathGuy/ShoppingList.


***added as an after-thought. your Edit thing could return to your View thing, with edits showing in some obvious fashion, which could then prominently display a "save the changes you made to this View thing" before going back up the navigation stack to your List of things?


hope that helps,

DMG

Try NavigationViewKit https://github.com/fatbobman/NavigationViewKit

import NavigationViewKit
NavigationView {
            List(0..<10) { _ in
                NavigationLink("abc", destination: DetailView())
            }
        }
        .navigationViewManager(for: "nv1", afterBackDo: {print("back to root") })

in any view in NavigationView

@Environment(\.navigationManager) var nvmanager         

Button("back to root view") {
    nvmanager.wrappedValue.popToRoot(tag:"nv1"){
          	 print("other back")
           }
}

You can also call it through NotificationCenter without calling it in the view

let backToRootItem = NavigationViewManager.BackToRootItem(tag: "nv1", animated: false, action: {})
NotificationCenter.default.post(name: .NavigationViewManagerBackToRoot, object: backToRootItem)
Popping back multiple levels?
 
 
Q