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 issue where item selection didn't work properly the List View layout #14800

Merged
merged 3 commits into from
Feb 21, 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
4 changes: 2 additions & 2 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
xmlns:local="using:Files.App.Views.Layouts"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:storage="using:Files.App.Utils.Storage"
xmlns:toolkit="using:CommunityToolkit.WinUI.UI.Controls"
xmlns:tui="using:CommunityToolkit.WinUI.UI"
xmlns:uc="using:Files.App.UserControls"
xmlns:wctanimations="using:CommunityToolkit.WinUI.UI.Animations"
Expand Down Expand Up @@ -41,7 +40,8 @@
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
<!-- VerticalScrollMode is set to Auto because setting it to Disabled here causes an issue. (#14785) -->
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
Expand Down
39 changes: 28 additions & 11 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public sealed partial class GridLayoutPage : BaseGroupableLayoutPage
// Fields

private uint currentIconSize;
private volatile bool shouldSetVerticalScrollMode;

// Properties

Expand Down Expand Up @@ -238,6 +239,8 @@ private void SetItemTemplate()
FileList.ItemsSource = oldSource;
}

shouldSetVerticalScrollMode = true;

switch (FolderSettings.LayoutMode)
{
case FolderLayoutModes.ListView:
Expand Down Expand Up @@ -664,6 +667,17 @@ private void Grid_Loaded(object sender, RoutedEventArgs e)

if (item is GridViewItem itemContainer)
itemContainer.ContextFlyout = ItemContextMenuFlyout;

// Set VerticalScrollMode after an item has been loaded (#14785)
if (shouldSetVerticalScrollMode)
{
shouldSetVerticalScrollMode = false;

if (FolderSettings?.LayoutMode is FolderLayoutModes.ListView)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled);
else
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled);
}
}

private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e)
Expand All @@ -689,42 +703,45 @@ private void SelectionCheckbox_PointerCanceled(object sender, PointerRoutedEvent
}

// To avoid crashes, disable scrolling when drag-and-drop if grouped. (#14484)
private bool ShouldDisableScrollingWhenDragAndDrop =>
FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView &&
(ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false);

protected override void FileList_DragItemsStarting(object sender, DragItemsStartingEventArgs e)
{
if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)
if (ShouldDisableScrollingWhenDragAndDrop)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled);

base.FileList_DragItemsStarting(sender, e);

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

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

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

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

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);
if (ShouldDisableScrollingWhenDragAndDrop)
ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled);

base.Item_Drop(sender, e);
}
Expand Down
Loading