How it works
ToolbarMinimizeBehavior describes when a toolbar should collapse its items into a compact, minimized form rather than displaying them at full size. It lets you trade toolbar prominence for content space, deciding whether the bar stays expanded, condenses automatically, or condenses in response to scrolling. Reach for it when a toolbar competes with scrollable content for vertical room and you want the system to reclaim that room as the reader moves through the view.
Apply the behavior with toolbarMinimizeBehavior(_:)
The view modifier toolbarMinimizeBehavior(_:) attaches a ToolbarMinimizeBehavior to the toolbar of the view it modifies, instructing SwiftUI when to minimize the bar's contents. In the example it is applied to the NavigationStack's content as
.toolbarMinimizeBehavior(.onScrollDown), governing the toolbar declared just above it.Choose a case to set the policy
ToolbarMinimizeBehavior is a value you select rather than configure, so you pass one of its predefined cases to express the policy. The example passes
.onScrollDown, which tells the toolbar to minimize as the reader scrolls downward through the content and restore itself otherwise.Pair it with a toolbar that has items to minimize
The behavior only matters when there is a toolbar to act on, so it works in concert with a
.toolbarblock. Here thetoolbarholds a singleToolbarItem(placement: .primaryAction)containing aButton("Compose", systemImage: "square.and.pencil")— that item is the content the behavior expands or condenses.Scope it to the navigation context
Toolbar minimization is most meaningful inside a navigation container, where the bar and a title share the top edge with scrolling content. The modifier sits within the
NavigationStackalongside.navigationTitle("Inbox"), so the minimize behavior coordinates with the navigation bar that hosts the toolbar.
.toolbarMinimizeBehavior(.onScrollDown) to .toolbarMinimizeBehavior(.never) and scroll the rows — the toolbar stays fully expanded instead of collapsing as you move down.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 ToolbarMinimizeBehaviorDemo: View {
var body: some View {
NavigationStack {
ScrollView {
ForEach(0..<20) { i in
Text("Row \(i + 1)")
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
}
}
.navigationTitle("Inbox")
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button("Compose", systemImage: "square.and.pencil") {}
}
}
.toolbarMinimizeBehavior(.onScrollDown)
}
}
}