Skip to content

Commit

Permalink
Fix: Fixed issue where refocusing Details View would sometimes scroll (
Browse files Browse the repository at this point in the history
  • Loading branch information
yaira2 authored Feb 8, 2024
1 parent 797b7ce commit 6025ab3
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions src/Files.App/Data/Behaviors/StickyHeaderBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,6 @@ private bool AssignAnimation()
headerElement.SizeChanged -= ScrollHeader_SizeChanged;
headerElement.SizeChanged += ScrollHeader_SizeChanged;

_scrollViewer.GotFocus -= ScrollViewer_GotFocus;
_scrollViewer.GotFocus += ScrollViewer_GotFocus;

var compositor = _scrollProperties.Compositor;

if (_animationProperties is null)
Expand Down Expand Up @@ -202,9 +199,6 @@ private void RemoveAnimation()
if (HeaderElement is FrameworkElement element)
element.SizeChanged -= ScrollHeader_SizeChanged;

if (_scrollViewer is not null)
_scrollViewer.GotFocus -= ScrollViewer_GotFocus;

StopAnimation();
}

Expand All @@ -231,38 +225,5 @@ private void ScrollHeader_SizeChanged(object sender, SizeChangedEventArgs e)
{
AssignAnimation();
}

private void ScrollViewer_GotFocus(object sender, RoutedEventArgs e)
{
var scroller = (ScrollViewer)sender;

object focusedElement;

if (IsXamlRootAvailable && scroller.XamlRoot is not null)
{
focusedElement = FocusManager.GetFocusedElement(scroller.XamlRoot);
}
else
{
focusedElement = FocusManager.GetFocusedElement();
}

// To prevent Popups (Flyouts...) from triggering the autoscroll, we check if the focused element has a valid parent.
// Popups have no parents, whereas a normal Item would have the ListView as a parent.
if (focusedElement is UIElement element && VisualTreeHelper.GetParent(element) is not null)
{
// NOTE: Ignore if element is child of header
if (!element.FindAscendants().Any(x => x == HeaderElement))
{
FrameworkElement header = (FrameworkElement)HeaderElement;

var point = element.TransformToVisual(scroller).TransformPoint(new Point(0, 0));

// NOTE: Do not change scroller horizontal offset
if (point.Y < header.ActualHeight)
scroller.ChangeView(scroller.HorizontalOffset, scroller.VerticalOffset - (header.ActualHeight - point.Y), 1, false);
}
}
}
}
}

0 comments on commit 6025ab3

Please sign in to comment.