feat: add appear animation.
This commit is contained in:
@@ -92,7 +92,7 @@ public partial class OverlayDialogHost
|
||||
ResetZIndices();
|
||||
}
|
||||
|
||||
private void OnDialogControlClosing(object sender, object? e)
|
||||
private async void OnDialogControlClosing(object sender, object? e)
|
||||
{
|
||||
if (sender is DialogControlBase control)
|
||||
{
|
||||
@@ -109,6 +109,7 @@ public partial class OverlayDialogHost
|
||||
if (_masks.Count > 0)
|
||||
{
|
||||
var last = _masks.Last();
|
||||
await _maskDisappearAnimation.RunAsync(last);
|
||||
this.Children.Remove(last);
|
||||
_masks.Remove(last);
|
||||
if (_masks.Count > 0)
|
||||
@@ -116,6 +117,7 @@ public partial class OverlayDialogHost
|
||||
_masks.Last().IsVisible = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
ResetZIndices();
|
||||
}
|
||||
@@ -143,33 +145,7 @@ public partial class OverlayDialogHost
|
||||
SetToPosition(control);
|
||||
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDialogControlClosing);
|
||||
control.AddHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnDrawerControlClosing(object sender, ResultEventArgs e)
|
||||
{
|
||||
if (sender is DrawerControlBase control)
|
||||
{
|
||||
Children.Remove(control);
|
||||
control.RemoveHandler(CustomDialogControl.ClosedEvent, OnDialogControlClosing);
|
||||
control.RemoveHandler(CustomDialogControl.LayerChangedEvent, OnDialogLayerChanged);
|
||||
if (_modalDialogs.Contains(control))
|
||||
{
|
||||
_modalDialogs.Remove(control);
|
||||
if (_masks.Count > 0)
|
||||
{
|
||||
var last = _masks.Last();
|
||||
this.Children.Remove(last);
|
||||
_masks.Remove(last);
|
||||
if (_masks.Count > 0)
|
||||
{
|
||||
_masks.Last().IsVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ResetZIndices();
|
||||
}
|
||||
_maskAppearAnimation.RunAsync(mask);
|
||||
}
|
||||
|
||||
// Handle dialog layer change event
|
||||
|
||||
@@ -4,6 +4,7 @@ using Avalonia.Animation.Easings;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Styling;
|
||||
using Ursa.Controls.OverlayShared;
|
||||
using Ursa.EventArgs;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
@@ -61,4 +62,29 @@ public partial class OverlayDialogHost
|
||||
animation.Duration = TimeSpan.FromSeconds(0.3);
|
||||
return animation;
|
||||
}
|
||||
|
||||
private void OnDrawerControlClosing(object sender, ResultEventArgs e)
|
||||
{
|
||||
if (sender is DrawerControlBase control)
|
||||
{
|
||||
Children.Remove(control);
|
||||
control.RemoveHandler(OverlayFeedbackElement.ClosedEvent, OnDialogControlClosing);
|
||||
control.RemoveHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
|
||||
if (_modalDialogs.Contains(control))
|
||||
{
|
||||
_modalDialogs.Remove(control);
|
||||
if (_masks.Count > 0)
|
||||
{
|
||||
var last = _masks.Last();
|
||||
this.Children.Remove(last);
|
||||
_masks.Remove(last);
|
||||
if (_masks.Count > 0)
|
||||
{
|
||||
_masks.Last().IsVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ResetZIndices();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Media;
|
||||
using Ursa.Controls.OverlayShared;
|
||||
using Avalonia.Layout;
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
@@ -13,6 +15,28 @@ public partial class OverlayDialogHost: Canvas
|
||||
private readonly List<OverlayFeedbackElement> _dialogs = new();
|
||||
private readonly List<OverlayFeedbackElement> _modalDialogs = new();
|
||||
private readonly List<Border> _masks = new();
|
||||
private static readonly Animation _maskAppearAnimation;
|
||||
private static readonly Animation _maskDisappearAnimation;
|
||||
|
||||
static OverlayDialogHost()
|
||||
{
|
||||
_maskAppearAnimation = CreateOpacityAnimation(true);
|
||||
_maskDisappearAnimation = CreateOpacityAnimation(false);
|
||||
}
|
||||
|
||||
private static Animation CreateOpacityAnimation(bool appear)
|
||||
{
|
||||
var animation = new Animation();
|
||||
animation.FillMode = FillMode.Forward;
|
||||
var keyFrame1 = new KeyFrame(){ Cue = new Cue(0.0) };
|
||||
keyFrame1.Setters.Add(new Setter() { Property = OpacityProperty, Value = appear ? 0.0 : 1.0 });
|
||||
var keyFrame2 = new KeyFrame() { Cue = new Cue(1.0) };
|
||||
keyFrame2.Setters.Add(new Setter() { Property = OpacityProperty, Value = appear ? 1.0 : 0.0 });
|
||||
animation.Children.Add(keyFrame1);
|
||||
animation.Children.Add(keyFrame2);
|
||||
animation.Duration = TimeSpan.FromSeconds(0.3);
|
||||
return animation;
|
||||
}
|
||||
|
||||
public string? HostId { get; set; }
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ namespace Ursa.Controls;
|
||||
|
||||
public class CustomDrawerControl: DrawerControlBase
|
||||
{
|
||||
internal bool IsCloseButtonVisible { get; set; }
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
|
||||
@@ -40,7 +40,7 @@ public const string PART_CloseButton = "PART_CloseButton";
|
||||
|
||||
public static readonly StyledProperty<bool> IsCloseButtonVisibleProperty =
|
||||
AvaloniaProperty.Register<DrawerControlBase, bool>(
|
||||
nameof(IsCloseButtonVisible));
|
||||
nameof(IsCloseButtonVisible), defaultValue: true);
|
||||
|
||||
public bool IsCloseButtonVisible
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user