AccessibilityEnvironmentAdditions.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // AccessibilityEnvironmentAdditions.swift
  3. // ark_ui_basic
  4. //
  5. // Audited for 6.5.4
  6. // Status: Complete
  7. // ID: E3F97FE8C846010147E7A62076265464 (SwiftUI)
  8. import ark_ui_basic_core
  9. // MARK: - EnabledTechnologiesKey
  10. private struct EnabledTechnologiesKey: EnvironmentKey {
  11. static var defaultValue: AccessibilityTechnologies { AccessibilityTechnologies() }
  12. }
  13. // MARK: - EnvironmentValues + Accessbility
  14. extension EnvironmentValues {
  15. @_spi(Private)
  16. @available(OpenSwiftUI_v3_0, *)
  17. public var accessibilityEnabledTechnologies: AccessibilityTechnologies {
  18. get { self[EnabledTechnologiesKey.self] }
  19. set { self[EnabledTechnologiesKey.self] = newValue }
  20. }
  21. fileprivate func isEnabled(for technology: AccessibilityTechnology) -> Bool {
  22. let member = AccessibilityTechnologies(list: [technology])
  23. return accessibilityEnabledTechnologies.contains(member)
  24. }
  25. fileprivate mutating func setIsEnabled(_ enabled: Bool, for technology: AccessibilityTechnology) {
  26. guard isEnabled(for: technology) != enabled else { return }
  27. let member = AccessibilityTechnologies(list: [technology])
  28. if enabled {
  29. accessibilityEnabledTechnologies.insert(member)
  30. } else {
  31. accessibilityEnabledTechnologies.remove(member)
  32. }
  33. }
  34. }
  35. @available(OpenSwiftUI_v3_0, *)
  36. extension EnvironmentValues {
  37. /// A Boolean value that indicates whether the VoiceOver screen reader is in use.
  38. ///
  39. /// The state changes as the user turns on or off the VoiceOver screen reader.
  40. public var accessibilityVoiceOverEnabled: Bool {
  41. isEnabled(for: .voiceOver)
  42. }
  43. /// A Boolean value that indicates whether the Switch Control motor accessibility feature is in use.
  44. ///
  45. /// The state changes as the user turns on or off the Switch Control feature.
  46. public var accessibilitySwitchControlEnabled: Bool {
  47. isEnabled(for: .switchControl)
  48. }
  49. }
  50. @_spi(Private)
  51. @available(OpenSwiftUI_v4_0, *)
  52. extension EnvironmentValues {
  53. public var accessibilityFullKeyboardAccessEnabled: Bool {
  54. isEnabled(for: .fullKeyboardAccess)
  55. }
  56. public var accessibilityVoiceControlEnabled: Bool {
  57. isEnabled(for: .voiceControl)
  58. }
  59. }
  60. @_spi(Private)
  61. @available(OpenSwiftUI_v5_0, *)
  62. extension EnvironmentValues {
  63. public var accessibilityHoverTextEnabled: Bool {
  64. isEnabled(for: .hoverText)
  65. }
  66. }
  67. @available(OpenSwiftUI_v6_0, *)
  68. extension EnvironmentValues {
  69. /// A Boolean value that indicates whether Assistive Access is in use.
  70. public var accessibilityAssistiveAccessEnabled: Bool {
  71. isEnabled(for: .assistiveAccess)
  72. }
  73. }