DeviceHinge

A type encapsulating the state of a single hinge.

StructureiOS 27.1+macOS 27.1+tvOS 27.1+watchOS 27.1+visionOS 27.1+DeviceHinge in SwiftUI

Declaration

React
type DeviceHinge = { readonly angle: Angle; readonly hashValue: number; readonly status: DeviceHingeStatus; };
Swift
struct DeviceHinge

Properties

Overview

A hinge provides its angle along with a status determined by the system based on the current angle and device orientation. You use this type with the View.onHingeChange(_:) modifier.

@State private var hinge: DeviceHinge? = nil

var body: some View {
    VStack {
        if let hinge {
            AngleDisplayView(angle: hinge.angle)
            StatusDisplayView(status: hinge.status)
        } else {
            ContentUnavailableView(
                "Hinge Unavailable",
                systemImage: "rectangle.split.2x1")
        }
    }
    .onHingeChange { _, newContext in
        hinge = newContext.hinge
    }
}

In the example above, the current angle and status of the hinge will be displayed in the app as you interact with the hinge.

From Apple’s SwiftUI documentation. Code samples there are Swift.

See also

More in Other values.