View ModifieriOS 27.1+macOS 27.1+tvOS 27.1+watchOS 27.1+visionOS 27.1+onHingeChange(isEnabled:_:) in SwiftUI
Declaration
compose().onHingeChange({
isEnabled?: boolean,
action: (oldContext: SwiftUI.DeviceHingeContext, newContext: SwiftUI.DeviceHingeContext) => void,
})nonisolated func onHingeChange(
isEnabled: Bool = true,
_ action: @escaping (DeviceHingeContext, DeviceHingeContext) -> Void
) -> some ViewParameters
options.isEnabledbooleanoptions.action*(oldContext: SwiftUI.DeviceHingeContext, newContext: SwiftUI.DeviceHingeContext) => void
Discussion
Use this modifier to be informed of changes to the hinge context of the device.
@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.
See also
More in Events and lifecycle.
- onAppearAdds an action to perform before this view appears.
- onChangeAdds a modifier for this view that fires an action when a specific value changes.
- onContinueUserActivityRegisters a handler to invoke in response to a user activity that your app receives.
- onContinuousHoverAdds an action to perform when the pointer enters, moves within, and exits the view's bounds.
- onDisappearAdds an action to perform after this view disappears.
- onDragActivates this view as the source of a drag and drop operation.
- onDragSessionUpdatedSpecifies an action to perform on each update of an ongoing dragging operation activated by draggable(:) or anther drag modifiers.
- onDropDefines the destination of a drag and drop operation that handles the dropped content with a closure that you specify.
- onDropSessionUpdatedSpecifies an action to perform on each update of an ongoing drop operation activated by dropDestination(:) or other drop modifiers.
- onGeometryChangeAdds an action to be performed when a value, created from a geometry proxy, changes.
- onHoverAdds an action to perform when the user moves the pointer over or away from the view's frame.
- onInteractiveResizeChangeAdds an action to perform when the enclosing window is being interactively resized.