Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed crash that could occur when dragging in grouped grid layout #14654

Merged
merged 2 commits into from
Feb 6, 2024
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
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
Loading