Contents

ReservedRegion

A region within a view’s coordinate space that another entity reserves.

Declaration

struct ReservedRegion

Overview

A reserved region indicates an area within a view’s coordinate space that an entity, such as the device hardware, reserves. Arrange the view’s content to account for this region. Each region describes a frame, margins, active state, and an identifier.

There are two categories of reserved regions:

occlusion

An area where an element, such as the Dynamic Island, a camera, or window controls, occludes content.

division

An area where content splits into separate regions, such as at the fold of a hinge.

Read reserved regions using the reservedRegions(kind:options:layoutDirectionBehavior:) method, which returns all of the reserved regions that currently intersect your view regardless of whether they are currently active.

In the example below, a custom Layout uses the reserved regions from a GeometryProxy instance to handle positioning its subviews away from any regions that intersect it.

GeometryReader { proxy in
    RegionAvoidingLayout(
        regions: proxy.reservedRegions(kind: .occlusion)
    ) {
        ForEach(items) { item in
            ItemView(item)
        }
    }
}    

When you manually position your content to incorporate reserved regions, consider right-to-left layout directions. Reserved regions are typically in a fixed coordinate space; the absolute location of a device’s camera doesn’t flip depending on a person’s preferred language. By default, the system mirrors the geometry of these regions automatically before it provides them to SwiftUI APIs.

For example, a Layout automatically flips the geometry of the subviews you place. By mirroring the geometry of the reserved regions, your layout doesn’t need to account for the layout direction when determining whether a particular subview intersects the region.

There may be cases when you need to make more manual adjustments for the frames of reserved regions for right-to-left layout directions. In these cases, you can provide the LayoutDirectionBehavior.fixed value to the method and the system doesn’t mirror the frames of the regions.

Topics

Getting region details

Querying reserved regions

Default Implementations

See Also

Measuring a view