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 still displaying the LightDismissOverlayBackground after tapping outside #453

Merged
merged 1 commit into from
Jan 20, 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
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