How it works
TabCustomizationBehavior describes how much control a person has over an individual tab when a TabView enters customization mode — whether they can move it, hide it, or neither. You attach a behavior to a tab to opt it into reordering, lock it in place, or remove it from the customization UI entirely, giving you per-tab authority over an experience that is otherwise driven by the user. Reach for it whenever a sidebar-adaptable TabView exposes customization and certain tabs must stay fixed or remain immutable while others are free to be rearranged.
Choose a behavior with the type's static members
TabCustomizationBehaviorsupplies the named cases that express intent:.reorderablelets a person move the tab among its peers, while.disabledexcludes the tab from customization so it cannot be moved or hidden. You select one of these values and hand it to the tab; in the example.reorderablefrees the Browse tab and.disabledpins the Settings tab.Apply it with customizationBehavior(_:for:)
The
customizationBehavior(_:for:)modifier binds aTabCustomizationBehaviorto a tab for one or more placements. The first argument is the behavior; the variadicfor:argument lists the surfaces it governs. In the example,.customizationBehavior(.reorderable, for: .sidebar, .tabBar)and.customizationBehavior(.disabled, for: .sidebar, .tabBar)apply each behavior to both the sidebar and the tab bar at once.Give each tab a stable customizationID
A behavior only takes effect on a tab that SwiftUI can identify across launches, so each
Tabis tagged withcustomizationID(_:)—"tab.home","tab.browse", and"tab.settings". This identity is what lets the framework remember and persist a tab's customized state alongside the behavior you declared for it.Persist state through tabViewCustomization(_:)
The behaviors operate against a
TabViewCustomizationvalue that records what the person has changed. You hold it in@State private var customization = TabViewCustomization()and bind it with.tabViewCustomization($customization)so reordering and visibility edits are captured; tabs marked.disabledsimply never contribute changes to it.Enable customization with a sidebar-adaptable style
Customization, and therefore
TabCustomizationBehavior, is meaningful only when theTabViewpresents an editable layout. The.tabViewStyle(.sidebarAdaptable)modifier provides the sidebar-and-tab-bar presentation whose.sidebarand.tabBarplacements your behaviors target.
.customizationBehavior(.disabled, for: .sidebar, .tabBar) to .reorderable and watch a previously locked tab become draggable in the sidebar.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct TabCustomizationBehaviorDemo: View {
@State private var customization = TabViewCustomization()
var body: some View {
TabView {
Tab("Home", systemImage: "house") {
Text("Home").padding()
}
.customizationID("tab.home")
Tab("Browse", systemImage: "square.grid.2x2") {
Text("Browse").padding()
}
.customizationID("tab.browse")
.customizationBehavior(.reorderable, for: .sidebar, .tabBar)
Tab("Settings", systemImage: "gearshape") {
Text("Settings").padding()
}
.customizationID("tab.settings")
.customizationBehavior(.disabled, for: .sidebar, .tabBar)
}
.tabViewStyle(.sidebarAdaptable)
.tabViewCustomization($customization)
.padding()
}
}