From 4aaa48739cee611d1f9458eec67c1c93623d7e46 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Wed, 24 Jun 2020 20:36:58 +0500 Subject: [PATCH 1/7] Fix skip ISolidColorBrush when animation --- .../Animation/Animators/SolidColorBrushAnimator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 8776d3a7b7..8f0b710f63 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -29,13 +29,13 @@ namespace Avalonia.Animation.Animators { foreach (var keyframe in this) { - if (keyframe.Value as ISolidColorBrush == null) + if (!(keyframe.Value is ISolidColorBrush)) return Disposable.Empty; // Preprocess keyframe values to Color if the xaml parser converts them to ISCB. - if (keyframe.Value.GetType() == typeof(ImmutableSolidColorBrush)) + if (keyframe.Value is ISolidColorBrush colorBrush) { - keyframe.Value = ((ImmutableSolidColorBrush)keyframe.Value).Color; + keyframe.Value = colorBrush.Color; } } From be4f4ed1c2d5d34b6bf52b095cf9f6036fa52648 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Wed, 24 Jun 2020 20:49:25 +0500 Subject: [PATCH 2/7] Fix using pattern matching --- .../Animation/Animators/SolidColorBrushAnimator.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 8f0b710f63..d60542a6b4 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -51,17 +51,14 @@ namespace Avalonia.Animation.Animators if (_colorAnimator == null) InitializeColorAnimator(); - SolidColorBrush finalTarget; - // If it's ISCB, change it back to SCB. - if (targetVal.GetType() == typeof(ImmutableSolidColorBrush)) + if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush) { - var col = (ImmutableSolidColorBrush)targetVal; - targetVal = new SolidColorBrush(col.Color); + targetVal = new SolidColorBrush(immutableSolidColorBrush.Color); control.SetValue(Property, targetVal); } - finalTarget = targetVal as SolidColorBrush; + var finalTarget = targetVal as SolidColorBrush; return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete); } From c0d192a8f63d704e097eb3880e9c87617380d6f1 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Wed, 24 Jun 2020 23:57:56 +0500 Subject: [PATCH 3/7] Rewrite getting targetVal --- .../Animation/Animators/SolidColorBrushAnimator.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index d60542a6b4..9c8f72fe88 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -1,6 +1,5 @@ using System; using System.Reactive.Disposables; -using Avalonia.Logging; using Avalonia.Media; using Avalonia.Media.Immutable; @@ -39,11 +38,13 @@ namespace Avalonia.Animation.Animators } } - // Add SCB if the target prop is empty. - if (control.GetValue(Property) == null) - control.SetValue(Property, new SolidColorBrush(Colors.Transparent)); - var targetVal = control.GetValue(Property); + // Add SCB if the target prop is empty. + if (targetVal is null) + { + targetVal = new SolidColorBrush(Colors.Transparent); + control.SetValue(Property, targetVal); + } // Continue if target prop is not empty & is a SolidColorBrush derivative. if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType())) From 3157dbd13335a42c6dd6c753d000d44d8c6f3247 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Thu, 25 Jun 2020 00:05:23 +0500 Subject: [PATCH 4/7] Rewrite condition by if not ISolidColorBrush --- .../Animators/SolidColorBrushAnimator.cs | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 9c8f72fe88..191c9631b7 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -46,25 +46,22 @@ namespace Avalonia.Animation.Animators control.SetValue(Property, targetVal); } - // Continue if target prop is not empty & is a SolidColorBrush derivative. - if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType())) - { - if (_colorAnimator == null) - InitializeColorAnimator(); - - // If it's ISCB, change it back to SCB. - if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush) - { - targetVal = new SolidColorBrush(immutableSolidColorBrush.Color); - control.SetValue(Property, targetVal); - } + if (!(targetVal is ISolidColorBrush)) + return Disposable.Empty; - var finalTarget = targetVal as SolidColorBrush; + if (_colorAnimator == null) + InitializeColorAnimator(); - return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete); + // If it's ISCB, change it back to SCB. + if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush) + { + targetVal = new SolidColorBrush(immutableSolidColorBrush.Color); + control.SetValue(Property, targetVal); } - return Disposable.Empty; + var finalTarget = targetVal as SolidColorBrush; + + return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete); } public override SolidColorBrush Interpolate(double p, SolidColorBrush o, SolidColorBrush n) => null; From d7c3c03ccfefae01042662eb50fd9815a0362ba2 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Thu, 25 Jun 2020 00:14:55 +0500 Subject: [PATCH 5/7] Rewrite check targetVal --- .../Animators/SolidColorBrushAnimator.cs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 191c9631b7..8f3abcf068 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -10,9 +10,9 @@ namespace Avalonia.Animation.Animators /// public class SolidColorBrushAnimator : Animator { - ColorAnimator _colorAnimator; + private ColorAnimator _colorAnimator; - void InitializeColorAnimator() + private void InitializeColorAnimator() { _colorAnimator = new ColorAnimator(); @@ -38,28 +38,29 @@ namespace Avalonia.Animation.Animators } } + SolidColorBrush finalTarget; var targetVal = control.GetValue(Property); - // Add SCB if the target prop is empty. if (targetVal is null) { - targetVal = new SolidColorBrush(Colors.Transparent); - control.SetValue(Property, targetVal); + finalTarget = new SolidColorBrush(Colors.Transparent); + control.SetValue(Property, finalTarget); } - - if (!(targetVal is ISolidColorBrush)) + else if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush) + { + finalTarget = new SolidColorBrush(immutableSolidColorBrush.Color); + control.SetValue(Property, finalTarget); + } + else if (!(targetVal is ISolidColorBrush)) + { return Disposable.Empty; - - if (_colorAnimator == null) - InitializeColorAnimator(); - - // If it's ISCB, change it back to SCB. - if (targetVal is ImmutableSolidColorBrush immutableSolidColorBrush) + } + else { - targetVal = new SolidColorBrush(immutableSolidColorBrush.Color); - control.SetValue(Property, targetVal); + finalTarget = targetVal as SolidColorBrush; } - var finalTarget = targetVal as SolidColorBrush; + if (_colorAnimator == null) + InitializeColorAnimator(); return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete); } From b4b54fe6a3fe69869db97d16b07d99df66a0a113 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Thu, 25 Jun 2020 11:05:30 +0500 Subject: [PATCH 6/7] Swap condition --- .../Animation/Animators/SolidColorBrushAnimator.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 8f3abcf068..9c94823608 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -50,13 +50,13 @@ namespace Avalonia.Animation.Animators finalTarget = new SolidColorBrush(immutableSolidColorBrush.Color); control.SetValue(Property, finalTarget); } - else if (!(targetVal is ISolidColorBrush)) + else if (targetVal is ISolidColorBrush) { - return Disposable.Empty; + finalTarget = targetVal as SolidColorBrush; } else { - finalTarget = targetVal as SolidColorBrush; + return Disposable.Empty; } if (_colorAnimator == null) From 8e7d785419f20f7fd41ef366d6cb282ecf8443d3 Mon Sep 17 00:00:00 2001 From: Rustam Sayfutdinov Date: Thu, 25 Jun 2020 11:12:40 +0500 Subject: [PATCH 7/7] Merge condition --- .../Animation/Animators/SolidColorBrushAnimator.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs index 9c94823608..a8e618af27 100644 --- a/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs +++ b/src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs @@ -26,16 +26,17 @@ namespace Avalonia.Animation.Animators public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable match, Action onComplete) { + // Preprocess keyframe values to Color if the xaml parser converts them to ISCB. foreach (var keyframe in this) { - if (!(keyframe.Value is ISolidColorBrush)) - return Disposable.Empty; - - // Preprocess keyframe values to Color if the xaml parser converts them to ISCB. if (keyframe.Value is ISolidColorBrush colorBrush) { keyframe.Value = colorBrush.Color; } + else + { + return Disposable.Empty; + } } SolidColorBrush finalTarget;