Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabView has delay when changing visibility

I have a TabView and in a certain subview I want to hide the toolbar. This can be done with .toolbar(.hidden, for: .tabBar). The problem is when the toolbar becomes visible again: the toolbar takes a long time to show up again.

It is easily reproducible with the following code:

struct ContentView: View {
    var body: some View {
        TabView {
            NavigationStack {
                NavigationLink("Tap Me") {
                    Text("Detail View")
                        .toolbar(.hidden, for: .tabBar)
                }
                .navigationTitle("Primary View")
            }
            .tabItem {
                Label("Home", systemImage: "house")
            }
        }
    }
}

The delay can be seen in the following GIF GIF of TabView having a delay before it becomes visible again

It honestly seems to me like this native functionality is bugged. I tried the SwiftUI Introspect package but also got a delay here.

Is there any fix for this problem?

like image 327
Ruben Veldman Avatar asked Dec 10 '25 11:12

Ruben Veldman


1 Answers

Changed a little bit your code, place NavigationStack upon TabBar, because you can specify navigation stack like main view. So it works fine, without delay.

struct SwiftUIView: View {
    var body: some View {
        NavigationStack {
            TabView {
                    NavigationLink("Tap Me") {
                        Text("Detail View")
                            .toolbar(.hidden, for: .tabBar)
                    }
                .tabItem {
                    Label("Home", systemImage: "house")
                }
            }
            .navigationTitle("Primary View")
        }
    }
}
like image 197
Arsienij Avatar answered Dec 13 '25 02:12

Arsienij



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!