how do you use the new navigationsplitview

Asked on 08/09/2024

1 search

To use the new NavigationSplitView in SwiftUI, you can follow the guidance provided in the WWDC sessions. Here are some key points and sessions that discuss the new navigation features:

  1. Adopting the Sidebar Appearance:

    • In tvOS 18, the floating sidebar from the TV app is now available system-wide through SwiftUI. You can build it using the existing NavigationSplitView APIs. If your app is currently using a tab bar, you can switch to this appearance with just one line of code by setting a TabView style of sidebarAdaptable. This will make your tab bar appear as a sidebar.
    • Migrate your TVML app to SwiftUI (14:22)
  2. Flexible Sidebar and Tab Bar:

    • In iOS 18, the sidebar has become more flexible. You can easily switch between a tab bar and a sidebar representation. The new TabView has a type-safe syntax in SwiftUI, making it easier to catch common errors at build time. You can apply the new sidebarAdaptable tab view style to make your tab view more flexible.
    • What’s new in SwiftUI (01:02)
  3. Enhanced Sidebar and Tab Bar Experience:

    • The new tab bar can float above the content and morph into a sidebar for deeper navigation. This is useful for apps with a simple hierarchy or a deeper hierarchy, allowing you to implement both a tab bar and sidebar with the same API.
    • Platforms State of the Union (47:40)
  4. Customization and Flexibility:

    • The sidebar supports customization features like reordering and removing tabs, which is programmatically controllable. This makes it great for content-rich apps.
    • What’s new in SwiftUI (01:57)
  5. Best Practices for Tab and Sidebar Navigation:

By following these guidelines and utilizing the new APIs, you can effectively use NavigationSplitView to create a flexible and customizable navigation experience in your SwiftUI apps.