summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs15
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs17
-rw-r--r--Xamarin.Forms.Platform.iOS/ViewRenderer.cs57
-rw-r--r--Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs55
4 files changed, 142 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
index 68d4702..3e99cd5 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
@@ -86,6 +86,21 @@ namespace Xamarin.Forms.Platform.iOS
UpdateImage();
}
+ protected override void SetAccessibilityLabel()
+ {
+ // If we have not specified an AccessibilityLabel and the AccessibiltyLabel is current bound to the Title,
+ // exit this method so we don't set the AccessibilityLabel value and break the binding.
+ // This may pose a problem for users who want to explicitly set the AccessibilityLabel to null, but this
+ // will prevent us from inadvertently breaking UI Tests that are using Query.Marked to get the dynamic Title
+ // of the Button.
+
+ var elemValue = (string)Element?.GetValue(Accessibility.NameProperty);
+ if (string.IsNullOrWhiteSpace(elemValue) && Control?.AccessibilityLabel == Control?.Title(UIControlState.Normal))
+ return;
+
+ base.SetAccessibilityLabel();
+ }
+
void OnButtonTouchUpInside(object sender, EventArgs eventArgs)
{
((IButtonController)Element)?.SendClicked();
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
index 5fde351..4cf3be9 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/LabelRenderer.cs
@@ -121,6 +121,23 @@ namespace Xamarin.Forms.Platform.MacOS
UpdateLineBreakMode();
}
+#if __MOBILE__
+ protected override void SetAccessibilityLabel()
+ {
+ // If we have not specified an AccessibilityLabel and the AccessibiltyLabel is current bound to the Text,
+ // exit this method so we don't set the AccessibilityLabel value and break the binding.
+ // This may pose a problem for users who want to explicitly set the AccessibilityLabel to null, but this
+ // will prevent us from inadvertently breaking UI Tests that are using Query.Marked to get the dynamic Text
+ // of the Label.
+
+ var elemValue = (string)Element?.GetValue(Accessibility.NameProperty);
+ if (string.IsNullOrWhiteSpace(elemValue) && Control?.AccessibilityLabel == Control?.Text)
+ return;
+
+ base.SetAccessibilityLabel();
+ }
+#endif
+
protected override void SetBackgroundColor(Color color)
{
#if __MOBILE__
diff --git a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
index 01f8e06..2cf9f75 100644
--- a/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/ViewRenderer.cs
@@ -25,6 +25,11 @@ namespace Xamarin.Forms.Platform.MacOS
public abstract class ViewRenderer<TView, TNativeView> : VisualElementRenderer<TView> where TView : View where TNativeView : NativeView
{
+#if __MOBILE__
+ string _defaultAccessibilityLabel;
+ string _defaultAccessibilityHint;
+ bool? _defaultIsAccessibilityElement;
+#endif
NativeColor _defaultColor;
public TNativeView Control { get; private set; }
@@ -110,7 +115,59 @@ namespace Xamarin.Forms.Platform.MacOS
base.OnRegisterEffect(effect);
effect.Control = Control;
}
+#if __MOBILE__
+ protected override void SetAccessibilityHint()
+ {
+ if (Control == null)
+ {
+ base.SetAccessibilityHint();
+ return;
+ }
+
+ if (Element == null)
+ return;
+
+ if (_defaultAccessibilityHint == null)
+ _defaultAccessibilityHint = Control.AccessibilityHint;
+
+ Control.AccessibilityHint = (string)Element.GetValue(Accessibility.HintProperty) ?? _defaultAccessibilityHint;
+
+ }
+
+ protected override void SetAccessibilityLabel()
+ {
+ if (Control == null)
+ {
+ base.SetAccessibilityLabel();
+ return;
+ }
+
+ if (Element == null)
+ return;
+
+ if (_defaultAccessibilityLabel == null)
+ _defaultAccessibilityLabel = Control.AccessibilityLabel;
+
+ Control.AccessibilityLabel = (string)Element.GetValue(Accessibility.NameProperty) ?? _defaultAccessibilityLabel;
+ }
+
+ protected override void SetIsAccessibilityElement()
+ {
+ if (Control == null)
+ {
+ base.SetIsAccessibilityElement();
+ return;
+ }
+ if (Element == null)
+ return;
+
+ if (!_defaultIsAccessibilityElement.HasValue)
+ _defaultIsAccessibilityElement = Control.IsAccessibilityElement;
+
+ Control.IsAccessibilityElement = (bool)((bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement);
+ }
+#endif
protected override void SetAutomationId(string id)
{
if (Control == null)
diff --git a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
index 0e7af2a..57c9ab1 100644
--- a/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/VisualElementRenderer.cs
@@ -36,6 +36,11 @@ namespace Xamarin.Forms.Platform.MacOS
readonly List<EventHandler<VisualElementChangedEventArgs>> _elementChangedHandlers = new List<EventHandler<VisualElementChangedEventArgs>>();
readonly PropertyChangedEventHandler _propertyChangedHandler;
+#if __MOBILE__
+ string _defaultAccessibilityLabel;
+ string _defaultAccessibilityHint;
+ bool? _defaultIsAccessibilityElement;
+#endif
EventTracker _events;
VisualElementRendererFlags _flags = VisualElementRendererFlags.AutoPackage | VisualElementRendererFlags.AutoTrack;
@@ -177,6 +182,7 @@ namespace Xamarin.Forms.Platform.MacOS
}
element.PropertyChanged += _propertyChangedHandler;
+
}
OnElementChanged(new ElementChangedEventArgs<TElement>(oldElement, element));
@@ -188,6 +194,11 @@ namespace Xamarin.Forms.Platform.MacOS
if (Element != null && !string.IsNullOrEmpty(Element.AutomationId))
SetAutomationId(Element.AutomationId);
+#if __MOBILE__
+ SetAccessibilityLabel();
+ SetAccessibilityHint();
+ SetIsAccessibilityElement();
+#endif
}
#if __MOBILE__
@@ -269,6 +280,12 @@ namespace Xamarin.Forms.Platform.MacOS
#if __MOBILE__
else if (e.PropertyName == PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty.PropertyName)
SetBlur((BlurEffectStyle)Element.GetValue(PlatformConfiguration.iOSSpecific.VisualElement.BlurEffectProperty));
+ else if (e.PropertyName == Accessibility.HintProperty.PropertyName)
+ SetAccessibilityHint();
+ else if (e.PropertyName == Accessibility.NameProperty.PropertyName)
+ SetAccessibilityLabel();
+ else if (e.PropertyName == Accessibility.IsInAccessibleTreeProperty.PropertyName)
+ SetIsAccessibilityElement();
#endif
}
@@ -277,6 +294,40 @@ namespace Xamarin.Forms.Platform.MacOS
effect.Container = this;
}
+#if __MOBILE__
+ protected virtual void SetAccessibilityHint()
+ {
+ if (Element == null)
+ return;
+
+ if (_defaultAccessibilityHint == null)
+ _defaultAccessibilityHint = AccessibilityHint;
+
+ AccessibilityHint = (string)Element.GetValue(Accessibility.HintProperty) ?? _defaultAccessibilityHint;
+ }
+
+ protected virtual void SetAccessibilityLabel()
+ {
+ if (Element == null)
+ return;
+
+ if (_defaultAccessibilityLabel == null)
+ _defaultAccessibilityLabel = AccessibilityLabel;
+
+ AccessibilityLabel = (string)Element.GetValue(Accessibility.NameProperty) ?? _defaultAccessibilityLabel;
+ }
+
+ protected virtual void SetIsAccessibilityElement()
+ {
+ if (Element == null)
+ return;
+
+ if (!_defaultIsAccessibilityElement.HasValue)
+ _defaultIsAccessibilityElement = IsAccessibilityElement;
+
+ IsAccessibilityElement = (bool)((bool?)Element.GetValue(Accessibility.IsInAccessibleTreeProperty) ?? _defaultIsAccessibilityElement);
+ }
+#endif
protected virtual void SetAutomationId(string id)
{
AccessibilityIdentifier = id;
@@ -286,11 +337,11 @@ namespace Xamarin.Forms.Platform.MacOS
{
if (color == Color.Default)
#if __MOBILE__
-
+
BackgroundColor = _defaultColor;
else
BackgroundColor = color.ToUIColor();
-
+
#else
Layer.BackgroundColor = _defaultColor.CGColor;
else