Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pickers Inside CollectionView get SelectedItem Cleared on Scrolling - FIX #26775

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Controls/src/Core/Picker/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ void OnItemsSourceChanged(IList oldValue, IList newValue)
}
else
{
// Unlock, then clear, so OnItemsCollectionChanged executes
((LockableObservableListWrapper)Items).IsLocked = false;
((LockableObservableListWrapper)Items).InternalClear();
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue25842.xaml
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 src/Controls/tests/TestCases.HostApp/Issues/Issue25842.xaml.cs
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" };
}
}
}
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();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.