Skip to content

Commit

Permalink
优化切入切出动画
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Jan 23, 2025
1 parent 520c017 commit d1da636
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 13 deletions.
30 changes: 17 additions & 13 deletions WonderLab/Controls/AutoPanelViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using System;
using System.Diagnostics;

namespace WonderLab.Controls;

[PseudoClasses(":press", ":panelopen", ":panelclose", ":panelhide", ":panelshow", ":panelhideopen")]
[PseudoClasses(":press", ":panelopen", ":panelclose", ":panelhide", ":panelshow", ":panelhideopen", ":panelhideclose")]
public sealed class AutoPanelViewer : ContentControl {
private bool _isPress;
private double _startX;
private bool _isHideClose;

Check warning on line 15 in WonderLab/Controls/AutoPanelViewer.cs

View workflow job for this annotation

GitHub Actions / test_build

The field 'AutoPanelViewer._isHideClose' is never used

Check warning on line 15 in WonderLab/Controls/AutoPanelViewer.cs

View workflow job for this annotation

GitHub Actions / build_Linux (arm64)

The field 'AutoPanelViewer._isHideClose' is never used

Check warning on line 15 in WonderLab/Controls/AutoPanelViewer.cs

View workflow job for this annotation

GitHub Actions / build_MacOS

The field 'AutoPanelViewer._isHideClose' is never used

Check warning on line 15 in WonderLab/Controls/AutoPanelViewer.cs

View workflow job for this annotation

GitHub Actions / build_Linux (x64)

The field 'AutoPanelViewer._isHideClose' is never used

Check warning on line 15 in WonderLab/Controls/AutoPanelViewer.cs

View workflow job for this annotation

GitHub Actions / build_Linux (arm)

The field 'AutoPanelViewer._isHideClose' is never used

Check warning on line 15 in WonderLab/Controls/AutoPanelViewer.cs

View workflow job for this annotation

GitHub Actions / build_Windows

The field 'AutoPanelViewer._isHideClose' is never used
private bool _canOpenPanel;
private Border _PART_LayoutBorder;

Expand Down Expand Up @@ -46,13 +48,14 @@ public double PanelHeight {
set => SetValue(PanelHeightProperty, value);
}

private void SetPseudoclasses(bool isPress, bool isPanelOpen, bool isPanelClose, bool isPanelHide, bool isPanelShow, bool isPanelHideOpen) {
private void SetPseudoclasses(bool isPress, bool isPanelOpen, bool isPanelClose, bool isPanelHide, bool isPanelShow, bool isPanelHideOpen, bool isPanelHideClose) {
PseudoClasses.Set(":press", isPress);
PseudoClasses.Set(":panelopen", isPanelOpen);
PseudoClasses.Set(":panelclose", isPanelClose);
PseudoClasses.Set(":panelhide", isPanelHide);
PseudoClasses.Set(":panelshow", isPanelShow);
PseudoClasses.Set(":panelhideopen", isPanelHideOpen);
PseudoClasses.Set(":panelhideclose", isPanelHideClose);
}

private void OnLayoutPointerMoved(object sender, PointerEventArgs e) {
Expand All @@ -77,7 +80,7 @@ private void OnLayoutPointerReleased(object sender, PointerReleasedEventArgs e)
return;
}

SetPseudoclasses(_isPress = false, false, false, false, false, false);
SetPseudoclasses(_isPress = false, false, false, false, false, false, false);
if (e.InitialPressMouseButton is MouseButton.Left) {
_PART_LayoutBorder.Margin = new Thickness(0, 0, 0, 0);

Expand All @@ -93,7 +96,7 @@ private void OnLayoutPointerPressed(object sender, PointerPressedEventArgs e) {
return;
}

SetPseudoclasses(_isPress = true, false, false, false, false, false);
SetPseudoclasses(_isPress = true, false, false, false, false, false, false);
if (e.GetCurrentPoint(_PART_LayoutBorder).Properties.IsLeftButtonPressed) {
_startX = e.GetPosition(this).X;
}
Expand Down Expand Up @@ -128,30 +131,31 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) {
});
}

protected override async void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) {
base.OnPropertyChanged(change);

if (change.Property == IsOpenPanelProperty) {
if (IsOpenPanel && IsHidePanel) {
IsHidePanel = false;
SetPseudoclasses(_isPress, false, false, false, false, true);
SetPseudoclasses(_isPress, false, false, false, false, true, false);
return;
}else if (!IsOpenPanel && IsHidePanel) {
return;
}

SetPseudoclasses(_isPress, IsOpenPanel, !IsOpenPanel, false, false, false);
SetPseudoclasses(_isPress, IsOpenPanel, !IsOpenPanel, false, false, false, false);

}

if (change.Property == IsHidePanelProperty) {
//if (IsOpenPanel && IsHidePanel) {
// IsOpenPanel = false;
// await Task.Delay(TimeSpan.FromSeconds(0.75d));
//}
if (!IsHidePanel && IsOpenPanel) {
if (IsHidePanel && IsOpenPanel) {
IsOpenPanel = false;
SetPseudoclasses(_isPress, false, false, false, false, false, true);
return;
}


SetPseudoclasses(_isPress, false, false, IsHidePanel, !IsHidePanel, false);
SetPseudoclasses(_isPress, false, false, IsHidePanel, !IsHidePanel, false, false);
}
}
}
53 changes: 53 additions & 0 deletions WonderLab/Controls/Theme/AutoPanelViewer.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,58 @@
</Animation>
</Style.Animations>
</Style>

<Style Selector="^:panelhideclose /template/ ContentPresenter#PART_ContentPresenter">
<Style.Animations>
<Animation Delay="0:0:0.1"
Duration="0:0:.55"
FillMode="Forward"
Easing="ExponentialEaseInOut">
<KeyFrame Cue="0%">
<Setter Property="Opacity" Value="1"/>
</KeyFrame>

<KeyFrame Cue="100%">
<Setter Property="Opacity" Value="0"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>

<Style Selector="^:panelhideclose /template/ Border#PART_LayoutBorder">
<Style.Animations>
<Animation Duration="0:0:.85"
FillMode="Forward">
<KeyFrame Cue="0%" KeySpline="0.34, 1.56, 0.64, 1">
<Setter Property="Width" Value="440"/>
<Setter Property="CornerRadius" Value="12"/>
<Setter Property="Height" Value="{Binding $parent[Panel].Bounds.Height}"/>
</KeyFrame>

<KeyFrame Cue="30%" KeySpline="0.34, 1.26, 0.64, 1">
<Setter Property="Width" Value="450"/>
<Setter Property="Height" Value="{Binding $parent[Panel].Bounds.Height, Converter={StaticResource BackEaseValueConverter}, ConverterParameter=10}"/>
<Setter Property="TranslateTransform.X" Value="-16"/>
</KeyFrame>

<KeyFrame Cue="60%" KeySpline="0.55, 0, 1, 0.45">
<Setter Property="Width" Value="10"/>
<Setter Property="Height" Value="150"/>
<Setter Property="CornerRadius" Value="8"/>

<Setter Property="ScaleTransform.ScaleY" Value="1"/>
</KeyFrame>

<KeyFrame Cue="100%" KeySpline="0.34, 1.26, 0.64, 1">
<Setter Property="Width" Value="10"/>
<Setter Property="Height" Value="150"/>
<Setter Property="CornerRadius" Value="8"/>

<Setter Property="TranslateTransform.X" Value="25"/>
<Setter Property="ScaleTransform.ScaleY" Value="0.75"/>
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</ControlTheme>
</ResourceDictionary>
2 changes: 2 additions & 0 deletions WonderLab/ViewModels/Window/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ private void ChangeActivePage() {
3 => "Setting/Navigation",
_ => PageKey ?? "Home",
};

IsOpenTaskPanel = false;
}

[RelayCommand]
Expand Down

0 comments on commit d1da636

Please sign in to comment.