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
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?
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")
}
}
}