to summarize my problem:
My application contains a TabView
on the root level. The children of the TabView must be searchable (using the apple native .searchable(...)
modifier. Additionally at least one of the views must be able to push a third view on the stack which hides the TabBar on the bottom.
The problem with that is that both approaches: Using one single NavigationView in the root view and using additional navigation views inside the child views did not work.
Using only one NavigationView:
- TabBar gets overlayed when navigating to another acitivty ✔
- Not searchable ❌
Using nested NavigationViews:
- TabBar is always visible also in the full screen activity ❌
- Desired title + search behavior ✔
Root View:
public enum TestNavItemId: String, CaseIterable, Equatable {
case activity1 = "activity1"
case activity2 = "activity2"
public static func == (lhs: NavItemId, rhs: NavItemId) -> Bool {
lhs.rawValue == rhs.rawValue
}
}
struct DemoView: View {
var body: some View {
NavigationView {
TabView {
Activity1()
.tabItem {
Image(systemName: "house.fill")
Text(LocalizedStringKey(TestNavItemId.activity1.rawValue))
}
.tag(TestNavItemId.activity1)
Text("Nothing to see here")
.tabItem {
Image(systemName: "fire")
Text(LocalizedStringKey(TestNavItemId.activity2.rawValue))
}
.tag(TestNavItemId.activity2)
}
}
}
}
Activity1:
struct Activity1: View {
@State private var query: String = ""
var body: some View {
NavigationView {
VStack {
Text("Content")
NavigationLink(destination: Text("Full Screen View")) {
Text("Open full screen view")
}
}
.searchable(text: $query)
}
}
}
Any help is much appreciated!