Skip to content

Commit c05aff5

Browse files
authored
[Catalyst] Fixed the CanMixGroups Set to False Still Allows Reordering Between Groups in CollectionView (#28623)
* Fixed the CanMixGroups Set to False Still Allows Reordering Between Groups in CollectionView * Committed the test case and sample * Committed the pending snap
1 parent f6353ac commit c05aff5

File tree

8 files changed

+122
-0
lines changed

8 files changed

+122
-0
lines changed

src/Controls/src/Core/Handlers/Items/iOS/ReorderableItemsViewController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public ReorderableItemsViewController(TItemsView reorderableItemsView, ItemsView
2121
// For some reason it only seemed to work when the CollectionView was inside the Flyout section of a FlyoutPage.
2222
// The UILongPressGestureRecognizer is simple enough to set up so let's just add our own.
2323
InstallsStandardGestureForInteractiveMovement = false;
24+
#if MACCATALYST
25+
// On Mac Catalyst, the default normal press and drag interactions occur, causing the CanMixGroups = false logic to not work.
26+
// Since all reordering logic is handled exclusively by UILongPressGestureRecognizer, we can set DragInteractionEnabled to false, ensuring that only the long press gesture is used.
27+
CollectionView.DragInteractionEnabled = false;
28+
#endif
2429
}
2530

2631
public override bool CanMoveItem(UICollectionView collectionView, NSIndexPath indexPath)

src/Controls/src/Core/Handlers/Items2/iOS/ReorderableItemsViewController2.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public ReorderableItemsViewController2(TItemsView reorderableItemsView, UICollec
2121
// For some reason it only seemed to work when the CollectionView was inside the Flyout section of a FlyoutPage.
2222
// The UILongPressGestureRecognizer is simple enough to set up so let's just add our own.
2323
InstallsStandardGestureForInteractiveMovement = false;
24+
#if MACCATALYST
25+
// On Mac Catalyst, the default normal press and drag interactions occur, causing the CanMixGroups = false logic to not work.
26+
// Since all reordering logic is handled exclusively by UILongPressGestureRecognizer, we can set DragInteractionEnabled to false, ensuring that only the long press gesture is used.
27+
CollectionView.DragInteractionEnabled = false;
28+
#endif
2429
}
2530

2631
public override bool CanMoveItem(UICollectionView collectionView, NSIndexPath indexPath)
10.8 KB
Loading
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage
3+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
x:Class="Maui.Controls.Sample.Issues.Issue28530">
6+
7+
<VerticalStackLayout Padding="10">
8+
<CollectionView
9+
ItemsSource="{Binding GroupedItems}"
10+
IsGrouped="true"
11+
CanReorderItems="true"
12+
CanMixGroups="false"
13+
AutomationId="CollectionViewControl">
14+
<CollectionView.GroupHeaderTemplate>
15+
<DataTemplate>
16+
<Label Text="{Binding GroupHeaderName}"
17+
FontAttributes="Bold"
18+
FontSize="14"
19+
Padding="5"/>
20+
</DataTemplate>
21+
</CollectionView.GroupHeaderTemplate>
22+
<CollectionView.ItemTemplate>
23+
<DataTemplate>
24+
<Label Text="{Binding Name}"
25+
AutomationId="{Binding .}"
26+
FontSize="12"
27+
Padding="5"/>
28+
</DataTemplate>
29+
</CollectionView.ItemTemplate>
30+
</CollectionView>
31+
</VerticalStackLayout>
32+
33+
</ContentPage>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System.Collections.ObjectModel;
2+
using System.ComponentModel;
3+
4+
namespace Maui.Controls.Sample.Issues;
5+
[Issue(IssueTracker.Github, 28530, "[Catalyst] CanMixGroups Set to False Still Allows Reordering Between Groups in CollectionView", PlatformAffected.macOS)]
6+
public partial class Issue28530 : ContentPage
7+
{
8+
public Issue28530()
9+
{
10+
InitializeComponent();
11+
BindingContext = new Issue28530CollectionViewViewModel();
12+
}
13+
}
14+
15+
public class Issue28530CollectionViewViewModel : INotifyPropertyChanged
16+
{
17+
public ObservableCollection<Issue28530GroupedItem> GroupedItems { get; set; }
18+
public event PropertyChangedEventHandler PropertyChanged;
19+
20+
public Issue28530CollectionViewViewModel()
21+
{
22+
GroupedItems = new ObservableCollection<Issue28530GroupedItem>
23+
{
24+
new Issue28530GroupedItem("Group 1")
25+
{
26+
new Issue28530Item { Name = "Item 1" },
27+
new Issue28530Item { Name = "Item 2" }
28+
},
29+
new Issue28530GroupedItem("Group 2")
30+
{
31+
new Issue28530Item { Name = "Item 3" },
32+
new Issue28530Item { Name = "Item 4" }
33+
}
34+
};
35+
}
36+
37+
protected void OnPropertyChanged(string propertyName)
38+
{
39+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
40+
}
41+
}
42+
43+
public class Issue28530GroupedItem : ObservableCollection<Issue28530Item>
44+
{
45+
public string GroupHeaderName { get; set; }
46+
47+
public Issue28530GroupedItem(string groupHeaderName)
48+
{
49+
GroupHeaderName = groupHeaderName;
50+
}
51+
}
52+
53+
public class Issue28530Item
54+
{
55+
public string Name { get; set; }
56+
}
9.67 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#if TEST_FAILS_ON_WINDOWS
2+
// https://github.com/dotnet/maui/issues/13027 In windows, .NET MAUI CollectionView does not reorder when grouped
3+
using NUnit.Framework;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues;
8+
public class Issue28530 : _IssuesUITest
9+
{
10+
public Issue28530(TestDevice device) : base(device) { }
11+
12+
public override string Issue => "[Catalyst] CanMixGroups Set to False Still Allows Reordering Between Groups in CollectionView";
13+
14+
[Test]
15+
[Category(UITestCategories.CollectionView)]
16+
public void ReorderBetweenGroupsShouldNotOccurWhenCanMixGroupsIsFalse()
17+
{
18+
App.WaitForElement("CollectionViewControl");
19+
App.DragAndDrop("Item 2", "Item 3");
20+
VerifyScreenshot();
21+
}
22+
}
23+
#endif
15 KB
Loading

0 commit comments

Comments
 (0)