-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #331 from AvaloniaCommunity/b/borderTransitionsBug
Add mixin for BoxShadow instead of just Border style. #330
- Loading branch information
Showing
4 changed files
with
50 additions
and
21 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
Material.Styles/Assists/Mixins/MaterialBorderBoxShadowMixin.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using Avalonia; | ||
using Avalonia.Animation; | ||
using Avalonia.Controls; | ||
|
||
namespace Material.Styles.Assists.Mixins; | ||
|
||
/// <summary> | ||
/// Adds BoxShadows transitions for any control, which has enabled animations. | ||
/// </summary> | ||
public static class MaterialBorderBoxShadowMixin { | ||
public static BoxShadowsTransition TargetTransition { get; set; } = new() { Property = Border.BoxShadowProperty, Duration = TimeSpan.FromMilliseconds(350) }; | ||
|
||
/// <summary> | ||
/// Initializes BoxShadows transitions for specified control. | ||
/// </summary> | ||
/// <typeparam name="TControl">The control type.</typeparam> | ||
public static void Attach<TControl>() where TControl : Control { | ||
TransitionAssist.DisableTransitionsProperty.Changed.AddClassHandler<TControl>(OnDisableTransitionsChanged); | ||
Animatable.TransitionsProperty.Changed.AddClassHandler<TControl>(OnTransitionCollectionChanged); | ||
} | ||
|
||
private static void OnDisableTransitionsChanged<TControl>(TControl control, AvaloniaPropertyChangedEventArgs args) | ||
where TControl : Control { | ||
var transitions = control.GetValue(Animatable.TransitionsProperty); | ||
if (transitions is null) return; | ||
|
||
var disableTransitions = args.GetNewValue<bool>(); | ||
if (disableTransitions) | ||
transitions.Remove(TargetTransition); | ||
else | ||
transitions.Add(TargetTransition); | ||
} | ||
|
||
private static void OnTransitionCollectionChanged<TControl>(TControl control, AvaloniaPropertyChangedEventArgs args) | ||
where TControl : Control { | ||
var disableTransitions = (bool)control.GetValue(TransitionAssist.DisableTransitionsProperty)!; | ||
if (disableTransitions) return; | ||
|
||
if (args.NewValue is Transitions transitions && !transitions.Contains(TargetTransition)) transitions.Add(TargetTransition); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters