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

fix(drawerflyout): empty flyout in certain situation #928

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading