UserInterfaceSizeClass
A set of values that indicate the visual size available to the view.
Declaration
type UserInterfaceSizeClass = 'compact' | 'regular';enum UserInterfaceSizeClassPass a literal, or build one with SwiftUI.UserInterfaceSizeClass from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'compact'SwiftUI.UserInterfaceSizeClass.compact'regular'SwiftUI.UserInterfaceSizeClass.regular
Overview
You receive a size class value when you read either the
EnvironmentValues.horizontalSizeClass or
EnvironmentValues.verticalSizeClass environment value. The value tells
you about the amount of space available to your views in a given
direction. You can read the size class like any other of the
EnvironmentValues, by creating a property with the Environment
property wrapper:
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
@Environment(\.verticalSizeClass) private var verticalSizeClassSwiftUI sets the size class based on several factors, including:
- The current device type.
- The orientation of the device.
- The appearance of Slide Over and Split View on iPad.
Several built-in views change their behavior based on the size class.
For example, a NavigationView presents a multicolumn view when
the horizontal size class is UserInterfaceSizeClass.regular,
but a single column otherwise. You can also adjust the appearance of
custom views by reading the size class and conditioning your views.
If you do, be prepared to handle size class changes while
your app runs, because factors like device orientation can change at
runtime.
From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Layout.
- AlignmentAn alignment in both axes.
- ContainerBackgroundPlacementThe placement of a container background.
- ContainerValuesReadableKeys of SwiftUI ContainerValues JavaScript can read.
- ContainerValuesWritableKeys of SwiftUI ContainerValues JavaScript can write.
- ControlSizeThe size classes, like regular or small, that you can apply to controls within a view.
- DocumentLaunchGeometryProxyA proxy for access to the frame of the scene and its title view.
- DynamicTypeSizeA Dynamic Type size, which specifies how large scalable content should be.
- EdgeAn enumeration to indicate one edge of a rectangle.
- EdgeInsetsThe inset distances for the sides of a rectangle.
- EdgeInsetsChainEdgeInsets with chained calls: SwiftUI.EdgeInsets.inset(...).
- EdgeSetAn efficient set of edges.
- GeometryProxyA proxy for access to the size and coordinate space (for anchor resolution) of the container view.