-
Notifications
You must be signed in to change notification settings - Fork 61
Add AccessibilityCore.UserSettings support #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+908
−6
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
78ada37
Add AccessibilityCoreUserSettings
Kyle-Ye 3f159b7
Add AccessibilityTechnologies
Kyle-Ye 6f0adff
Add AccessibilityEnvironmentAdditions
Kyle-Ye b586521
Add AccessibilityLargeContentView
Kyle-Ye f7e7ec1
Add AccessibilityQuickAction
Kyle-Ye ee33c8b
Update AccessibilityCoreUserSettings
Kyle-Ye 9e153a3
Fix iOS linkage issue for Accessbility
Kyle-Ye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
Sources/OpenSwiftUI/Accessibility/AccessibilityCoreUserSettings.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // | ||
| // AccessibilityCoreUserSettings.swift | ||
| // OpenSwiftUI | ||
| // | ||
| // Audited for 6.5.4 | ||
| // Status: Complete | ||
|
|
||
| #if canImport(UIKit) | ||
| import Accessibility | ||
| package import OpenSwiftUICore | ||
| import UIKit | ||
|
|
||
| extension AccessibilityCore { | ||
| package enum UserSettings { | ||
| package static func resolve(into environment: inout EnvironmentValues) { | ||
| environment.accessibilityDifferentiateWithoutColor = UIAccessibility.shouldDifferentiateWithoutColor | ||
| environment.accessibilityReduceTransparency = UIAccessibility.isReduceTransparencyEnabled | ||
| environment.accessibilityReduceMotion = UIAccessibility.isReduceMotionEnabled | ||
| environment.accessibilityInvertColors = UIAccessibility.isInvertColorsEnabled | ||
| environment.accessibilityPrefersCrossFadeTransitions = UIAccessibility.prefersCrossFadeTransitions | ||
| environment.accessibilityShowButtonShapes = UIAccessibility.buttonShapesEnabled | ||
| environment.accessibilityDimFlashingLights = _AXSPhotosensitiveMitigationEnabled() | ||
| environment.accessibilityPlayAnimatedImages = AccessibilitySettings.animatedImagesEnabled | ||
| environment.accessibilityEnabledTechnologies = .enabledTechnologies | ||
| environment._accessibilityLargeContentViewerEnabled = UILargeContentViewerInteraction.isEnabled | ||
| environment._accessibilityQuickActionsEnabled = false | ||
| environment.accessibilityPrefersOnOffLabels = _AXSIncreaseButtonLegibility() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // MARK: - AccessibilityTechnologies + enabledTechnologies | ||
|
|
||
| extension AccessibilityTechnologies { | ||
| package static var enabledTechnologies: AccessibilityTechnologies { | ||
| let enabled = AccessibilityTechnology.allCases.filter { technology in | ||
| switch technology { | ||
| case .voiceOver: UIAccessibility.isVoiceOverRunning | ||
| case .switchControl: UIAccessibility.isSwitchControlRunning | ||
| case .fullKeyboardAccess: _AXSFullKeyboardAccessEnabled() | ||
| case .voiceControl: _AXSCommandAndControlEnabled() | ||
| case .hoverText: _AXSHoverTextEnabled() | ||
| case .assistiveAccess: AXAssistiveAccessEnabled() | ||
| } | ||
| } | ||
| return AccessibilityTechnologies(list: enabled) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Private C functions | ||
|
|
||
| @_silgen_name("_AXSPhotosensitiveMitigationEnabled") | ||
| private func _AXSPhotosensitiveMitigationEnabled() -> Bool | ||
|
|
||
| @_silgen_name("_AXSIncreaseButtonLegibility") | ||
| private func _AXSIncreaseButtonLegibility() -> Bool | ||
|
|
||
| @_silgen_name("_AXSFullKeyboardAccessEnabled") | ||
| private func _AXSFullKeyboardAccessEnabled() -> Bool | ||
|
|
||
| @_silgen_name("_AXSCommandAndControlEnabled") | ||
| private func _AXSCommandAndControlEnabled() -> Bool | ||
|
|
||
| @_silgen_name("_AXSHoverTextEnabled") | ||
| private func _AXSHoverTextEnabled() -> Bool | ||
|
|
||
| @_silgen_name("AXAssistiveAccessEnabled") | ||
| private func AXAssistiveAccessEnabled() -> Bool | ||
|
|
||
| #endif | ||
88 changes: 88 additions & 0 deletions
88
Sources/OpenSwiftUI/Accessibility/AccessibilityEnvironmentAdditions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // | ||
| // AccessibilityEnvironmentAdditions.swift | ||
| // OpenSwiftUI | ||
| // | ||
| // Audited for 6.5.4 | ||
| // Status: Complete | ||
| // ID: E3F97FE8C846010147E7A62076265464 (SwiftUI) | ||
|
|
||
| import OpenSwiftUICore | ||
|
|
||
| // MARK: - EnabledTechnologiesKey | ||
|
|
||
| private struct EnabledTechnologiesKey: EnvironmentKey { | ||
| static var defaultValue: AccessibilityTechnologies { AccessibilityTechnologies() } | ||
| } | ||
|
|
||
| // MARK: - EnvironmentValues + Accessbility | ||
|
|
||
| extension EnvironmentValues { | ||
| @_spi(Private) | ||
| @available(OpenSwiftUI_v3_0, *) | ||
| public var accessibilityEnabledTechnologies: AccessibilityTechnologies { | ||
| get { self[EnabledTechnologiesKey.self] } | ||
| set { self[EnabledTechnologiesKey.self] = newValue } | ||
| } | ||
|
|
||
| fileprivate func isEnabled(for technology: AccessibilityTechnology) -> Bool { | ||
| let member = AccessibilityTechnologies(list: [technology]) | ||
| return accessibilityEnabledTechnologies.contains(member) | ||
| } | ||
|
|
||
| fileprivate mutating func setIsEnabled(_ enabled: Bool, for technology: AccessibilityTechnology) { | ||
| guard isEnabled(for: technology) != enabled else { return } | ||
| let member = AccessibilityTechnologies(list: [technology]) | ||
| if enabled { | ||
| accessibilityEnabledTechnologies.insert(member) | ||
| } else { | ||
| accessibilityEnabledTechnologies.remove(member) | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @available(OpenSwiftUI_v3_0, *) | ||
| extension EnvironmentValues { | ||
|
|
||
| /// A Boolean value that indicates whether the VoiceOver screen reader is in use. | ||
| /// | ||
| /// The state changes as the user turns on or off the VoiceOver screen reader. | ||
| public var accessibilityVoiceOverEnabled: Bool { | ||
| isEnabled(for: .voiceOver) | ||
| } | ||
|
|
||
| /// A Boolean value that indicates whether the Switch Control motor accessibility feature is in use. | ||
| /// | ||
| /// The state changes as the user turns on or off the Switch Control feature. | ||
| public var accessibilitySwitchControlEnabled: Bool { | ||
| isEnabled(for: .switchControl) | ||
| } | ||
| } | ||
|
|
||
| @_spi(Private) | ||
| @available(OpenSwiftUI_v4_0, *) | ||
| extension EnvironmentValues { | ||
| public var accessibilityFullKeyboardAccessEnabled: Bool { | ||
| isEnabled(for: .fullKeyboardAccess) | ||
| } | ||
|
|
||
| public var accessibilityVoiceControlEnabled: Bool { | ||
| isEnabled(for: .voiceControl) | ||
| } | ||
| } | ||
|
|
||
| @_spi(Private) | ||
| @available(OpenSwiftUI_v5_0, *) | ||
| extension EnvironmentValues { | ||
| public var accessibilityHoverTextEnabled: Bool { | ||
| isEnabled(for: .hoverText) | ||
| } | ||
| } | ||
|
|
||
| @available(OpenSwiftUI_v6_0, *) | ||
| extension EnvironmentValues { | ||
| /// A Boolean value that indicates whether Assistive Access is in use. | ||
| public var accessibilityAssistiveAccessEnabled: Bool { | ||
| isEnabled(for: .assistiveAccess) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.