Hinge interaction, layoutSubviews, etc – when we're supposed to get notified, and react to the change of pose/layout?
To identify when active reserved regions are changing in a SwiftUI view, follow these steps:
- Use a
GeometryReaderto access aGeometryProxyinstance within your view hierarchy. - Call reservedRegions(kind:options:layoutDirectionBehavior:) on the proxy to retrieve an array of
ReservedRegioninstances. - Specify a
ReservedRegion.Kindsuch as.occlusionor.divisionto filter the queried regions.
To monitor and respond to changing reserved regions in a UIKit application, follow these steps:
- Access the target UIView instance where you need to avoid hardware occlusions or folds.
- Call reservedRegions(kind:options:) on the view.
- Pass a
UIView.ReservedRegion.Kindvalue to inspect active or inactive frames for divisions and occlusions.
Note: UIKit provides methods and closures in several objects where automatic observation tracking happens, including for trait collection changes and updates to a view's layout or display. To learn more, see Updating views automatically with observation tracking in UIKit.
In addition to querying reserved regions directly, you can observe changes to the physical state and angle of the hinge to track when active regions shift. In SwiftUI, use the onHingeChange(isEnabled:_:) view modifier to receive updates through DeviceHingeContext. See SwiftUI updates for more details.
In UIKit, add a UIHingeInteraction to the view hierarchy to observe updates. The interaction handler delivers a UIHingeInteraction.Update containing the current UIHinge status, such as .closed, .partiallyOpen, or .fullyOpen. To learn more, see UIKit updates.
Cheers,
Paris X Pinkney | WWDR | DTS Engineer