TechnologiesSwiftUI

ToolbarMinimizationSafeAreaAdjustment struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The safe area adjustment during toolbar minimization.

How it works

ToolbarMinimizationSafeAreaAdjustment controls how a scroll view's safe area responds when a minimizable toolbar collapses out of the way. When a toolbar minimizes as the user scrolls, the space it once occupied can either be reclaimed by your content or held in reserve, and this type lets you choose between those policies rather than accepting the default. Reach for it through the toolbarMinimizationSafeAreaAdjustment(_:) modifier whenever a toolbar's appear-and-disappear behavior causes your content to shift or clip in ways you want to tune.

  1. Choose an adjustment policy with the value

    ToolbarMinimizationSafeAreaAdjustment is a value type whose cases describe how aggressively SwiftUI reclaims the toolbar's safe-area inset as it minimizes. In the example the .automatic case lets the framework pick the standard behavior for the platform and toolbar placement, which is the right starting point before you opt into anything more specific.

  2. Apply it with toolbarMinimizationSafeAreaAdjustment(_:)

    You hand the value to the view modifier of the same name, which threads the policy down to the scrollable content that shares the toolbar's safe area. Here .toolbarMinimizationSafeAreaAdjustment(.automatic) is attached alongside .navigationTitle("Inbox") on the ScrollView, so the adjustment governs how the inbox list reflows when the bar collapses.

  3. Pair it with a minimizable toolbar

    The adjustment only has something to do when a toolbar can actually minimize, so it lives next to a .toolbar declaration. In the example the ToolbarItem(placement: .bottomBar) holding the Button("Compose", systemImage: "square.and.pencil") is the bar whose collapse the safe-area policy responds to.

  4. Let it ride on the scrolling content

    Because the policy is about safe-area insets, it takes effect as the user scrolls the surrounding ScrollView. The ForEach(1..<20) rows are what move through that changing inset, and the adjustment decides whether they slide up into the toolbar's vacated space or keep their original margin as the bar minimizes.

Try it — Swap .toolbarMinimizationSafeAreaAdjustment(.automatic) for a different case and scroll the inbox to watch whether the ForEach rows reclaim the bottom bar's space or leave it reserved as the toolbar minimizes.

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.

ToolbarMinimizationSafeAreaAdjustment.swift
struct ToolbarMinimizationSafeAreaAdjustmentDemo: View {
    var body: some View {
        NavigationStack {
            ScrollView {
                VStack(alignment: .leading, spacing: 12) {
                    ForEach(1..<20) { i in
                        Text("Row \(i)")
                            .frame(maxWidth: .infinity, alignment: .leading)
                            .padding()
                            .background(.quaternary)
                            .clipShape(RoundedRectangle(cornerRadius: 8))
                    }
                }
                .padding()
            }
            .navigationTitle("Inbox")
            .toolbarMinimizationSafeAreaAdjustment(.automatic)
            .toolbar {
                ToolbarItem(placement: .bottomBar) {
                    Button("Compose", systemImage: "square.and.pencil") {}
                }
            }
        }
    }
}
Live preview
Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12 Row 13 Row 14 Row 15 Row 16 Row 17 Row 18 Row 19 9:41 Inbox
Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12 Row 13 Row 14 Row 15 Row 16 Row 17 Row 18 Row 19 9:41 Inbox
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →