SwiftfulRouting icon indicating copy to clipboard operation
SwiftfulRouting copied to clipboard

Pop to specific View

Open bhadresh13 opened this issue 1 year ago • 3 comments

View1 -> View2 -> View3 -> View4 How can I pop from View4 directly to View2 considering that we do not have control over the navigation stack ?

bhadresh13 avatar Sep 16 '24 05:09 bhadresh13

This framework is very use full for navigation. But I am also looking for above issue. I also want to navigate back to some specific screen

kjp151087 avatar Sep 25 '24 17:09 kjp151087

The way to do it currently would be to keep the reference to the router for each view. If you call "dismissScreen" on View3's Router, it should dismiss both View3 and View4.

The recommended approach would be to display View3 as a .sheet or .fullScreenCover, so that you could call "dismissEnvironment" to dismiss View3 and View4 (see Enter Screen Flows in the ReadMe: https://github.com/SwiftfulThinking/SwiftfulRouting).

In regards to pop to a specific view, this seems doable but it's quite difficult to implement - this isn't in the native SwiftUI framework either. I attempted it a few weeks ago and got pretty close but I need more time to implement it fully.

SwiftfulThinking avatar Sep 26 '24 23:09 SwiftfulThinking

Thanks a lot @SwiftfulThinking

bhadresh13 avatar Sep 27 '24 04:09 bhadresh13

Please take care of this in ur future releases as it will be very helpful to the developers.

cah-suresh-kumar04 avatar Oct 09 '24 04:10 cah-suresh-kumar04

The way to do it currently would be to keep the reference to the router for each view. If you call "dismissScreen" on View3's Router, it should dismiss both View3 and View4.

@SwiftfulThinking I tried this, but it didn't seems to work for me. View1 -> View2 -> View3 -> View4. When I call dismissScreen in View4 with the router of View3, nothing happens. Is that correct?

davidnext avatar Nov 08 '24 09:11 davidnext

Please take care of this in ur future releases as it will be very helpful to the developers.

CoderLGL avatar Nov 08 '24 09:11 CoderLGL

this isn't in the native SwiftUI framework either.

I thought you could do this with the native framework. You would just update the stack/path. It's just an array. So, you could do path.removeLast(2) or use something like lastIndex(where:) to pop back to a specific screen. I actually need this functionality currently. Hope this makes it in very soon. 🤞

marlonjames71 avatar Apr 16 '25 01:04 marlonjames71

Added additional dismiss support, including "dismiss count" and "dismiss to id" in Version 6 (https://github.com/SwiftfulThinking/SwiftfulRouting/releases/tag/beta-6.1)

SwiftfulThinking avatar Apr 20 '25 17:04 SwiftfulThinking