-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Fix RadioButton selection in Group (#22787)
* Revert changes to fix the issue * Added repro sample * Added UITest * More samples * Added new UITest * Fix the issue * Removed unnecessary changes * Fixed test description * Adding snapshots * More snapshots
- Loading branch information
1 parent
c8ce71e
commit df93d3a
Showing
11 changed files
with
301 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+23.9 KB
...tCases.Android.Tests/snapshots/android/RadioButtonUpdateValueInsideBorderNo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.6 KB
...Cases.Android.Tests/snapshots/android/RadioButtonUpdateValueInsideBorderYes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions
31
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22183.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#if IOS | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue22183: _IssuesUITest | ||
{ | ||
public Issue22183(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "RadioButton with value cannot display selected state correctly"; | ||
|
||
[Test] | ||
public void RadioButtonWithValueChangeSelected() | ||
{ | ||
App.WaitForElement("TestCollectionView"); | ||
|
||
App.Tap("True_0"); | ||
App.Tap("False_0"); | ||
|
||
VerifyScreenshot(); | ||
|
||
App.Tap("True_1"); | ||
App.Tap("False_1"); | ||
} | ||
} | ||
} | ||
#endif |
31 changes: 31 additions & 0 deletions
31
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22750.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#if ANDROID | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue22750 : _IssuesUITest | ||
{ | ||
public Issue22750(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
public override string Issue => "Using radiobuttons in a group, pressing one button works fine, but pressing the second does not reset the first hence"; | ||
|
||
[Test] | ||
public void RadioButtonUpdateValueInsideBorder() | ||
{ | ||
App.WaitForElement("WaitForStubControl"); | ||
|
||
App.Tap("Yes"); | ||
|
||
App.Tap("No"); | ||
VerifyScreenshot("RadioButtonUpdateValueInsideBorderNo"); | ||
|
||
App.Tap("Yes"); | ||
VerifyScreenshot("RadioButtonUpdateValueInsideBorderYes"); | ||
} | ||
} | ||
} | ||
#endif |
Binary file added
BIN
+18.9 KB
.../tests/TestCases.iOS.Tests/snapshots/ios/RadioButtonWithValueChangeSelected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue22183" | ||
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues"> | ||
<AbsoluteLayout | ||
VerticalOptions="Fill"> | ||
<CollectionView | ||
AutomationId="TestCollectionView" | ||
ItemsSource="{Binding ItemSource}" | ||
AbsoluteLayout.LayoutFlags="All" | ||
AbsoluteLayout.LayoutBounds="0,0,1,1"> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<VerticalStackLayout | ||
x:DataType="local:Issue22183Model" | ||
Padding="20" | ||
Margin="0,0"> | ||
<Border Padding="10"> | ||
<VerticalStackLayout | ||
RadioButtonGroup.GroupName="{Binding GroupId}" | ||
RadioButtonGroup.SelectedValue="{Binding ShowOptions}"> | ||
<RadioButton | ||
AutomationId="{Binding False}" | ||
Content="{Binding False}" | ||
VerticalOptions="Center"> | ||
<RadioButton.Value> | ||
<x:Boolean>False</x:Boolean> | ||
</RadioButton.Value> | ||
</RadioButton> | ||
<RadioButton | ||
AutomationId="{Binding True}" | ||
Content="{Binding True}" | ||
VerticalOptions="Center"> | ||
<RadioButton.Value> | ||
<x:Boolean>True</x:Boolean> | ||
</RadioButton.Value> | ||
</RadioButton> | ||
</VerticalStackLayout> | ||
</Border> | ||
<VerticalStackLayout | ||
IsVisible="{Binding ShowOptions}" | ||
BindableLayout.ItemsSource="{Binding Options}"> | ||
<BindableLayout.ItemTemplate> | ||
<DataTemplate x:DataType="local:Options"> | ||
<HorizontalStackLayout> | ||
<CheckBox /> | ||
<Label | ||
VerticalOptions="Center" | ||
Text="{Binding Name}" /> | ||
</HorizontalStackLayout> | ||
</DataTemplate> | ||
</BindableLayout.ItemTemplate> | ||
</VerticalStackLayout> | ||
</VerticalStackLayout> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
</AbsoluteLayout> | ||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.ObjectModel; | ||
using Microsoft.Maui.Controls; | ||
using Microsoft.Maui.Controls.Xaml; | ||
|
||
namespace Maui.Controls.Sample.Issues | ||
{ | ||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 22183, "RadioButton with value cannot display selected state correctly", PlatformAffected.iOS)] | ||
public partial class Issue22183 : ContentPage | ||
{ | ||
public Issue22183() | ||
{ | ||
InitializeComponent(); | ||
|
||
BindingContext = new Issue22183ViewModel(); | ||
} | ||
} | ||
|
||
public class Issue22183ViewModel | ||
{ | ||
public ObservableCollection<Issue22183Model> ItemSource { get; } = new ObservableCollection<Issue22183Model>( | ||
[new Issue22183Model() | ||
{ | ||
GroupId = 0, | ||
}, | ||
new Issue22183Model() | ||
{ | ||
GroupId = 1, | ||
}]); | ||
} | ||
|
||
public class Issue22183Model : BindableObject | ||
{ | ||
public int GroupId { get; set; } | ||
|
||
public string False => $"False_{GroupId}"; | ||
|
||
public string True => $"True_{GroupId}"; | ||
|
||
public static readonly BindableProperty ShowOptionsProperty = | ||
BindableProperty.Create(nameof(ShowOptions), typeof(bool), typeof(Issue22183Model)); | ||
|
||
public bool ShowOptions | ||
{ | ||
set => SetValue(ShowOptionsProperty, value); | ||
get => (bool)GetValue(ShowOptionsProperty); | ||
} | ||
|
||
public ObservableCollection<Options> Options { get; } | ||
|
||
public Issue22183Model() | ||
{ | ||
ShowOptions = false; | ||
|
||
Options = new ObservableCollection<Options>(); | ||
|
||
for (int i = 0; i < 10; i++) | ||
{ | ||
Options.Add(new Options | ||
{ | ||
Name = $"Options_{i}", | ||
}); | ||
} | ||
} | ||
} | ||
|
||
public class Options | ||
{ | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage | ||
xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue22750" | ||
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues"> | ||
<Border | ||
Padding="15,10,0,0"> | ||
<Border.Shadow> | ||
<Shadow | ||
Brush="{AppThemeBinding Light=LightGray, Dark=Gray}" | ||
Offset="5,5" | ||
Opacity="0.5"/> | ||
</Border.Shadow> | ||
<VerticalStackLayout> | ||
<Label | ||
AutomationId="WaitForStubControl" | ||
Text="Lorem ipsum dolor sit amet" | ||
FontAttributes="Bold" /> | ||
<Label | ||
Text="{Binding Text}" | ||
FontSize="Small" | ||
HorizontalOptions="Start" | ||
VerticalOptions="Start" | ||
Padding="0,0,15,0"/> | ||
<HorizontalStackLayout> | ||
<RadioButton | ||
Content="Yes" | ||
AutomationId="Yes" | ||
GroupName="Issue22750Group" | ||
CheckedChanged="OnRadioButtonCheckedChanged" /> | ||
<RadioButton | ||
Content="No" | ||
AutomationId="No" | ||
GroupName="Issue22750Group" | ||
CheckedChanged="OnRadioButtonCheckedChanged" /> | ||
</HorizontalStackLayout> | ||
</VerticalStackLayout> | ||
</Border> | ||
</ContentPage> |
Oops, something went wrong.