Skip to content

Commit

Permalink
Fix for CollectionView SelectedItem loses Background after opening an…
Browse files Browse the repository at this point in the history
…d closing a Modal page (dotnet#26694)

* Fixed-22467 : CollectionView SelectedItem loses Background after opening and closing a Modal page

* UI test images updated

* UI test images updated

* ios UI test image updated

---------

Co-authored-by: praveenkumarkarunanithi <[email protected]>
Co-authored-by: praveenkumarkarunanithi <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent e3a4c07 commit 758b5e3
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,17 @@ internal void UpdateSelectionMode()
case SelectionMode.None:
CollectionView.AllowsSelection = false;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = true;
break;
case SelectionMode.Single:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = false;
break;
case SelectionMode.Multiple:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = true;
ClearsSelectionOnViewWillAppear = false;
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,17 @@ internal void UpdateSelectionMode()
case SelectionMode.None:
CollectionView.AllowsSelection = false;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = true;
break;
case SelectionMode.Single:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = false;
ClearsSelectionOnViewWillAppear = false;
break;
case SelectionMode.Multiple:
CollectionView.AllowsSelection = true;
CollectionView.AllowsMultipleSelection = true;
ClearsSelectionOnViewWillAppear = false;
break;
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22467.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?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.Issue22467"
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues">
<Grid>

<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<CollectionView x:Name="ResultCollectionView"
AutomationId="CollectionView"
Grid.Row="0"
MinimumHeightRequest="150"
MaximumHeightRequest="300"
SelectionMode="Single">

<CollectionView.ItemTemplate>
<DataTemplate>
<VerticalStackLayout>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal"/>
<VisualState Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor"
Value="LightGreen"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>

<Label Text="{Binding}"
FontSize="14"
VerticalTextAlignment="Center"
Margin="25,7,7,7"/>

<BoxView HeightRequest="1"
BackgroundColor="Black"/>

</VerticalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>

<Button Grid.Row="1"
x:Name="CounterBtn"
AutomationId="PushModalAsyncButton"
Text="Push New Page"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="CounterBtn_Clicked"
HorizontalOptions="Fill"/>
</Grid>
</ContentPage>
45 changes: 45 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22467.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22467, "CollectionView SelectedItem Background Reset After Modal Navigation", PlatformAffected.iOS)]
public partial class Issue22467 : ContentPage
{
public Issue22467()
{
InitializeComponent();
List<string> list = new() { "1", "2", "3", "4", "5" };
ResultCollectionView.ItemsSource = list;
ResultCollectionView.SelectedItem = list[3];
}

private async void CounterBtn_Clicked(object sender, EventArgs e)
{
await Navigation.PushModalAsync(CreateNewPage1());
}

private ContentPage CreateNewPage1()
{
var newPage = new ContentPage
{
Title = "NewPage1",
Content = new VerticalStackLayout
{
Children =
{
new Button
{
Text = "Pop to Main Page",
AutomationId = "PopModalAsyncButton",
Command = new Command(async () =>
{
await Navigation.PopModalAsync(true);
})
}
}
}
};

return newPage;
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue22467 : _IssuesUITest
{
public Issue22467(TestDevice device) : base(device) { }

public override string Issue => "CollectionView SelectedItem Background Reset After Modal Navigation";

[Test]
[Category(UITestCategories.CollectionView)]
public void CollectionViewSelectedItemBackgroundShouldPersistAfterModalNavigation()
{
App.WaitForElement("CollectionView");
App.Tap("PushModalAsyncButton");
App.WaitForElement("PopModalAsyncButton");
App.Tap("PopModalAsyncButton");
App.WaitForElement("CollectionView");
VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 758b5e3

Please sign in to comment.