Skip to content

Instantly share code, notes, and snippets.

@robinkanatzar
Last active August 4, 2024 14:02
Show Gist options
  • Save robinkanatzar/bca6930ceec76062f8503f8c38a3c944 to your computer and use it in GitHub Desktop.
Save robinkanatzar/bca6930ceec76062f8503f8c38a3c944 to your computer and use it in GitHub Desktop.
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 {
Text("User does NOT want things head anchored.")
} else {
Text("User is ok with things that are head anchored. Provide an alternative.")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment