diff options
author | Samantha Houts <samhouts@users.noreply.github.com> | 2017-06-22 11:19:26 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-06-22 19:26:53 +0100 |
commit | 595344f31aa108275bfbef9abc6a3ae68b79c52b (patch) | |
tree | 7af41ca3cb1a6d0ac110bc6e8a2fd7426fb6e1d6 /Xamarin.Forms.Platform.Android | |
parent | 8b014183fe21da9d9e221cc49d6c1750e52098aa (diff) | |
download | xamarin-forms-595344f31aa108275bfbef9abc6a3ae68b79c52b.tar.gz xamarin-forms-595344f31aa108275bfbef9abc6a3ae68b79c52b.tar.bz2 xamarin-forms-595344f31aa108275bfbef9abc6a3ae68b79c52b.zip |
[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
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r-- | Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs | 44 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Android/VisualElementRenderer.cs | 4 |
2 files changed, 23 insertions, 25 deletions
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) diff --git a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs index 747956c3..8f815a94 100644 --- a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs +++ b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs @@ -366,7 +366,7 @@ namespace Xamarin.Forms.Platform.Android if (_defaultContentDescription == null) _defaultContentDescription = ContentDescription; - var elemValue = string.Join(" ", (string)Element.GetValue(AutomationProperties.NameProperty), (string)Element.GetValue(AutomationProperties.HelpTextProperty)); + var elemValue = FastRenderers.AutomationPropertiesProvider.ConcatenateNameAndHelpText(Element); if (!string.IsNullOrWhiteSpace(elemValue)) ContentDescription = elemValue; @@ -401,7 +401,7 @@ namespace Xamarin.Forms.Platform.Android if (_defaultHint == null) _defaultHint = textView.Hint; - var elemValue = string.Join((String.IsNullOrWhiteSpace((string)(Element.GetValue(AutomationProperties.NameProperty))) || String.IsNullOrWhiteSpace((string)(Element.GetValue(AutomationProperties.HelpTextProperty)))) ? "" : ". ", (string)Element.GetValue(AutomationProperties.NameProperty), (string)Element.GetValue(AutomationProperties.HelpTextProperty)); + var elemValue = FastRenderers.AutomationPropertiesProvider.ConcatenateNameAndHelpText(Element); if (!string.IsNullOrWhiteSpace(elemValue)) textView.Hint = elemValue; |