Repository navigation
Don't set UseInterpreter for iOS or Mac Catalyst. #39032
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
165 changes: 128 additions & 37 deletions
165
src/Controls/src/Core/Platform/iOS/Extensions/AcessibilityExtensions.cs
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 |
|---|---|---|
| @@ -1,43 +1,134 @@ | ||
| using System.Runtime.CompilerServices; | ||
| using UIKit; | ||
|
|
||
| namespace Microsoft.Maui.Controls.Platform; | ||
|
|
||
| internal static class AcessibilityExtensions | ||
| internal static class AccessibilityExtensions | ||
| { | ||
| internal static void UpdateAccessibilityTraits(this UICollectionView collectionView, SelectableItemsView itemsView) | ||
| { | ||
| foreach (var subview in collectionView.Subviews) | ||
| { | ||
| if (subview is UICollectionViewCell cell) | ||
| { | ||
| cell.UpdateAccessibilityTraits(itemsView); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal static void UpdateAccessibilityTraits(this UICollectionViewCell cell, ItemsView itemsView) | ||
| { | ||
| var selectionMode = (itemsView as CollectionView)?.SelectionMode; | ||
| if (cell.ContentView is not null | ||
| && cell.ContentView.Subviews.Length > 0 | ||
| && selectionMode is not null) | ||
| { | ||
| var firstChild = cell.ContentView.Subviews[0]; | ||
|
|
||
| // if the first child is a control, changing the accessibility traits from an entry to a button could be confusing. | ||
| if (firstChild is UIControl) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (selectionMode != SelectionMode.None) | ||
| { | ||
| firstChild.AccessibilityTraits |= UIAccessibilityTrait.Button; | ||
| } | ||
| else | ||
| { | ||
| firstChild.AccessibilityTraits &= ~UIAccessibilityTrait.Button; | ||
| } | ||
| } | ||
| } | ||
| static readonly ConditionalWeakTable<UICollectionViewCell, AccessibilityTraitState> AccessibilityTraitStates = new(); | ||
|
|
||
| internal static void UpdateAccessibilityTraits(this UICollectionView collectionView, SelectableItemsView itemsView) | ||
| { | ||
| foreach (var subview in collectionView.Subviews) | ||
| { | ||
| if (subview is UICollectionViewCell cell) | ||
| { | ||
| cell.UpdateAccessibilityTraits(itemsView); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal static void UpdateAccessibilityTraits(this UICollectionViewCell cell, ItemsView itemsView, bool invalidateAccessibilityTarget = false) | ||
| { | ||
| var selectionMode = (itemsView as CollectionView)?.SelectionMode; | ||
| var traitState = AccessibilityTraitStates.GetValue(cell, static _ => new AccessibilityTraitState()); | ||
|
|
||
| if (selectionMode is null || cell.ContentView is null || cell.ContentView.Subviews.Length == 0) | ||
| { | ||
| ResetAccessibilityTraitState(traitState); | ||
| return; | ||
| } | ||
|
|
||
| var accessibilityRoot = cell.ContentView.Subviews[0]; | ||
| if (!ReferenceEquals(traitState.AccessibilityRoot, accessibilityRoot)) | ||
| { | ||
| ResetAccessibilityTraitState(traitState); | ||
| traitState.AccessibilityRoot = accessibilityRoot; | ||
| } | ||
|
|
||
| if (selectionMode == SelectionMode.None) | ||
| { | ||
| ClearButtonTrait(traitState); | ||
| return; | ||
| } | ||
|
|
||
| if (!traitState.HasResolvedAccessibilityTarget) | ||
| { | ||
| traitState.AccessibilityTarget = FindAccessibilityElement(accessibilityRoot); | ||
| traitState.HasResolvedAccessibilityTarget = true; | ||
| } | ||
|
|
||
| var accessibilityTarget = traitState.AccessibilityTarget; | ||
|
|
||
| // The exposed accessibility element can change when semantic properties are updated. | ||
| // Always remove the trait from the view where we added it before targeting another view. | ||
| if (!ReferenceEquals(traitState.Target, accessibilityTarget)) | ||
| { | ||
| ClearButtonTrait(traitState); | ||
| } | ||
|
|
||
| if (accessibilityTarget is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| // Only track traits added here so developer-assigned Button traits are preserved. | ||
| if ((accessibilityTarget.AccessibilityTraits & UIAccessibilityTrait.Button) == 0) | ||
| { | ||
| accessibilityTarget.AccessibilityTraits |= UIAccessibilityTrait.Button; | ||
| traitState.Target = accessibilityTarget; | ||
| traitState.AddedButtonTrait = true; | ||
| } | ||
| } | ||
|
|
||
| static void ClearButtonTrait(AccessibilityTraitState traitState) | ||
| { | ||
| if (traitState.AddedButtonTrait && traitState.Target is not null) | ||
| { | ||
| traitState.Target.AccessibilityTraits &= ~UIAccessibilityTrait.Button; | ||
| } | ||
|
|
||
| traitState.Target = null; | ||
| traitState.AddedButtonTrait = false; | ||
| } | ||
|
|
||
| static void ResetAccessibilityTraitState(AccessibilityTraitState traitState) | ||
| { | ||
| ClearButtonTrait(traitState); | ||
| traitState.AccessibilityRoot = null; | ||
| traitState.AccessibilityTarget = null; | ||
| traitState.HasResolvedAccessibilityTarget = false; | ||
| } | ||
|
|
||
| static UIView? FindAccessibilityElement(UIView view) | ||
| { | ||
| // Do not change the role of native controls such as | ||
| // UIButton, UITextField, UISwitch, etc. | ||
| if (view is UIControl) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| // This is the native view that MAUI has exposed to | ||
| // VoiceOver as the accessibility element. | ||
| if (view.IsAccessibilityElement) | ||
| { | ||
| return view; | ||
| } | ||
|
|
||
| foreach (var subview in view.Subviews) | ||
| { | ||
| var accessibilityElement = FindAccessibilityElement(subview); | ||
|
|
||
| if (accessibilityElement is not null) | ||
| { | ||
| return accessibilityElement; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| sealed class AccessibilityTraitState | ||
| { | ||
| public UIView? AccessibilityRoot { get; set; } | ||
|
|
||
| public UIView? AccessibilityTarget { get; set; } | ||
|
|
||
| public bool HasResolvedAccessibilityTarget { get; set; } | ||
|
|
||
| public UIView? Target { get; set; } | ||
|
|
||
| public bool AddedButtonTrait { get; set; } | ||
| } | ||
| } |
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
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.