How can I Hide TabBar in specific Views, in iOS 15 using SwiftUI

Viewed 1286

I need my TabBar to disappear if I click on a NavigationLink. I know you can achieve that in iOS 14 with the following code:

 NavigationView{
        TabView{
            View1().tabItem {
                Image(systemName: "house.fill")
                Text("Home")
            }
        }
    }

And View1:

struct View1: some View {
var body: some View {
    NavigationView{
        NavigationLink(destination: Text("New Page without the Tabbar")) {
            Text("Link")
        }
    }
}
}

But somehow this don't works in iOS 15... Are there any other workarounds?

1 Answers

You could try using only one NavigationView, like in this example:

import SwiftUI

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        NavigationView {
            TabView {
                View1().tabItem {
                    Image(systemName: "house.fill")
                    Text("Home")
                }
            }
        }
    }
}

struct View1: View {
    var body: some View {
        // ---> here no NavigationView
        NavigationLink(destination: Text("New Page without the Tabbar")) {
            Text("Link")
        }
    }
}
Related