TabViewCustomization
The customizations a person makes to an adaptable sidebar tab view.
Declaration
type TabViewCustomization = TabViewCustomizationChain;struct TabViewCustomizationOverview
By default, if a person hasn't made customizations, tabs appear according to the default builder visibilities and sections appear in the order you declare in the tab view's tab builder.
You can change the default visibility by using the
TabContent.defaultVisibility(_:for:) with a
AdaptableTabBarPlacement.sidebar placement.
You can change the default section order by changing the order
in the builder. If there's an existing persisted customization,
reset the order by calling
TabViewCustomization.SectionCustomization.resetTabOrder()
when you change the order.
All tabs and tab sections that support customization need to have
a customization ID. You can mark a tab as being non-customizable
by specifying a TabCustomizationBehavior.disabled behavior
in all adaptable tab bar placements
using TabContent.customizationBehavior(_:for:)-2u727.
On macOS, a default interaction is provided for reordering sections but not for controlling the visibility of individual tabs. A custom experience should be provided if desired by setting the visibility of the tab on the customization.
The following code example uses @AppStorage to automatically persist
any visibility or section order customizations a person makes.
@AppStorage
private var customization: TabViewCustomization
TabView {
Tab("Home", systemImage: "house") {
MyHomeView()
}
.customizationID("com.myApp.home")
Tab("Reports", systemImage: "chart.bar") {
MyReportsView()
}
.customizationID("com.myApp.reports")
TabSection("Categories") {
Tab("Climate", systemImage: "fan") {
ClimateView()
}
.customizationID("com.myApp.climate")
Tab("Lights", systemImage: "lightbulb") {
LightsView()
}
.customizationID("com.myApp.lights")
}
.customizationID("com.myApp.browse")
}
.tabViewStyle(.sidebarAdaptable)
.tabViewCustomization($customization)From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
- AppStorageA property wrapper type that reflects a value from UserDefaults and invalidates a view on a change in value in that user default.
- SceneStorageA property wrapper type that reads and writes to persisted, per-scene storage.
- tabViewCustomizationSpecifies the customizations to apply to the sidebar representation of the tab view.
- createTabViewCustomizationStarts a SwiftUI TabViewCustomization. Each call returns a new value, as compose() does.
See also
More in Navigation.
- AdaptableTabBarPlacementA placement for tabs in a tab view using the adaptable sidebar style.
- AutomaticNavigationTransitionA style that automatically chooses the appropriate presentation transition for the current context.
- ContentToolbarPlacementA region of the interface that hosts its own toolbar content.
- CrossFadeNavigationTransitionA navigation transition that cross-fades between the appearing view and the disappearing view.
- DismissSearchActionAn action that can end a search interaction.
- NavigationBarItemTitleDisplayModeA style for displaying the title of a navigation bar.
- NavigationPathA type-erased list of data representing the content of a navigation stack.
- NavigationPathChainNavigationPath with chained calls: SwiftUI.NavigationPath.append(...).
- NavigationPathCodableRepresentationA serializable representation of a navigation path.
- NavigationSplitViewColumnA view that represents a column in a navigation split view.
- NavigationSplitViewVisibilityThe visibility of the leading columns in a navigation split view.
- NavigationTransitionA type that defines the transition to use when navigating to a view.