Skip to content

Commit

Permalink
fix(drawerflyout): empty flyout in certain situation (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoy312 authored Nov 25, 2023
1 parent edf7200 commit 7681185
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/Uno.Toolkit.UI/Controls/DrawerFlyout/DrawerFlyoutPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public partial class DrawerFlyoutPresenter : ContentControl
private bool _isReady;
private bool _isGestureCaptured;
private bool _initOnceOnLoaded = true;
private bool _initOnceOnLayoutUpdated = true;
private double _startingTranslateOffset;
private bool _suppressIsOpenHandler;

Expand Down Expand Up @@ -95,7 +94,7 @@ T FindTemplatePart<T>(string name) where T : class =>
UpdateTranslateAnimationTargetProperty();
_storyboard.Children.Add(_translateAnimation);

// no point updating size here, as we lack the flyout size that is unknown until LayoutUpdated
// no point updating size here, as we lack the flyout size that is unknown until SizeChanged
UpdateSwipeContentPresenterLayout();
//UpdateSwipeContentPresenterSize();

Expand Down Expand Up @@ -141,33 +140,28 @@ T FindTemplatePart<T>(string name) where T : class =>
// note: by the time we got here, the popup would be already opened, thus we will miss the first opened event.
// in order to catch it, we use LayoutUpdated; Loaded event cannot be used here, as the _drawerContentPresenter
// still don't have its Actual(Width|Height) set which are needed for changing the position.
LayoutUpdated += OnLayoutUpdated;
SizeChanged += OnSizeChanged;

_isReady = true;
}

private void DrawerContentPresenterSizeChanged(object sender, SizeChangedEventArgs e)
private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
_lastMeasuredFlyoutContentSize = e.NewSize;
if (!HasConcreteActualSize()) return;

UpdateSwipeContentPresenterLayout();
UpdateSwipeContentPresenterSize();
}

private void OnLayoutUpdated(object sender, object e)
private void DrawerContentPresenterSizeChanged(object sender, SizeChangedEventArgs e)
{
if (_initOnceOnLayoutUpdated)
{
_initOnceOnLayoutUpdated = false;

UpdateSwipeContentPresenterLayout();
UpdateSwipeContentPresenterSize();

// reset to close position, and animate to open position
UpdateOpenness(false);
UpdateIsOpen(true, animate: true);
}
_lastMeasuredFlyoutContentSize = e.NewSize;
}

private void OnPopupOpened(object sender, object e)
{
if (!HasConcreteActualSize()) return;

// reset to close position, and animate to open position
UpdateOpenness(false);
UpdateIsOpen(true, animate: true);
Expand Down Expand Up @@ -199,6 +193,7 @@ private void OnOpenDirectionChanged(DependencyPropertyChangedEventArgs e)

StopRunningAnimation();
UpdateSwipeContentPresenterLayout();
UpdateSwipeContentPresenterSize();
UpdateManipulationMode();
UpdateTranslateAnimationTargetProperty();
ResetOtherAxisTranslateOffset();
Expand Down Expand Up @@ -508,6 +503,8 @@ private bool UseNegativeTranslation()
};
}

private bool HasConcreteActualSize() => ActualWidth > 0 && ActualHeight > 0;

private double GetActualDrawerLength()
{
if (_drawerContentPresenter == null) throw new InvalidOperationException($"{nameof(_drawerContentPresenter)} is null");
Expand Down

0 comments on commit 7681185

Please sign in to comment.