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

Feature: Keep scroll offset when changing item size #14914

Merged
merged 1 commit into from Mar 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Files.App/Views/Layouts/ColumnLayoutPage.xaml
Expand Up @@ -191,6 +191,7 @@
IsRightTapEnabled="True"
IsTabStop="True"
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
Loaded="FileList_Loaded"
PreviewKeyDown="FileList_PreviewKeyDown"
RightTapped="FileList_RightTapped"
ScrollViewer.IsScrollInertiaEnabled="True"
Expand Down
15 changes: 12 additions & 3 deletions src/Files.App/Views/Layouts/ColumnLayoutPage.xaml.cs
Expand Up @@ -40,7 +40,7 @@ public sealed partial class ColumnLayoutPage : BaseGroupableLayoutPage

protected override ListViewBase ListViewBase => FileList;
protected override SemanticZoom RootZoom => RootGridZoom;

public ScrollViewer? ContentScroller { get; private set; }

/// <summary>
/// Row height in the Columns View
Expand All @@ -66,6 +66,11 @@ public ColumnLayoutPage() : base()

// Methods

private void FileList_Loaded(object sender, RoutedEventArgs e)
{
ContentScroller = FileList.FindDescendant<ScrollViewer>(x => x.Name == "ScrollViewer");
}

private void ColumnViewBase_GotFocus(object sender, RoutedEventArgs e)
{
if (FileList.SelectedItem == null && openedFolderPresenter != null)
Expand Down Expand Up @@ -167,14 +172,18 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)

private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
// TODO keep scroll position when changing styles (see details view)

if (e.PropertyName == nameof(ILayoutSettingsService.ColumnsViewSize))
{
// Get current scroll position
var previousOffset = ContentScroller?.VerticalOffset;

NotifyPropertyChanged(nameof(RowHeight));

// Update the container style to match the item size
SetItemContainerStyle();

// Restore correct scroll position
ContentScroller?.ChangeView(null, previousOffset, null);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Files.App/Views/Layouts/GridLayoutPage.xaml
Expand Up @@ -778,6 +778,7 @@
IsTabStop="True"
ItemContainerTransitions="{x:Null}"
ItemsSource="{x:Bind CollectionViewSource.View, Mode=OneWay}"
Loaded="FileList_Loaded"
PreviewKeyDown="FileList_PreviewKeyDown"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
SelectionChanged="FileList_SelectionChanged"
Expand Down
13 changes: 12 additions & 1 deletion src/Files.App/Views/Layouts/GridLayoutPage.xaml.cs
Expand Up @@ -28,6 +28,8 @@ public sealed partial class GridLayoutPage : BaseGroupableLayoutPage

// Properties

public ScrollViewer? ContentScroller { get; private set; }

protected override ListViewBase ListViewBase => FileList;
protected override SemanticZoom RootZoom => RootGridZoom;

Expand Down Expand Up @@ -147,7 +149,8 @@ protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)

private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChangedEventArgs e)
{
// TODO keep scroll position when changing styles (see details view)
// Get current scroll position
var previousOffset = ContentScroller?.VerticalOffset;

if (e.PropertyName == nameof(ILayoutSettingsService.ListViewSize))
{
Expand Down Expand Up @@ -175,6 +178,9 @@ private void LayoutSettingsService_PropertyChanged(object? sender, PropertyChang

FolderSettings_IconHeightChanged();
}

// Restore correct scroll position
ContentScroller?.ChangeView(null, previousOffset, null);
}

private async void FolderSettings_LayoutModeChangeRequested(object? sender, LayoutModeEventArgs e)
Expand Down Expand Up @@ -249,6 +255,11 @@ private void SetItemContainerStyle()
}
}

private void FileList_Loaded(object sender, RoutedEventArgs e)
{
ContentScroller = FileList.FindDescendant<ScrollViewer>(x => x.Name == "ScrollViewer");
}

protected override void FileList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
base.FileList_SelectionChanged(sender, e);
Expand Down