From d7bf85c15f65558665b33668f002ac29d19fc903 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:51:33 +0900 Subject: [PATCH 1/2] Fixed List layout --- .../Views/Layouts/GridLayoutPage.xaml | 3 +- .../Views/Layouts/GridLayoutPage.xaml.cs | 34 +++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml b/src/Files.App/Views/Layouts/GridLayoutPage.xaml index 5df80a4c0875..19c2c1e660b8 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml @@ -41,7 +41,8 @@ - + + diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs index bd217e3e1a82..d858c72c4195 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs @@ -664,6 +664,14 @@ private void Grid_Loaded(object sender, RoutedEventArgs e) if (item is GridViewItem itemContainer) itemContainer.ContextFlyout = ItemContextMenuFlyout; + + // Change VerticalScrollMode after items are loaded (#14785) + if (FolderSettings?.LayoutMode is FolderLayoutModes.ListView && + ScrollViewer.GetVerticalScrollMode(FileList) is not ScrollMode.Disabled) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); + else if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + ScrollViewer.GetVerticalScrollMode(FileList) is not ScrollMode.Enabled) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); } private void Grid_PointerEntered(object sender, PointerRoutedEventArgs e) @@ -691,40 +699,46 @@ private void SelectionCheckbox_PointerCanceled(object sender, PointerRoutedEvent // 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) + if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); base.FileList_DragItemsStarting(sender, e); - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false && + if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) && e.Cancel) - ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Auto); + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); } private void ItemsLayout_DragEnter(object sender, DragEventArgs e) { - if (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) + if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (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); + if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + 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 (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + 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 (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && + (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); base.Item_Drop(sender, e); } From 6f7bf0f8640dd2aeaacbc96190ee28ef8c549db5 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Thu, 22 Feb 2024 00:04:17 +0900 Subject: [PATCH 2/2] Refactored --- .../Views/Layouts/GridLayoutPage.xaml | 5 +-- .../Views/Layouts/GridLayoutPage.xaml.cs | 43 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml b/src/Files.App/Views/Layouts/GridLayoutPage.xaml index 19c2c1e660b8..7ba67452df65 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml @@ -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" @@ -41,8 +40,8 @@ - - + + diff --git a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs index d858c72c4195..acd6a88c78d9 100644 --- a/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs +++ b/src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs @@ -24,6 +24,7 @@ public sealed partial class GridLayoutPage : BaseGroupableLayoutPage // Fields private uint currentIconSize; + private volatile bool shouldSetVerticalScrollMode; // Properties @@ -238,6 +239,8 @@ private void SetItemTemplate() FileList.ItemsSource = oldSource; } + shouldSetVerticalScrollMode = true; + switch (FolderSettings.LayoutMode) { case FolderLayoutModes.ListView: @@ -665,13 +668,16 @@ private void Grid_Loaded(object sender, RoutedEventArgs e) if (item is GridViewItem itemContainer) itemContainer.ContextFlyout = ItemContextMenuFlyout; - // Change VerticalScrollMode after items are loaded (#14785) - if (FolderSettings?.LayoutMode is FolderLayoutModes.ListView && - ScrollViewer.GetVerticalScrollMode(FileList) is not ScrollMode.Disabled) - ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); - else if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - ScrollViewer.GetVerticalScrollMode(FileList) is not ScrollMode.Enabled) - ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); + // 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) @@ -697,38 +703,36 @@ 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 (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); base.FileList_DragItemsStarting(sender, e); - if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false) && - e.Cancel) + if (ShouldDisableScrollingWhenDragAndDrop && e.Cancel) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); } private void ItemsLayout_DragEnter(object sender, DragEventArgs e) { - if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Disabled); } private void ItemsLayout_DragLeave(object sender, DragEventArgs e) { - if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); } protected override void ItemsLayout_Drop(object sender, DragEventArgs e) { - if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); base.ItemsLayout_Drop(sender, e); @@ -736,8 +740,7 @@ protected override void ItemsLayout_Drop(object sender, DragEventArgs e) protected override void Item_Drop(object sender, DragEventArgs e) { - if (FolderSettings?.LayoutMode is FolderLayoutModes.GridView or FolderLayoutModes.TilesView && - (ParentShellPageInstance?.FilesystemViewModel.FilesAndFolders.IsGrouped ?? false)) + if (ShouldDisableScrollingWhenDragAndDrop) ScrollViewer.SetVerticalScrollMode(FileList, ScrollMode.Enabled); base.Item_Drop(sender, e);