Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ bool PositionIsSelected(int position)

void SelectableClicked(object sender, int adapterPosition)
{
UpdateMauiSelection(adapterPosition);
if (adapterPosition >= 0 && adapterPosition < ItemsSource?.Count)
{
UpdateMauiSelection(adapterPosition);
}
}

void UpdateMauiSelection(int adapterPosition)
Expand Down
18 changes: 18 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22674.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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.Issue22674">
<CollectionView
AutomationId="TestCollectionView"
SelectionMode="Single"
ItemsSource="{Binding ItemList}"
SelectionChanged="OnCollectionViewSelectionChanged">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label
Text="{Binding .}"
HorizontalTextAlignment="Center" />
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
28 changes: 28 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue22674.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.ObjectModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 22674, "Crash when quickly clicking to delete item", PlatformAffected.iOS)]
public partial class Issue22674 : ContentPage
{
public Issue22674()
{
InitializeComponent();

BindingContext = this;
}

public ObservableCollection<string> ItemList { get; } = ["A", "B", "C", "D", "E", "F", "G", "H", "I",];

void OnCollectionViewSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is CollectionView view && view.SelectedItem is string item)
{
ItemList.Remove(item);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue22674 : _IssuesUITest
{
public Issue22674(TestDevice device) : base(device) { }

public override string Issue => "Crash when quickly clicking to delete item";

[Test]
[Category(UITestCategories.CollectionView)]
public void RemoveItemWhenSelectionChanged()
{
App.WaitForElement("TestCollectionView");

for (int i = 0; i < 5; i++)
{
App.TapCoordinates(24, 24);
}

// Without crashes, the test has passed.
}
}
#endif