TabView doesn't show all tabs in tab mode.

Check my following code:

struct ContentView: View {
    var body: some View {
        TabView {
            Tab("Firsttt", systemImage: "plus") {
                MainScreen(name: "First")
            }
            .defaultVisibility(.hidden, for: .sidebar)
            
            Tab("Seconddd", systemImage: "plus") {
                MainScreen(name: "Second")
            }
            .defaultVisibility(.hidden, for: .sidebar)
            
            Tab("Thirddd", systemImage: "xmark") {
                MainScreen(name: "Third")
            }
            .defaultVisibility(.hidden, for: .sidebar)
            
            TabSection {
                Tab("Third", systemImage: "plus") {
                    MainScreen(name: "Third")
                }
                
                Tab("Fourth", systemImage: "plus") {
                    MainScreen(name: "Fourth")
                }
            } header: {
                Label("Group", systemImage: "plus")
            }
            .defaultVisibility(.hidden, for: .tabBar)
            
            TabSection {
                Tab("Section 1", systemImage: "plus") {
                    MainScreen(name: "Fourth")
                }
                
                Tab("Section 2", systemImage: "plus") {
                    MainScreen(name: "Fourth")
                }
                
                Tab("Section 3", systemImage: "plus") {
                    MainScreen(name: "Fourth")
                }
            } header: {
                Label("More", systemImage: "minus")
            }
            .defaultVisibility(.hidden, for: .tabBar)

        }
        .tabViewStyle(.sidebarAdaptable)
        
    }
}

My expectation is it would show three tab in tab mode. And two sections in sidebar mode. Side bar mode works as expected but tab bar shows only the first tab.

Answered by DTS Engineer in 790455022

@zoha131 This is because If you hide a tab in the sidebar using .defaultVisibility(.hidden, for: .sidebar), it is also hidden in the tab bar hence the first three Tabs are hidden.

You could set the defaultVisibility to visible to display the Tab.

Accepted Answer

@zoha131 This is because If you hide a tab in the sidebar using .defaultVisibility(.hidden, for: .sidebar), it is also hidden in the tab bar hence the first three Tabs are hidden.

You could set the defaultVisibility to visible to display the Tab.

TabView doesn't show all tabs in tab mode.
 
 
Q