How it works
SidebarRowSize is an enumeration that describes the standard control sizes a sidebar uses to lay out its rows, letting you choose between compact, medium, and large row metrics. SwiftUI reads this value from the environment when rendering a sidebar-style List, scaling row height, label spacing, and the size of leading icons to match. Reach for it when the default density doesn't fit your content — for example, to give a navigation sidebar a roomier, touch-friendly feel, or to tighten it up so more items are visible at once.
Pick a row size from the SidebarRowSize cases
SidebarRowSize is a frozen enum whose cases name the available densities —
small,medium, andlarge. Each case maps to a system-defined set of metrics for row height and icon sizing, so you express intent ("give me large rows") rather than hardcoding point values. In the example the choice is.large, the most spacious option.Apply it through the sidebarRowSize environment key
You don't set SidebarRowSize on a view directly; you publish it into the environment with the
\.sidebarRowSizekey value, and the enclosing sidebar reads it when laying out its rows. Here.environment(\.sidebarRowSize, .large)is attached to theList, telling every row inside that list to adopt the large metrics.Let the rows inherit the value
Because the size travels through the environment, it propagates to the descendants of the view it's set on without each row opting in. The three
Labelrows —"Inbox","Sent", and"Archive"— pick up the.largesizing automatically, growing their height and thesystemImageglyphs to match the chosen density.Combine it with the sidebar list style
SidebarRowSize takes effect where SwiftUI draws sidebar-style rows, so it pairs with a
Listpresented as a sidebar (for instance inside a NavigationSplitView column). TheListin the example is the surface that interprets the value; placing the.environmentmodifier on that list is what scopes the row size to exactly those rows.
.environment(\.sidebarRowSize, .large) to .medium or .small and watch the row height and the systemImage icons in the three Labels shrink to a denser layout.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 SidebarRowSizeDemo: View {
var body: some View {
List {
Label("Inbox", systemImage: "tray")
Label("Sent", systemImage: "paperplane")
Label("Archive", systemImage: "archivebox")
}
.environment(\.sidebarRowSize, .large)
.padding()
}
}