CoordinateSpaceProtocol
A frame of reference within the layout system.
Declaration
type CoordinateSpaceProtocol =
| 'global'
| 'local'
| 'scrollView'
| { named: string | number | boolean; }
| { scrollView: { axis: Axis; }; }
| GlobalCoordinateSpace
| LocalCoordinateSpace
| NamedCoordinateSpace;protocol CoordinateSpaceProtocolPass a literal, or build one with SwiftUI.CoordinateSpaceProtocol from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'global'SwiftUI.CoordinateSpaceProtocol.globalThe global coordinate space at the root of the view hierarchy.
'local'SwiftUI.CoordinateSpaceProtocol.localThe local coordinate space of the current view.
'scrollView'SwiftUI.CoordinateSpaceProtocol.scrollViewThe named coordinate space that is added by the system for the innermost containing scroll view.
Type methods
Overview
All geometric properties of a view, including size, position, and
transform, are defined within the local coordinate space of the view's
parent. These values can be converted into other coordinate spaces
by passing types conforming to this protocol into functions such as
GeometryProxy.frame(in:).
For example, a named coordinate space allows you to convert the frame
of a view into the local coordinate space of an ancestor view by defining
a named coordinate space using the coordinateSpace(_:) modifier, then
passing that same named coordinate space into the frame(in:) function.
VStack {
GeometryReader { geometryProxy in
let distanceFromTop = geometryProxy.frame(in: "container").origin.y
Text("This view is \(distanceFromTop) points from the top of the VStack")
}
.padding()
}
.coordinateSpace(.named("container"))You don't typically create types conforming to this protocol yourself.
Instead, use the system-provided .global, .local, and .named(_:)
implementations.
From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
See also
More in Drawing and shapes.
- AngleA geometric angle whose value you access in either radians or degrees.
- AngularGradientAn angular gradient.
- AnyGradientA color gradient.
- BlendModeModes for compositing a view with overlapping content.
- ButtonBorderShapeA shape used to draw a button's border.
- ColorMatrixA matrix to use in an RGBA color transformation.
- ConcentricRectangleAnimatableDataThe type defining the data to animate.
- ContainerRelativeShapeA shape that is replaced by an inset version of the current container shape. If no container shape was defined, is replaced by a rectangle.
- ContentShapeKindsA kind for the content shape of a view.
- DefaultGlassEffectShapeThe default shape applied by glass effects, a capsule.
- EllipticalGradientA radial gradient that draws an ellipse.
- GlobalCoordinateSpaceThe global coordinate space at the root of the view hierarchy.