Hi, I'm experiencing the behaviour outlined below. When I navigate programmatically on iPadOS or macOS from a tab that hides the tab bar to another tab, the tab bar remains hidden. The real app has it's entry point in UIKit (i.e. it uses an UITabBarController
instead of a SwiftUI TabView)
but since the problem is reproducible with a SwiftUI only app, I used one for the sake of simplicity.
import SwiftUI
@main
struct HiddenTabBarTestApp: App {
@State private var selectedIndex = 0
var body: some Scene {
WindowGroup {
TabView(selection: $selectedIndex) {
Text("First Tab")
.tabItem {
Label("1", systemImage: "1.circle")
}
.tag(0)
NavigationStack {
Button("Go to first tab") {
selectedIndex = 0
}
.searchable(text: .constant(""))
}
.tabItem {
Label("2", systemImage: "2.circle")
}
.tag(1)
}
}
}
}
Reproduction:
- Create a new SwiftUI App with the iOS App template and use the code from above
- Run the app on iPadOS or macOS
- Navigate to the second tab
- Click into the search bar
- Click the "Go to first tab" button
- The tab bar is no longer visible
Is this a bug in the Framework or is it the expected behaviour? If it's the expected behaviour, do you have a good solution/workaround that doesn't require me to end the search programmatically (e.g. by using @Environment(\.dismissSearch)
) before navigating to another tab? The goal would be to show the tab bar in the first tab while keeping the search open in the second tab.