Skip to content

Commit

Permalink
fix: DrawerFlyout still displaying the LightDismissOverlayBackground …
Browse files Browse the repository at this point in the history
…after tapping outside
  • Loading branch information
Agnès Zitte committed Jan 19, 2023
1 parent ec3ccea commit f5a3808
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/Uno.Toolkit.UI/Controls/DrawerFlyout/DrawerFlyoutPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public partial class DrawerFlyoutPresenter : ContentControl
// references
private TranslateTransform _drawerContentPresenterTransform;
private Storyboard _storyboard = new Storyboard();
private DoubleAnimation _translateAnimation;
private DoubleAnimation _translateAnimation, _opacityAnimation;
private Popup _popup;

// states
Expand Down Expand Up @@ -101,7 +101,18 @@ protected override void OnApplyTemplate()
ManipulationDelta += OnManipulationDelta;
ManipulationCompleted += OnManipulationCompleted;

_lightDismissOverlay.Tapped += OnLightDismissOverlayTapped;
if (_lightDismissOverlay != null)
{
_opacityAnimation = new DoubleAnimation()
{
Duration = new Duration(AnimationDuration),
};
Storyboard.SetTarget(_opacityAnimation, _lightDismissOverlay);
Storyboard.SetTargetProperty(_opacityAnimation, nameof(_lightDismissOverlay.Opacity));
_storyboard.Children.Add(_opacityAnimation);

_lightDismissOverlay.Tapped += OnLightDismissOverlayTapped;
}

#if HAS_UNO // uno: the visual tree parent is not set, until Loaded.
Loaded += (s, e) =>
Expand Down Expand Up @@ -276,16 +287,23 @@ void UpdateIsOpenWithSuppress(bool value)
private void UpdateOpenness(double ratio)
{
TranslateOffset = (1 - ratio) * GetVectoredLength();

if (_lightDismissOverlay != null)
{
_lightDismissOverlay.Opacity = 1 - ratio;
_lightDismissOverlay.IsHitTestVisible = ratio != 1;
}
}

private void PlayAnimation(double fromRatio, bool willBeOpen)
{
var toRatio = willBeOpen ? 0 : 1;

if (_storyboard == null) return;

if (_translateAnimation != null)
{
var vectoredLength = GetVectoredLength();
var toRatio = willBeOpen ? 0 : 1;

// windows: _drawerContentPresenter is not measured on reopening
// in such case, all numerical values here are invalid
Expand All @@ -312,6 +330,17 @@ private void PlayAnimation(double fromRatio, bool willBeOpen)
_translateAnimation.To = toRatio * vectoredLength;
}

if (_opacityAnimation != null)
{
_opacityAnimation.From = 1 - fromRatio;
_opacityAnimation.To = 1 - toRatio;
}

if (_lightDismissOverlay != null)
{
_lightDismissOverlay.IsHitTestVisible = willBeOpen;
}

_storyboard.Begin();
}

Expand All @@ -326,10 +355,12 @@ private void StopRunningAnimation()
// pause & snapshot the animated values in the middle of animation
_storyboard.Pause();
var offset = TranslateOffset;
var opacity = _lightDismissOverlay?.Opacity ?? default;

// restore the values after stopping it
_storyboard.Stop();
TranslateOffset = offset;
if (_lightDismissOverlay != null) _lightDismissOverlay.Opacity = opacity;
}
}

Expand Down

0 comments on commit f5a3808

Please sign in to comment.