frzi / swiftui-router

Path-based routing in SwiftUI
MIT License
900 stars 43 forks source link

Full screen navigation above tabView #60

Closed IlyasNN closed 1 year ago

IlyasNN commented 1 year ago

How can I Create one more navigation stack above tabView?

So I need to present a few different flows under each of tab. But I can't fine approach to do that. I had a look in examples and there is no scenario I need.

I'll explain using one of examples: From one of the tabs I what to navigate further:

Screenshot 2022-11-07 at 18 52 43

How can I push View above tabView, not inside?

image

Please help)

frzi commented 1 year ago

This is actually very easy 🙂 All you need to do is put the entire tabView into another route.

E.g. if we have the ContentView:

struct ContentView: View {
    var body: some View {
        SwitchRoutes {
            Route("/settings/*", content: SettingsView())
            Route {
                ViewWithTabs() // <--- the 'tab view'
            }
        }
    }
}

We have a route that renders SettingsView for the path "/settings/*". For any other path the ViewWithTabs (in this case the so-called tabView) will be rendered.

Then, somewhere in ViewWithTabs (maybe as a tab itself) you need a NavLink that redirects to an absolute path (in this case "/settings"):

NavLink(to: "/settings") {
    VStack {
        Image(systemName: "gears")
        Text("Settings")
    }
}

In this case the entire ViewWithTabs will be replaced with the SettingsView, and thus allowing an entirely different flow of routing.

IlyasNN commented 1 year ago

Is there a way how I can save state of tabTab views with it's tabs' contents?

frzi commented 1 year ago

Sadly not automatically, no. You will need to come up with your own solution. (Maybe an environment object) This is a challenge you will face very often in SwiftUI 🙂

IlyasNN commented 1 year ago

It's very sad( Anyway, thank you for fast answer. I suppose this issue can be closed