Skip to content

Commit c768997

Browse files
Tamilarasan-Paranthamanrmarinho
authored andcommitted
[Catalyst] Click-Dragging Behavior in CollectionView (#29616)
* CollectionView drag changes on Mac * Mac drag changes
1 parent 71a47f4 commit c768997

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class ReorderableItemsViewController<TItemsView> : GroupableItemsViewCont
1414
bool _disposed;
1515
UILongPressGestureRecognizer _longPressGestureRecognizer;
1616

17+
#if MACCATALYST
18+
const double defaultMacCatalystPressDuration = 0.1;
19+
#endif
20+
1721
public ReorderableItemsViewController(TItemsView reorderableItemsView, ItemsViewLayout layout)
1822
: base(reorderableItemsView, layout)
1923
{
@@ -162,6 +166,12 @@ public void UpdateCanReorderItems()
162166
if (_longPressGestureRecognizer == null)
163167
{
164168
_longPressGestureRecognizer = new UILongPressGestureRecognizer(HandleLongPress);
169+
#if MACCATALYST
170+
// On Mac Catalyst, we disable the default drag interaction and instead handle dragging using a long press gesture recognizer.
171+
// Since a long press typically takes more time to trigger than the system's default drag interaction,
172+
// we reduce the minimum press duration to 0.1 seconds to better match the previous behavior.
173+
_longPressGestureRecognizer.MinimumPressDuration = defaultMacCatalystPressDuration;
174+
#endif
165175
CollectionView.AddGestureRecognizer(_longPressGestureRecognizer);
166176
}
167177
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class ReorderableItemsViewController2<TItemsView> : GroupableItemsViewCon
1414
bool _disposed;
1515
UILongPressGestureRecognizer _longPressGestureRecognizer;
1616

17+
#if MACCATALYST
18+
const double defaultMacCatalystPressDuration = 0.1;
19+
#endif
20+
1721
public ReorderableItemsViewController2(TItemsView reorderableItemsView, UICollectionViewLayout layout)
1822
: base(reorderableItemsView, layout)
1923
{
@@ -162,6 +166,12 @@ public void UpdateCanReorderItems()
162166
if (_longPressGestureRecognizer == null)
163167
{
164168
_longPressGestureRecognizer = new UILongPressGestureRecognizer(HandleLongPress);
169+
#if MACCATALYST
170+
// On Mac Catalyst, we disable the default drag interaction and instead handle dragging using a long press gesture recognizer.
171+
// Since a long press typically takes more time to trigger than the system's default drag interaction,
172+
// we reduce the minimum press duration to 0.1 seconds to better match the previous behavior.
173+
_longPressGestureRecognizer.MinimumPressDuration = defaultMacCatalystPressDuration;
174+
#endif
165175
CollectionView.AddGestureRecognizer(_longPressGestureRecognizer);
166176
}
167177
}

0 commit comments

Comments
 (0)