mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-29 15:19:12 +08:00
refactor(ToggleIconButton): migrate transitions to XAML theme
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
using AtomUI.Animations;
|
||||
using Avalonia;
|
||||
using Avalonia.Animation;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Media;
|
||||
|
||||
namespace AtomUI.Controls.Commons;
|
||||
@@ -124,53 +121,4 @@ public abstract class AbstractToggleIconButton : ToggleButton, IMotionAwareContr
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
{
|
||||
base.OnPropertyChanged(change);
|
||||
|
||||
if (IsLoaded)
|
||||
{
|
||||
if (change.Property == IsMotionEnabledProperty)
|
||||
{
|
||||
ConfigureTransitions(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnLoaded(e);
|
||||
ConfigureTransitions(false);
|
||||
}
|
||||
|
||||
protected override void OnUnloaded(RoutedEventArgs e)
|
||||
{
|
||||
base.OnUnloaded(e);
|
||||
Transitions = null;
|
||||
}
|
||||
|
||||
private void ConfigureTransitions(bool force)
|
||||
{
|
||||
if (IsMotionEnabled)
|
||||
{
|
||||
if (force || Transitions == null)
|
||||
{
|
||||
Transitions =
|
||||
[
|
||||
TransitionUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty),
|
||||
TransitionUtils.CreateTransition<TransformOperationsTransition>(RenderTransformProperty)
|
||||
];
|
||||
NotifyConfigureTransitions(Transitions);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Transitions = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void NotifyConfigureTransitions(Transitions transitions)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,15 @@
|
||||
<Setter Property="IconBrush"
|
||||
Value="{atom:SharedTokenResource ColorIcon}" />
|
||||
|
||||
<Style Selector="^[IsMotionEnabled=True]">
|
||||
<Setter Property="Transitions">
|
||||
<Transitions>
|
||||
<atom:SolidColorBrushTransition Property="Background" Duration="{atom:SharedTokenResourceValue Kind=MotionDurationMid}" />
|
||||
<TransformOperationsTransition Property="RenderTransform" Duration="{atom:SharedTokenResourceValue Kind=MotionDurationMid}" />
|
||||
</Transitions>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<Style Selector="^:pointerover">
|
||||
<Setter Property="IconBrush"
|
||||
Value="{atom:SharedTokenResource ColorIconHover}" />
|
||||
|
||||
Reference in New Issue
Block a user