visionOS Accessibility

Heads up... You're reading this book for free, with parts of this chapter shown beyond this point as scrambled text.

AccessibilityComponent

Similar to using the SwiftUI Accessibility API for SwiftUI elements, RealityKit’s AccessibilityComponent lets you customize a RealityKit entity’s label, value, and traits. In addition, you can customize an entity’s actions and content. You initialize a default AccessibilityComponent, set values for its properties, then assign it to the entity’s components set as the AccessibilityComponent.self element:

var accessibilityComponent = AccessibilityComponent()
accessibilityComponent.label = "Plane"
accessibilityComponent.value = "Flying"
accessibilityComponent.isAccessibilityElement = true
accessibilityComponent.traits = [.button, .playsSound]
accessibilityComponent.systemActions = [.activate]
scene.components[AccessibilityComponent.self] = accessibilityComponent

AccessibilityNotification Announcements

The four types of AccessibilityNotification are available on all platforms:

AccessibilityNotification.Announcement("Plane stopped flying").post()
See forum comments
Download course materials from Github
Previous: Demo: Dynamic Type & Contrast Ratio Next: Demo: Accessibility Traits & Announcements