Skip to content

Instantly share code, notes, and snippets.

View robinkanatzar's full-sized avatar

Robin Kanatzar robinkanatzar

View GitHub Profile
@robinkanatzar
robinkanatzar / RealityKitAnnotationsExample.swift
Created August 9, 2024 10:49
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
@robinkanatzar
robinkanatzar / ReducedMotionView.swift
Created August 4, 2024 14:02
Accessibility + visionOS: Observe reduced motion system setting
import SwiftUI
/// An example view that listens to the user's system settings
/// about preferring motion
struct ReducedMotionView: View {
@Environment(\.accessibilityReduceMotion)
private var accessibilityReduceMotion
var body: some View {
if accessibilityReduceMotion {
@robinkanatzar
robinkanatzar / HeadAnchoredView.swift
Last active August 4, 2024 14:02
Accessibility + visionOS: Observe head anchor system setting
import SwiftUI
/// An example view that listens to the user's system settings
/// about preferring head-anchored views
struct HeadAnchoredView: View {
@Environment(\.accessibilityPrefersHeadAnchorAlternative)
private var accessibilityPrefersHeadAnchorAlternative
var body: some View {
if accessibilityPrefersHeadAnchorAlternative {
@robinkanatzar
robinkanatzar / AStack.swift
Last active August 4, 2024 07:37
AStack: An accessible stack view that switches from an HStack to a VStack when the dynamic type size is an accessibility size
import SwiftUI
/// An accessible stack view that starts as an HStack
/// then becomes a VStack once the dynamic type size
/// is an accessibility size.
///
/// Usage in a View:
/// ```
/// var body: some View {
/// AStack(hStackAlignment: .top, hStackSpacing: 100, vStackAlignment: .leading, vStackSpacing: 5) {