Skip to content

Instantly share code, notes, and snippets.

@robinkanatzar
Created August 9, 2024 10:49
Show Gist options
  • Save robinkanatzar/99b484fe7e6b6a92915c8f9925b616b4 to your computer and use it in GitHub Desktop.
Save robinkanatzar/99b484fe7e6b6a92915c8f9925b616b4 to your computer and use it in GitHub Desktop.
Accessibility + visionOS: RealityKit Accessibility Annotations
import RealityKit
// 1 - Create RealityKit Entity
let modelEntity = ModelEntity(/* ... */)
// 2 - Create AccessibilityComponent
var accessibilityComponent = AccessibilityComponent()
// 3 - Expose to assistive technology
accessibilityComponent.isAccessibilityElement = true
// 4 - Add basic annotations (label, value, traits)
accessibilityComponent.label = "Label"
accessibilityComponent.value = "Value"
accessibilityComponent.traits = [.button]
// 5 - Add custom actions and rotors
accessibilityComponent.customActions = [/* ... */]
accessibilityComponent.customRotors = [/* ... */]
// 6 - Assign AccessibilityComponent to RealityKit Entity
modelEntity.components?[AccessibilityComponent.self] = accessibilityComponent
// 7 - Update the AccessibilityComponent as the app state changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment