Hello,
I'm trying to hide my TabView
when I push a new view in my NavigationView
but for now it seems that there is no way to do it (I saw a lot of thing on Internet, but nothing seems work properly for me)?
By default my code look like this:
struct ContentView: View {
var body: some View {
TabView {
NavigationView {
view1
}
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}
NavigationView {
view2
}
.tabItem {
Image(systemName: "bookmark.circle.fill")
Text("Bookmark")
}
}
.accentColor(.red)
}
private var view1: some View {
List {
NavigationLink {
DetailsView()
} label: {
Text("View 1")
}
}
.navigationTitle("View 1")
}
private var view2: some View {
List {
NavigationLink {
DetailsView()
} label: {
Text("View 2")
}
}
.navigationTitle("View 2")
}
}
struct DetailsView: View {
var body: some View {
EmptyView()
}
}
But then, I don't have any solution to hide my TabView
, so I try something like this in my ContentView
:
var body: some View {
NavigationView {
TabView {
view1
.tabItem {
Image(systemName: "house.fill")
Text("Home")
}
.navigationTitle(Text("title"))
view2
.tabItem {
Image(systemName: "bookmark.circle.fill")
Text("Bookmark")
}
.navigationTitle(Text("title"))
}
.accentColor(.red)
}
}
Now, the hide on push is working, but it cause some glitch in the navigation bar and I can't set multiple navigationTitle
(one for each view) like I did before; I can set only one navigationTitle
for the NavigationView
.
To solve the NavigationView
title, I found a workaround by using a @State
variable, but it remains this glitch on the navigation bar: sometimes the navigation view background is working, sometimes it's not working and sometimes I have a spacing between the title and the content (like in the Bookmark tab):
What am I doing wrong?
Does it exist any solution for this issue (hidesBottomBarWhenPushed
+ navigation bar glitch) ?
Thanks,
Alexandre