Browse Source

Merge pull request #4165 from rstm-sf/bugfix/skip_ISolidColorBrush

Fix skip convert ISolidColorBrush to Color when animation
pull/4168/head
Jumar Macato 6 years ago
committed by GitHub
parent
commit
cb295f782c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 61
      src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs

61
src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs

@ -1,6 +1,5 @@
using System; using System;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using Avalonia.Logging;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Media.Immutable; using Avalonia.Media.Immutable;
@ -11,9 +10,9 @@ namespace Avalonia.Animation.Animators
/// </summary> /// </summary>
public class SolidColorBrushAnimator : Animator<SolidColorBrush> public class SolidColorBrushAnimator : Animator<SolidColorBrush>
{ {
ColorAnimator _colorAnimator; private ColorAnimator _colorAnimator;
void InitializeColorAnimator() private void InitializeColorAnimator()
{ {
_colorAnimator = new ColorAnimator(); _colorAnimator = new ColorAnimator();
@ -27,46 +26,44 @@ namespace Avalonia.Animation.Animators
public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> match, Action onComplete) public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> match, Action onComplete)
{ {
// Preprocess keyframe values to Color if the xaml parser converts them to ISCB.
foreach (var keyframe in this) foreach (var keyframe in this)
{ {
if (keyframe.Value as ISolidColorBrush == null) if (keyframe.Value is ISolidColorBrush colorBrush)
return Disposable.Empty;
// Preprocess keyframe values to Color if the xaml parser converts them to ISCB.
if (keyframe.Value.GetType() == typeof(ImmutableSolidColorBrush))
{ {
keyframe.Value = ((ImmutableSolidColorBrush)keyframe.Value).Color; keyframe.Value = colorBrush.Color;
}
else
{
return Disposable.Empty;
} }
} }
// Add SCB if the target prop is empty. SolidColorBrush finalTarget;
if (control.GetValue(Property) == null)
control.SetValue(Property, new SolidColorBrush(Colors.Transparent));
var targetVal = control.GetValue(Property); var targetVal = control.GetValue(Property);
if (targetVal is null)
// Continue if target prop is not empty & is a SolidColorBrush derivative. {
if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType())) finalTarget = new SolidColorBrush(Colors.Transparent);
control.SetValue(Property, finalTarget);
}
else if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush)
{
finalTarget = new SolidColorBrush(immutableSolidColorBrush.Color);
control.SetValue(Property, finalTarget);
}
else if (targetVal is ISolidColorBrush)
{ {
if (_colorAnimator == null)
InitializeColorAnimator();
SolidColorBrush finalTarget;
// If it's ISCB, change it back to SCB.
if (targetVal.GetType() == typeof(ImmutableSolidColorBrush))
{
var col = (ImmutableSolidColorBrush)targetVal;
targetVal = new SolidColorBrush(col.Color);
control.SetValue(Property, targetVal);
}
finalTarget = targetVal as SolidColorBrush; finalTarget = targetVal as SolidColorBrush;
return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete);
} }
else
{
return Disposable.Empty;
}
if (_colorAnimator == null)
InitializeColorAnimator();
return Disposable.Empty; return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete);
} }
public override SolidColorBrush Interpolate(double p, SolidColorBrush o, SolidColorBrush n) => null; public override SolidColorBrush Interpolate(double p, SolidColorBrush o, SolidColorBrush n) => null;

Loading…
Cancel
Save