Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 24bb5bb

Browse files
magoolationjfversluis
authored andcommitted
#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
1 parent eb4ae07 commit 24bb5bb

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Xamarin.Forms.Internals;
2+
using Xamarin.Forms.CustomAttributes;
3+
4+
#if UITEST
5+
using Xamarin.Forms.Core.UITests;
6+
using Xamarin.UITest;
7+
using NUnit.Framework;
8+
#endif
9+
10+
namespace Xamarin.Forms.Controls.Issues
11+
{
12+
#if UITEST
13+
[Category(UITestCategories.Button)]
14+
#endif
15+
[Preserve(AllMembers = true)]
16+
[Issue(IssueTracker.Github, 7875, "Button size changes when setting Accessibility properties", PlatformAffected.Android)]
17+
public class Issue7875 : TestContentPage
18+
{
19+
public Issue7875()
20+
{
21+
Title = "Issue 7875";
22+
23+
var layout = new Grid();
24+
25+
layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
26+
layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
27+
layout.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
28+
29+
var instructions = new Label
30+
{
31+
BackgroundColor = Color.Black,
32+
TextColor = Color.White,
33+
Text = "If the buttons below have the same size, the test has passed."
34+
};
35+
layout.Children.Add(instructions, 0, 0);
36+
37+
var button = new Button
38+
{
39+
BackgroundColor = Color.Gray,
40+
HorizontalOptions = LayoutOptions.Center,
41+
ImageSource = "calculator.png",
42+
Text = "Text"
43+
};
44+
layout.Children.Add(button, 0, 1);
45+
46+
var accesibilityButton = new Button
47+
{
48+
BackgroundColor = Color.Gray,
49+
HorizontalOptions = LayoutOptions.Center,
50+
ImageSource = "calculator.png",
51+
Text = "Text"
52+
};
53+
accesibilityButton.SetValue(AutomationProperties.NameProperty, "AccesibilityButton");
54+
accesibilityButton.SetValue(AutomationProperties.HelpTextProperty, "Help Large Text");
55+
layout.Children.Add(accesibilityButton, 0, 2);
56+
57+
Content = layout;
58+
}
59+
60+
protected override void Init()
61+
{
62+
63+
}
64+
}
65+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

+1
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@
11811181
<Compile Include="$(MSBuildThisFileDirectory)Issue8672.cs" />
11821182
<Compile Include="$(MSBuildThisFileDirectory)Issue8326.xaml.cs" />
11831183
<Compile Include="$(MSBuildThisFileDirectory)Issue8449.xaml.cs" />
1184+
<Compile Include="$(MSBuildThisFileDirectory)Issue7875.cs" />
11841185
</ItemGroup>
11851186
<ItemGroup>
11861187
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Bugzilla22229.xaml">

Xamarin.Forms.Platform.Android/FastRenderers/AutomationPropertiesProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ static bool SetHint(AView Control, BindableObject Element, ref string defaultHin
124124
return false;
125125
}
126126

127-
if (Element is Picker)
127+
if (Element is Picker || Element is Button)
128128
{
129129
return false;
130130
}

Xamarin.Forms.Platform.Android/FastRenderers/ButtonRenderer.cs

+18-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,26 @@ void IOnFocusChangeListener.OnFocusChange(AView v, bool hasFocus)
8282
{
8383
((IElementController)Button).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, hasFocus);
8484
}
85-
85+
8686
SizeRequest IVisualElementRenderer.GetDesiredSize(int widthConstraint, int heightConstraint)
8787
{
88-
return _buttonLayoutManager.GetDesiredSize(widthConstraint, heightConstraint);
88+
if (_isDisposed)
89+
{
90+
return new SizeRequest();
91+
}
92+
93+
var hint = Control.Hint;
94+
95+
if (!string.IsNullOrWhiteSpace(hint))
96+
{
97+
Control.Hint = string.Empty;
98+
}
99+
100+
var result = _buttonLayoutManager.GetDesiredSize(widthConstraint, heightConstraint);
101+
102+
Control.Hint = hint;
103+
104+
return result;
89105
}
90106

91107
void IVisualElementRenderer.SetElement(VisualElement element)

0 commit comments

Comments
 (0)