From 24bb5bb1ec082a32258e0e70269e7e0ac20d5034 Mon Sep 17 00:00:00 2001 From: Alexandre Santos Costa Date: Tue, 17 Dec 2019 14:50:40 -0300 Subject: [PATCH] #7875: Android: Button size changes when setting Accessibility properties (#8368) * Tryed to reproduce the same correction applied to the default implementation * Added repro sample * Fixed build error on iOS --- .../Issue7875.cs | 65 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../AutomationPropertiesProvider.cs | 2 +- .../FastRenderers/ButtonRenderer.cs | 20 +++++- 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7875.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7875.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7875.cs new file mode 100644 index 000000000..88437c1a9 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue7875.cs @@ -0,0 +1,65 @@ +using Xamarin.Forms.Internals; +using Xamarin.Forms.CustomAttributes; + +#if UITEST +using Xamarin.Forms.Core.UITests; +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ +#if UITEST + [Category(UITestCategories.Button)] +#endif + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 7875, "Button size changes when setting Accessibility properties", PlatformAffected.Android)] + public class Issue7875 : TestContentPage + { + public Issue7875() + { + Title = "Issue 7875"; + + var layout = new Grid(); + + layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + + var instructions = new Label + { + BackgroundColor = Color.Black, + TextColor = Color.White, + Text = "If the buttons below have the same size, the test has passed." + }; + layout.Children.Add(instructions, 0, 0); + + var button = new Button + { + BackgroundColor = Color.Gray, + HorizontalOptions = LayoutOptions.Center, + ImageSource = "calculator.png", + Text = "Text" + }; + layout.Children.Add(button, 0, 1); + + var accesibilityButton = new Button + { + BackgroundColor = Color.Gray, + HorizontalOptions = LayoutOptions.Center, + ImageSource = "calculator.png", + Text = "Text" + }; + accesibilityButton.SetValue(AutomationProperties.NameProperty, "AccesibilityButton"); + accesibilityButton.SetValue(AutomationProperties.HelpTextProperty, "Help Large Text"); + layout.Children.Add(accesibilityButton, 0, 2); + + Content = layout; + } + + protected override void Init() + { + + } + } +} \ 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 941cd5c31..66001f152 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 @@ -1181,6 +1181,7 @@ + diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs b/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs index 623d19baf..9406e4d45 100644 --- a/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs +++ b/Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs @@ -124,7 +124,7 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers return false; } - if (Element is Picker) + if (Element is Picker || Element is Button) { return false; } diff --git a/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs index a410a5507..0aceb77df 100644 --- a/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs @@ -82,10 +82,26 @@ namespace Xamarin.Forms.Platform.Android.FastRenderers { ((IElementController)Button).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, hasFocus); } - + SizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint) { - return _buttonLayoutManager.GetDesiredSize(widthConstraint, heightConstraint); + if (_isDisposed) + { + return new SizeRequest(); + } + + var hint = Control.Hint; + + if (!string.IsNullOrWhiteSpace(hint)) + { + Control.Hint = string.Empty; + } + + var result = _buttonLayoutManager.GetDesiredSize(widthConstraint, heightConstraint); + + Control.Hint = hint; + + return result; } void IVisualElementRenderer.SetElement(VisualElement element)