2

I’m building a Files-style SwiftUI app and my primary goal is to adopt both:

  • NavigationSplitView on wider (regular) widths (iPad/macOS), and

  • TabView + NavigationStack on narrow (compact) widths (iPhone),

—so that the app feels native on any device.

Beyond simply swapping containers, I need two key behaviors:

  1. Completely remove the tab bar when in regular width (so no tab bar floating above the app).

  2. Preserve the full navigation hierarchy across size-class changes — for example, if the user drills into Browse → Documents → MyFolder → FileInfo on iPad, then rotates or switches to iPhone width, the compact stack should land directly in FileInfo with its back-button chain intact, and vice versa.

This kind of visual structure is present in 'Files', 'Shortcuts', 'Health' app. Any insights? Thanks!

enter image description hereenter image description here

I tried to wrap NavigationSplitView() within TabView() but I was unable to hide the TabView on .regular horizontalClassSize (i.e. wider width view).

6
  • 2
    Isn't that just a TabView with .sidebarAdaptable style? There is no NavigationSplitView. Commented Jun 13 at 16:03
  • Fair point. I want to adopt multi-pane navigation for iPad. If I adopt TabView I can no longer implement NavigationSplitView as that would mean I will have 2 sidebars. Commented Jun 13 at 19:26
  • TabView goes multipane on iPad Commented Jun 13 at 20:59
  • @malhal I'm looking for multipane for the content/detail view, not just only the sidebar Commented Jun 13 at 21:56
  • How about .inspector for the detail? That’s a pane in regular and sheet in compact. Commented Jun 14 at 5:45

1 Answer 1

0

If you use tabViewStyle(_:) with .sidebarAdaptable, your app can show both a sidebar and a tab bar depending on the platform.

import SwiftUI

struct SidebarAdaptableView: View {
    var body: some View {
        TabView {
            Tab("Home", systemImage: "house") {
                Text("My Works")
            }

            Tab("Library", systemImage: "books.vertical") {
                Text("All Books")
            }

            Tab("Search", systemImage: "magnifyingglass") {
                Text("Search Books")
            }

            Tab("Profile", systemImage: "person") {
                Text("My Profile")
            }
        }
        // Apply the sidebarAdaptable style
        .tabViewStyle(.sidebarAdaptable)
    }
}

sidebarAdaptable

A tab bar style that adapts to each platform.

Tab views using the sidebar adaptable style have an appearance that varies depending on the platform:

  • iPadOS displays a top tab bar that can adapt into a sidebar.
  • iOS displays a bottom tab bar.
  • macOS and tvOS always show a sidebar.
  • visionOS shows an ornament and also shows a sidebar for secondary tabs within a TabSection.

To apply this style to a tab view, or to a view that contains tab views, use the tabViewStyle(_:) modifier.

Source link

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.