Skip to content

Commit

Permalink
Fix Sidebar animation not being smooth when sections are sufficiently…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelwgn authored Dec 10, 2023
1 parent d83ee09 commit d638827
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/Files.App/UserControls/SideBar/SideBarItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ private void SidebarItem_Loaded(object sender, RoutedEventArgs e)
{
childrenRepeater = repeater;
repeater.ElementPrepared += ChildrenPresenter_ElementPrepared;
repeater.SizeChanged += ChildrenPresenter_SizeChanged;
}
if (GetTemplateChild("FlyoutChildrenPresenter") is ItemsRepeater flyoutRepeater)
{
Expand All @@ -99,14 +98,6 @@ public void HandleItemChange()
Decorator = Item.ItemDecorator;
}

private void ChildrenPresenter_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (e.NewSize.Height > 1)
{
ChildrenPresenterHeight = e.NewSize.Height;
}
}

private void HookupOwners()
{
FrameworkElement resolvingTarget = this;
Expand Down Expand Up @@ -337,12 +328,13 @@ private void UpdateExpansionState(bool useAnimations = true)
}
else
{
if (childrenRepeater != null)
if (Item?.Children is IList enumerable && enumerable.Count > 0 && childrenRepeater is not null)
{
if (childrenRepeater.ActualHeight > ChildrenPresenterHeight)
{
ChildrenPresenterHeight = childrenRepeater.ActualHeight;
}
var firstChild = childrenRepeater.GetOrCreateElement(0);

// Collapsed elements might have a desired size of 0 so we need to have a sensible fallback
var childHeight = firstChild.DesiredSize.Height > 0 ? firstChild.DesiredSize.Height : 32;
ChildrenPresenterHeight = enumerable.Count * childHeight;
}
VisualStateManager.GoToState(this, IsExpanded ? "Expanded" : "Collapsed", useAnimations);
VisualStateManager.GoToState(this, IsExpanded ? "ExpandedIconNormal" : "CollapsedIconNormal", useAnimations);
Expand Down

0 comments on commit d638827

Please sign in to comment.