Reputation: 467
I have HomeView which contains the TabView (which is inside a NavigationView, see the code below). If I am to load the HomeView from another view (LoginView) it loads as expected and everything works. If I try to load the HomeView directly like this (code is in my ContentView):
if authService.isLoggedIn {
HomeView()
} else {
LoginView()
}
it again loads the HomeView with the tabs at the bottom but my first tab is missing text and only displays its image. Strangely if I switch to a tab (i.e. click Account) the text on the first tab appears again.
Here is the code for my TabView:
NavigationView {
TabView(selection: $selected) {
PlayView()
.tabItem {
Image(systemName: "play.circle.fill")
.font(.system(size: 24))
Text("Play")
}
.navigationBarHidden(true)
.navigationBarTitle("")
.tag(1)
AccountView()
.tabItem {
Image(systemName: "person.circle.fill")
.font(.system(size: 24))
Text("Account")
}
.tag(3)
NotificationsView()
.tabItem {
Image(systemName: "bell.fill")
.font(.system(size: 24))
Text("Notifications")
}
.tag(4)
}
.accentColor(Color(K.Colors.Secondary))
.navigationBarTitle("")
.navigationBarHidden(true)
}
Note: Notice how the icon is displayed at lower level than other icons, so the text is actually not displaying at all
I did try only a few things, because the TabView is not very well documented on Apple's official documentation.
Upvotes: 0
Views: 1902
Reputation: 467
I have found a solution! Turns out what was showing at the bottom was that navigation bar title, which I was setting to an empty string. So I changed my navigation bar titles on every View of the TabView elements. The code now looks like this:
NavigationView {
TabView(selection: $selected) {
PlayView()
.tabItem {
Image(systemName: "play.circle.fill")
.font(.system(size: 24))
Text("Play")
}
.navigationBarHidden(true)
.navigationBarTitle("Play")
.tag(1)
AccountView()
.tabItem {
Image(systemName: "person.circle.fill")
.font(.system(size: 24))
Text("Account")
}
.navigationBarHidden(true)
.navigationBarTitle("Account")
.tag(3)
NotificationsView()
.tabItem {
Image(systemName: "bell.fill")
.font(.system(size: 24))
Text("Notifications")
}
.navigationBarHidden(true)
.navigationBarTitle("Notifications")
.tag(4)
}
.accentColor(Color(K.Colors.Secondary))
.navigationBarTitle("")
.navigationBarHidden(true)
}
and It works as expected.
Upvotes: 4