CoordinateSpaceProtocol

A frame of reference within the layout system.

ProtocoliOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+CoordinateSpaceProtocol in SwiftUI

Declaration

React
type CoordinateSpaceProtocol =
  | 'global'
  | 'local'
  | 'scrollView'
  | { named: string | number | boolean; }
  | { scrollView: { axis: Axis; }; }
  | GlobalCoordinateSpace
  | LocalCoordinateSpace
  | NamedCoordinateSpace;
Swift
protocol CoordinateSpaceProtocol

Pass a literal, or build one with SwiftUI.CoordinateSpaceProtocol from import { SwiftUI } from 'swiftui-react-native'.

Type properties

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.