Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 193fedc

Browse files
authored
Don't set IsAccessibilityElement for everything (#13423)
* Don't set IsAccessibilityElement for everything * - don't set IsInAccessibleTreeProperty
1 parent c419953 commit 193fedc

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Xamarin.Forms.Platform.iOS/Extensions/AccessibilityExtensions.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,24 @@ public static string SetAccessibilityLabel(this UIBarItem Control, Element Eleme
8888
if (Element == null || Control == null)
8989
return _defaultIsAccessibilityElement;
9090

91+
// If the user hasn't set IsInAccessibleTree then just don't do anything
92+
if (!Element.IsSet(AutomationProperties.IsInAccessibleTreeProperty))
93+
return null;
94+
9195
#if __MOBILE__
9296
if (!_defaultIsAccessibilityElement.HasValue)
93-
_defaultIsAccessibilityElement = Control.IsAccessibilityElement;
97+
{
98+
// iOS sets the default value for IsAccessibilityElement late in the layout cycle
99+
// But if we set it to false ourselves then that causes it to act like it's false
100+
101+
// from the docs:
102+
// https://developer.apple.com/documentation/objectivec/nsobject/1615141-isaccessibilityelement
103+
// The default value for this property is false unless the receiver is a standard UIKit control,
104+
// in which case the value is true.
105+
//
106+
// So we just base the default on that logic
107+
_defaultIsAccessibilityElement = Control.IsAccessibilityElement || Control is UIControl;
108+
}
94109

95110
Control.IsAccessibilityElement = (bool)((bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement);
96111
#else

Xamarin.Forms.Platform.iOS/ViewRenderer.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ protected void SetNativeControl(TNativeView uiview)
223223
_controlChanging?.Invoke(this, EventArgs.Empty);
224224
#if __MOBILE__
225225
_defaultColor = uiview.BackgroundColor;
226-
227-
// UIKit UIViews created via storyboard default IsAccessibilityElement to true, BUT
228-
// UIViews created programmatically default IsAccessibilityElement to false.
229-
// We need to default to true to allow all elements to be accessible by default and
230-
// allow users to override this later via AutomationProperties.IsInAccessibleTree
231-
uiview.IsAccessibilityElement = true;
232226
#else
233227
uiview.WantsLayer = true;
234228
_defaultColor = uiview.Layer.BackgroundColor;

0 commit comments

Comments
 (0)