summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs30
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/AndroidHelpText.cs50
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems1
-rw-r--r--Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs44
-rw-r--r--Xamarin.Forms.Platform.Android/VisualElementRenderer.cs4
5 files changed, 96 insertions, 33 deletions
diff --git a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
index 4f1813fc..8db3fac0 100644
--- a/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
+++ b/Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
@@ -30,6 +30,7 @@ using Xamarin.Forms.Controls.Issues;
[assembly: ExportRenderer(typeof(Bugzilla42000._42000NumericEntryNoDecimal), typeof(EntryRendererNoDecimal))]
[assembly: ExportRenderer(typeof(Bugzilla42000._42000NumericEntryNoNegative), typeof(EntryRendererNoNegative))]
+[assembly: ExportRenderer(typeof(AndroidHelpText.HintLabel), typeof(HintLabel))]
[assembly: ExportRenderer(typeof(Xamarin.Forms.Controls.Issues.NoFlashTestNavigationPage), typeof(Xamarin.Forms.ControlGallery.Android.NoFlashTestNavigationPage))]
@@ -236,9 +237,10 @@ namespace Xamarin.Forms.ControlGallery.Android
{// no view to re-use, create new
view = (context as Activity).LayoutInflater.Inflate(Resource.Layout.NativeAndroidCell, null);
}
- else { // re-use, clear image
- // doesn't seem to help
- //view.FindViewById<ImageView> (Resource.Id.Image).Drawable.Dispose ();
+ else
+ { // re-use, clear image
+ // doesn't seem to help
+ //view.FindViewById<ImageView> (Resource.Id.Image).Drawable.Dispose ();
}
view.FindViewById<TextView>(Resource.Id.Text1).Text = x.Name;
@@ -275,7 +277,8 @@ namespace Xamarin.Forms.ControlGallery.Android
}, TaskScheduler.FromCurrentSynchronizationContext());
}
- else {
+ else
+ {
// clear the image
view.FindViewById<ImageView>(Resource.Id.Image).SetImageBitmap(null);
}
@@ -390,9 +393,10 @@ namespace Xamarin.Forms.ControlGallery.Android
{// no view to re-use, create new
view = _context.LayoutInflater.Inflate(Resource.Layout.NativeAndroidListViewCell, null);
}
- else { // re-use, clear image
- // doesn't seem to help
- //view.FindViewById<ImageView> (Resource.Id.Image).Drawable.Dispose ();
+ else
+ { // re-use, clear image
+ // doesn't seem to help
+ //view.FindViewById<ImageView> (Resource.Id.Image).Drawable.Dispose ();
}
view.FindViewById<TextView>(Resource.Id.Text1).Text = item.Name;
view.FindViewById<TextView>(Resource.Id.Text2).Text = item.Category;
@@ -427,7 +431,8 @@ namespace Xamarin.Forms.ControlGallery.Android
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}
- else {
+ else
+ {
// clear the image
view.FindViewById<ImageView>(Resource.Id.Image).SetImageBitmap(null);
}
@@ -518,6 +523,15 @@ namespace Xamarin.Forms.ControlGallery.Android
}
}
+
+ public class HintLabel : Xamarin.Forms.Platform.Android.FastRenderers.LabelRenderer
+ {
+ public HintLabel()
+ {
+ Hint = AndroidHelpText.HintLabel.Success;
+ }
+ }
+
public class NoFlashTestNavigationPage : Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer
{
protected override void SetupPageTransition(global::Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/AndroidHelpText.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/AndroidHelpText.cs
new file mode 100644
index 00000000..014e50f6
--- /dev/null
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/AndroidHelpText.cs
@@ -0,0 +1,50 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST && __ANDROID__
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+// Apply the default category of "Issues" to all of the tests in this assembly
+// We use this as a catch-all for tests which haven't been individually categorized
+#if UITEST && __ANDROID__
+[assembly: NUnit.Framework.Category("Issues")]
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.None, 0, "Android shows . in empty labels because of a11y Name/HelpText", PlatformAffected.Android)]
+ public class AndroidHelpText : TestContentPage
+ {
+ [Preserve(AllMembers = true)]
+ public class HintLabel : Label
+ {
+ public const string Success = "SUCCESS";
+ }
+
+ protected override void Init()
+ {
+ var label = new Label
+ {
+ Text = $"There should be an empty label below this one. If the label shows a period (.), this test has failed. There should also be a label that says \"{HintLabel.Success}\"."
+ };
+
+ var emptyLabel = new Label { HorizontalTextAlignment = TextAlignment.Center };
+
+ var customLabel = new HintLabel { HorizontalTextAlignment = TextAlignment.Center }; ;
+
+ Content = new StackLayout { Children = { label, emptyLabel, customLabel } };
+ }
+
+#if UITEST && __ANDROID__
+ [Test]
+ public void AndroidHelpTextTest()
+ {
+ RunningApp.WaitForNoElement(q => q.Marked("."));
+ RunningApp.WaitForElement(q => q.Marked(HintLabel.Success));
+ }
+#endif
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
index 07480f11..d77ed10d 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
@@ -296,6 +296,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla53909.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ListViewNRE.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla55745.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)AndroidHelpText.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla32830.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla55365.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla39802.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)
diff --git a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
index 3c05fae4..120cc972 100644
--- a/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/VisualElementRenderer.cs
@@ -370,7 +370,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;
@@ -405,7 +405,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;