AdaptiveTabView

0.5.1

An adaptive SwiftUI TabView that switches between TabView and NavigationSplitView.
mpdifran/AdaptiveTabView

What's New

v0.5.1

2023-05-27T17:09:58Z
  • Add support for providing a @State property to control column visibility when in sidebar mode.

AdaptiveTabView

An adaptive SwiftUI container that switches between TabView and NavigationSplitView based on horiontal size class. This framework allows you to easily build iPhone and iPad apps that conform to Apple's Human Interface Guidelines.

iPhone iPad
Preview iPhone Preview iPad

Here's an example of how it can be used:

@main
struct MyApp: App {
    @State private var selectedTab = MyFirstTab.identifier
    @State private var columnVisibility: NavigationSplitViewVisibility = .doubleColumn

    var body: some Scene {
        WindowGroup {
            AdaptiveTabView(
                appName: "My App", 
                selectedTab: selectedTab
            ) {
                MyFirstTab()
                MySecondTab()
                MyThirdTab()
            } defaultContent: {
                MyDefaultContentView()
            } defaultDetail: {
                MyDefaultDetailView()
            } sidebarExtraContent: {
                Section {
                    ForEach(folders) { (folder) in
                        FolderSidebarCell(folder)
                    }
                }   
            }
            .selectedTabTransformer(transformer)
        }
    }
    
    let transformer = SelectedTabTransformer { (kind, tabIdentifier) in
        switch kind {
        case .tabView:
            let sharedTabViewIdentifiers = [
                MyFirstTab.identifier,
                MySecondTab.identifier,
                MyThirdTab.identifier
            ]
            if !sharedTabViewIdentifiers.contains(tabIdentifier) {
                return MyFirstTab.identifier
            }
        case .sidebarView:
            break
        }
        return tabIdentifier
    }
}
extension MyFirstTab {
    static let identifier = TabIdentifier("MyFirstTab")
}

struct MyFirstTab: View, TitleImageProviding {
    let title = "My First Tab"
    let systemImageName = "1.square"
    let id = MyFirstTab.identifier

    var body: some View {
        ...
    }
}

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Sun Dec 01 2024 10:14:33 GMT-1000 (Hawaii-Aleutian Standard Time)