-
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.
Pickers Inside CollectionView get SelectedItem Cleared on Scrolling -…
… fix
- Loading branch information
Showing
4 changed files
with
128 additions
and
2 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
59 changes: 59 additions & 0 deletions
59
src/Controls/tests/TestCases.HostApp/Issues/Issue25842.xaml
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,59 @@ | ||
<?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.Issue25842"> | ||
<ContentView> | ||
<CollectionView HeightRequest="600" | ||
AutomationId="CollectionView" | ||
VerticalOptions="Center" | ||
ItemsSource="{Binding Students}"> | ||
<CollectionView.ItemsLayout> | ||
<GridItemsLayout | ||
Orientation="Vertical" | ||
Span="1" | ||
HorizontalItemSpacing="10" | ||
VerticalItemSpacing="10"/> | ||
</CollectionView.ItemsLayout> | ||
<CollectionView.ItemTemplate> | ||
<DataTemplate> | ||
<Border Stroke="Black" | ||
StrokeThickness="1" | ||
Padding="10" | ||
BackgroundColor="Gray" | ||
StrokeShape="RoundRectangle 10"> | ||
<VerticalStackLayout Spacing="10"> | ||
<HorizontalStackLayout VerticalOptions="FillAndExpand" | ||
HorizontalOptions="FillAndExpand" | ||
Spacing="10"> | ||
<Label Text="Name:" | ||
FontAttributes="Bold" | ||
VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="FillAndExpand"/> | ||
<Label Text="{Binding Name}" | ||
FontSize="Medium" | ||
VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="FillAndExpand"/> | ||
</HorizontalStackLayout> | ||
|
||
<HorizontalStackLayout VerticalOptions="FillAndExpand" | ||
HorizontalOptions="FillAndExpand" | ||
Spacing="10"> | ||
<Label Text="Country:" | ||
FontAttributes="Bold" | ||
VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="FillAndExpand"/> | ||
<Picker Title="Country" | ||
WidthRequest="300" | ||
ItemsSource="{Binding Countries}" | ||
SelectedItem="{Binding Country}" | ||
VerticalOptions="CenterAndExpand" | ||
HorizontalOptions="FillAndExpand" | ||
FontSize="Medium"/> | ||
</HorizontalStackLayout> | ||
</VerticalStackLayout> | ||
</Border> | ||
</DataTemplate> | ||
</CollectionView.ItemTemplate> | ||
</CollectionView> | ||
</ContentView> | ||
</ContentPage> |
42 changes: 42 additions & 0 deletions
42
src/Controls/tests/TestCases.HostApp/Issues/Issue25842.xaml.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,42 @@ | ||
using System.Collections.ObjectModel; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 25842, "Pickers Inside CollectionView get SelectedItem Cleared on Scrolling", PlatformAffected.iOS)] | ||
public partial class Issue25842 : ContentPage | ||
{ | ||
public Issue25842() | ||
{ | ||
InitializeComponent(); | ||
BindingContext = new Issue25842ViewModel(); | ||
} | ||
|
||
class Issue25842ViewModel | ||
{ | ||
public ObservableCollection<Student> Students { get; set; } | ||
|
||
public Issue25842ViewModel() | ||
{ | ||
Students = new() | ||
{ | ||
new () { Name = "John Doe", Country = "United States" }, | ||
new () { Name = "Jane Smith", Country = "Canada" }, | ||
new () { Name = "Sam Brown", Country = "India" }, | ||
new () { Name = "Lisa White", Country = "United States" }, | ||
new () { Name = "Tom Green", Country = "Canada" }, | ||
new () { Name = "Emma Black", Country = "India" }, | ||
new () { Name = "Noah Blue", Country = "United States" }, | ||
new () { Name = "Olivia Yellow", Country = "Canada" }, | ||
new () { Name = "Liam Brown", Country = "India" }, | ||
new () { Name = "Sophia Pink", Country = "United States" } | ||
}; | ||
} | ||
|
||
public class Student | ||
{ | ||
public required string Name { get; set; } | ||
public required string Country { get; set; } | ||
public ObservableCollection<string> Countries { get; set; } = new() { "United States", "Canada", "India" }; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue25842.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,27 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue25842 : _IssuesUITest | ||
{ | ||
public Issue25842(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "Pickers Inside CollectionView get SelectedItem Cleared on Scrolling"; | ||
|
||
[Test] | ||
[Description("Verify that OnTapped is fired every time a ViewCell is tapped")] | ||
[Category(UITestCategories.CollectionView)] | ||
[Category(UITestCategories.Picker)] | ||
public void SelectedPickerItemsShouldNotClear() | ||
{ | ||
App.WaitForElement("CollectionView"); | ||
App.ScrollDown("CollectionView"); | ||
App.ScrollUp("CollectionView"); | ||
VerifyScreenshot(); | ||
} | ||
} | ||
} |