refactor(Spin): migrate AbstractSpin transitions to XAML theme

This commit is contained in:
chinboy
2026-04-19 22:39:30 +08:00
parent 8a694ba36a
commit d29cfa2154
3 changed files with 10 additions and 39 deletions
+2 -1
View File
@@ -95,7 +95,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
| 3 | ~~Switch/AbstractToggleSwitch.cs~~ | ~~KnobMovingRect(Rect), OnContentOffset(Point), OffContentOffset(Point), GrooveBackground(SolidColorBrush), SwitchOpacity(Double)~~ | ✅ |
| 4 | ~~Switch/SwitchKnob.cs~~ | ~~Background(SolidColorBrush), Width(Double), Height(Double)~~ | ✅ |
| 5 | ~~ProgressBar/AbstractProgressBar.cs~~ | ~~Background(SolidColorBrush), IndicatorBarBrush(SolidColorBrush)~~ | ✅ |
| 6 | Spin/AbstractSpin.cs | DotBrush(SolidColorBrush) | |
| 6 | ~~Spin/AbstractSpin.cs~~ | ~~DotBrush(SolidColorBrush)~~ | ✅ |
| 7 | CheckBox/Converters/CheckBoxIndicator.cs | Background(SolidColorBrush), BorderBrush(SolidColorBrush) | |
| 8 | Segmented/AbstractSegmented.cs | Background(SolidColorBrush) | |
| 9 | Segmented/AbstractSegmentedItem.cs | Background(SolidColorBrush), Foreground(SolidColorBrush) | |
@@ -226,6 +226,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
- [ ] 第 1 批:AtomUI.Controls 基础控件(16 个)
- [x] 4 | Switch/SwitchKnob.cs | Background(SolidColorBrush), Width(Double), Height(Double) | ✅ 已完成
- [x] 5 | ProgressBar/AbstractProgressBar.cs | Background(SolidColorBrush), IndicatorBarBrush(SolidColorBrush) | ✅ 已完成
- [x] 6 | Spin/AbstractSpin.cs | DotBrush(SolidColorBrush) | ✅ 已完成
- [ ] 第 2 批:AtomUI.Desktop.Controls Part A(19 个)
- [ ] 第 3 批:AtomUI.Desktop.Controls Part B(18 个)
- [ ] 第 4 批:AtomUI.Desktop.Controls Part C(17 个)
-38
View File
@@ -1,10 +1,8 @@
using Avalonia;
using Avalonia.Animation;
using Avalonia.Animation.Easings;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Templates;
using Avalonia.Interactivity;
using Avalonia.Metadata;
namespace AtomUI.Controls.Commons;
@@ -149,13 +147,6 @@ public abstract class AbstractSpin : ContentControl, IMotionAwareControl
{
SetCurrentValue(IsCustomIndicatorProperty, CustomIndicator != null || CustomIndicatorTemplate != null);
}
if (IsLoaded)
{
if (change.Property == IsMotionEnabledProperty)
{
ConfigureTransitions(true);
}
}
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
@@ -163,33 +154,4 @@ public abstract class AbstractSpin : ContentControl, IMotionAwareControl
base.OnApplyTemplate(e);
SetCurrentValue(IsCustomIndicatorProperty, CustomIndicator != null || CustomIndicatorTemplate != null);
}
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<DoubleTransition>(MaskOpacityProperty)
];
}
}
else
{
Transitions = null;
}
}
}
@@ -50,6 +50,14 @@
<Setter Property="IsMotionEnabled" Value="{atom:SharedTokenResource EnableMotion}" />
<Setter Property="MotionDuration"
Value="{atom:SpinTokenResource IndicatorDuration}" />
<Style Selector="^[IsMotionEnabled=True]">
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="MaskOpacity" Duration="{atom:SharedTokenResourceValue Kind=MotionDurationMid}" />
</Transitions>
</Setter>
</Style>
<Style Selector="^ /template/ atom|TextBlock#Tip">
<Setter Property="Foreground" Value="{atom:SharedTokenResource ColorPrimary}" />
</Style>