Skip to content

Commit

Permalink
Fix: Fixed crash that could occur when dragging in grouped grid layout (
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu authored Feb 6, 2024
1 parent e0ca27b commit a06aafc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Files.App/Views/Layouts/BaseLayoutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ protected virtual void Page_CharacterReceived(UIElement sender, CharacterReceive
}
}

protected void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
protected virtual void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
try
{
Expand Down Expand Up @@ -1094,7 +1094,7 @@ private async void Item_DragOver(object sender, DragEventArgs e)
}
}

private async void Item_Drop(object sender, DragEventArgs e)
protected virtual async void Item_Drop(object sender, DragEventArgs e)
{
var deferral = e.GetDeferral();

Expand Down Expand Up @@ -1282,7 +1282,7 @@ protected void ItemsLayout_DragOver(object sender, DragEventArgs e)
CommandsViewModel?.DragOverCommand?.Execute(e);
}

protected void ItemsLayout_Drop(object sender, DragEventArgs e)
protected virtual void ItemsLayout_Drop(object sender, DragEventArgs e)
{
CommandsViewModel?.DropCommand?.Execute(e);
}
Expand Down
2 changes: 2 additions & 0 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,9 @@
CanDragItems="{x:Bind AllowItemDrag, Mode=OneWay}"
ContainerContentChanging="FileList_ContainerContentChanging"
DoubleTapped="FileList_DoubleTapped"
DragEnter="ItemsLayout_DragEnter"
DragItemsStarting="FileList_DragItemsStarting"
DragLeave="ItemsLayout_DragLeave"
DragOver="ItemsLayout_DragOver"
Drop="ItemsLayout_Drop"
FocusVisualPrimaryThickness="0"
Expand Down
41 changes: 41 additions & 0 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,47 @@ private void SelectionCheckbox_PointerCanceled(object sender, PointerRoutedEvent
UpdateCheckboxVisibility((sender as FrameworkElement)!.FindAscendant<GridViewItem>()!, false);
}

// To avoid crashes, disable scrolling when drag-and-drop if grouped. (#14484)
protected override void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled);

base.FileList_DragItemsStarting(sender, e);

if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false &&
e.Cancel)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto);
}

private void ItemsLayout_DragEnter(object sender, DragEventArgs e)
{
if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled);
}

private void ItemsLayout_DragLeave(object sender, DragEventArgs e)
{
if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto);
}

protected override void ItemsLayout_Drop(object sender, DragEventArgs e)
{
if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto);

base.ItemsLayout_Drop(sender, e);
}

protected override void Item_Drop(object sender, DragEventArgs e)
{
if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto);

base.Item_Drop(sender, e);
}

private void UpdateCheckboxVisibility(object sender, bool isPointerOver)
{
if (sender is GridViewItem control && control.FindDescendant<UserControl>() is UserControl userControl)
Expand Down

0 comments on commit a06aafc

Please sign in to comment.