In the session it was recommended to use a TabView for Compact mode only on iPadOS. How do I achieve this easily in SwiftUI ?
You can check out the Fruta sample code project that does just this.
Sample project: https://developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui
Simplified relevant code:
Note that you may want to ensure your state is preserved in your destinations between your tab-based and list-based navigation views.
Sample project: https://developer.apple.com/documentation/swiftui/fruta_building_a_feature-rich_app_with_swiftui
Simplified relevant code:
Code Block struct ContentView: View { @Environment(\.horizontalSizeClass) private var horizontalSizeClass @ViewBuilder var body: some View { if horizontalSizeClass == .compact { TabView { /* Destination views with `.tabItem` modifiers */ } } else { NavigationView { List { /* List full of navigation links for column-based layout */ } } } } }
Note that you may want to ensure your state is preserved in your destinations between your tab-based and list-based navigation views.