From f80a5e05de0d1a6d8f1c1d81bced85cb468e7813 Mon Sep 17 00:00:00 2001 From: Samantha Houts Date: Thu, 22 Jun 2017 11:19:26 -0700 Subject: [Android] Remove the ". " on empty labels (Accessibility) on Fastrenderers (#915) * [Android] Concatenate Name/HelpText better Also remove some parameters that were added to workaround an issue that no longer exists. * Add repro * Listen to Stephane he's usually right * oops, didn't save --- .../FastRenderers/AutomationPropertiesProvider.cs | 44 +++++++++++----------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs') diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs b/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs index 6d34c6b5..6cd158ff 100644 --- a/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs +++ b/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs @@ -6,7 +6,6 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers { internal class AutomationPropertiesProvider : IDisposable { - const string GetFromElement = "GetValueFromElement"; string _defaultContentDescription; bool? _defaultFocusable; string _defaultHint; @@ -49,18 +48,14 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers } } - void SetAutomationId(string id = GetFromElement) + void SetAutomationId() { if (Element == null || Control == null) { return; } - string value = id; - if (value == GetFromElement) - { - value = Element.AutomationId; - } + string value = Element.AutomationId; if (!string.IsNullOrEmpty(value)) { @@ -68,7 +63,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers } } - void SetContentDescription(string contentDescription = GetFromElement) + void SetContentDescription() { if (Element == null || Control == null) { @@ -85,12 +80,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers _defaultContentDescription = Control.ContentDescription; } - string value = contentDescription; - if (value == GetFromElement) - { - value = string.Join(" ", (string)Element.GetValue(AutomationProperties.NameProperty), - (string)Element.GetValue(AutomationProperties.HelpTextProperty)); - } + string value = ConcatenateNameAndHelpText(Element); if (!string.IsNullOrWhiteSpace(value)) { @@ -102,7 +92,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers } } - void SetFocusable(bool? value = null) + void SetFocusable() { if (Element == null || Control == null) { @@ -115,10 +105,10 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers } Control.Focusable = - (bool)(value ?? (bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultFocusable); + (bool)((bool?)Element.GetValue(AutomationProperties.IsInAccessibleTreeProperty) ?? _defaultFocusable); } - bool SetHint(string hint = GetFromElement) + bool SetHint() { if (Element == null || Control == null) { @@ -142,18 +132,26 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers _defaultHint = textView.Hint; } - string value = hint; - if (value == GetFromElement) - { - value = string.Join(". ", (string)Element.GetValue(AutomationProperties.NameProperty), - (string)Element.GetValue(AutomationProperties.HelpTextProperty)); - } + string value = ConcatenateNameAndHelpText(Element); textView.Hint = !string.IsNullOrWhiteSpace(value) ? value : _defaultHint; return true; } + internal static string ConcatenateNameAndHelpText(Element Element) + { + var name = (string)Element.GetValue(AutomationProperties.NameProperty); + var helpText = (string)Element.GetValue(AutomationProperties.HelpTextProperty); + + if (string.IsNullOrWhiteSpace(name)) + return helpText; + if (string.IsNullOrWhiteSpace(helpText)) + return name; + + return $"{name}. {helpText}"; + } + void SetLabeledBy() { if (Element == null || Control == null) -- cgit v1.2.3