Ver Fonte

Fix nits :)

Jumar Macato há 6 anos atrás
pai
commit
6b025bb9a9

+ 4 - 4
src/Avalonia.Animation/Animation.cs

@@ -175,18 +175,18 @@ namespace Avalonia.Animation
         }
 
         /// <summary>
-        /// Obselete: Do not use this property, use <see cref="IterationCount"/> instead.
+        /// Obsolete: Do not use this property, use <see cref="IterationCount"/> instead.
         /// </summary>
         /// <value></value>
-        [Obsolete]
+        [Obsolete("This property has been superceded by IterationCount.")]
         public string RepeatCount
         {
             get { return IterationCount.ToString(); }
             set
             {
                 var val = value.ToUpper();
-                val = val .Replace("LOOP", "INFINITE");
-                val = val .Replace("NONE", "1");
+                val = val.Replace("LOOP", "INFINITE");
+                val = val.Replace("NONE", "1");
                 IterationCount = IterationCount.Parse(val);
             }
         }

+ 25 - 10
src/Avalonia.Animation/AnimationInstance`1.cs

@@ -20,7 +20,7 @@ namespace Avalonia.Animation
         private ulong _currentIteration;
         private bool _gotFirstKFValue;
         private FillMode _fillMode;
-        private PlaybackDirection _animationDirection;
+        private PlaybackDirection _playbackDirection;
         private Animator<T> _animator;
         private Animation _animation;
         private Animatable _targetControl;
@@ -53,7 +53,7 @@ namespace Avalonia.Animation
         {
             if (_animation.SpeedRatio < 0d)
                 throw new ArgumentOutOfRangeException("SpeedRatio value should not be negative.");
-                
+
             if (_animation.Duration.TotalSeconds <= 0)
                 throw new InvalidOperationException("Duration value cannot be negative or zero.");
 
@@ -70,7 +70,7 @@ namespace Avalonia.Animation
             else
                 _iterationCount = null;
 
-            _animationDirection = _animation.PlaybackDirection;
+            _playbackDirection = _animation.PlaybackDirection;
             _fillMode = _animation.FillMode;
         }
 
@@ -169,13 +169,28 @@ namespace Avalonia.Animation
                     // Normalize time for interpolation.
                     var normalizedTime = playbackTime / iterDuration;
 
-                    // Check if normalized time needs to be reversed.
-                    bool isCurIterReverse = _animationDirection == PlaybackDirection.Normal ? false :
-                                            _animationDirection == PlaybackDirection.Alternate ? (_currentIteration % 2 == 0) ? false : true :
-                                            _animationDirection == PlaybackDirection.AlternateReverse ? (_currentIteration % 2 == 0) ? true : false :
-                                            _animationDirection == PlaybackDirection.Reverse ? true : false;
+                    // Check if normalized time needs to be reversed according to PlaybackDirection
                     
-                    if (isCurIterReverse)
+                    bool playbackReversed;
+                    switch (_playbackDirection)
+                    {
+                        case PlaybackDirection.Normal:
+                            playbackReversed = false;
+                            break;
+                        case PlaybackDirection.Reverse:
+                            playbackReversed = true;
+                            break;
+                        case PlaybackDirection.Alternate:
+                            playbackReversed = (_currentIteration % 2 == 0) ? false : true;
+                            break;
+                        case PlaybackDirection.AlternateReverse:
+                            playbackReversed = (_currentIteration % 2 == 0) ? true : false;
+                            break;
+                        default:
+                            throw new InvalidOperationException($"Animation direction value is unknown: {_playbackDirection}");
+                    }
+
+                    if (playbackReversed)
                         normalizedTime = 1 - normalizedTime;
 
                     // Ease and interpolate
@@ -197,4 +212,4 @@ namespace Avalonia.Animation
             }
         }
     }
-}
+}

+ 1 - 1
src/Avalonia.Animation/Animators/ByteAnimator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class ByteAnimator : Animator<byte>
     {
-        static double maxVal = (double)byte.MaxValue;
+        const double maxVal = (double)byte.MaxValue;
 
         /// <inheritdocs/>
         public override byte Interpolate(double progress, byte oldValue, byte newValue)

+ 1 - 1
src/Avalonia.Animation/Animators/FloatAnimator.cs

@@ -11,7 +11,7 @@ namespace Avalonia.Animation.Animators
         /// <inheritdocs/>
         public override float Interpolate(double progress, float oldValue, float newValue)
         {
-            return ((newValue - oldValue) * (float)progress) + oldValue;
+            return (float)(((newValue - oldValue) * progress) + oldValue);
         }
     }
 }

+ 1 - 1
src/Avalonia.Animation/Animators/Int16Animator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class Int16Animator : Animator<Int16>
     {
-        static double maxVal = (double)Int16.MaxValue;
+        const double maxVal = (double)Int16.MaxValue;
 
         /// <inheritdocs/>
         public override Int16 Interpolate(double progress, Int16 oldValue, Int16 newValue)

+ 1 - 1
src/Avalonia.Animation/Animators/Int32Animator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class Int32Animator : Animator<Int32>
     {
-        static double maxVal = (double)Int32.MaxValue;
+        const double maxVal = (double)Int32.MaxValue;
 
         /// <inheritdocs/>
         public override Int32 Interpolate(double progress, Int32 oldValue, Int32 newValue)

+ 1 - 1
src/Avalonia.Animation/Animators/Int64Animator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class Int64Animator : Animator<Int64>
     {
-        static double maxVal = (double)Int64.MaxValue;
+        const double maxVal = (double)Int64.MaxValue;
 
         /// <inheritdocs/>
         public override Int64 Interpolate(double progress, Int64 oldValue, Int64 newValue)

+ 1 - 1
src/Avalonia.Animation/Animators/UInt16Animator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class UInt16Animator : Animator<UInt16>
     {
-        static double maxVal = (double)UInt16.MaxValue;
+        const double maxVal = (double)UInt16.MaxValue;
 
         /// <inheritdocs/>
         public override UInt16 Interpolate(double progress, UInt16 oldValue, UInt16 newValue)

+ 1 - 1
src/Avalonia.Animation/Animators/UInt32Animator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class UInt32Animator : Animator<UInt32>
     {
-        static double maxVal = (double)UInt32.MaxValue;
+        const double maxVal = (double)UInt32.MaxValue;
 
         /// <inheritdocs/>
         public override UInt32 Interpolate(double progress, UInt32 oldValue, UInt32 newValue)

+ 1 - 1
src/Avalonia.Animation/Animators/UInt64Animator.cs

@@ -10,7 +10,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class UInt64Animator : Animator<UInt64>
     {
-        static double maxVal = (double)UInt64.MaxValue;
+        const double maxVal = (double)UInt64.MaxValue;
 
         /// <inheritdocs/>
         public override UInt64 Interpolate(double progress, UInt64 oldValue, UInt64 newValue)

+ 6 - 6
src/Avalonia.Visuals/Animation/Animators/SolidColorBrushAnimator.cs

@@ -11,18 +11,18 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class SolidColorBrushAnimator : Animator<SolidColorBrush>
     {
-        ColorAnimator colorAnimator;
+        ColorAnimator _colorAnimator;
 
         void InitializeColorAnimator()
         {
-            colorAnimator = new ColorAnimator();
+            _colorAnimator = new ColorAnimator();
 
             foreach (AnimatorKeyFrame keyframe in this)
             {
-                colorAnimator.Add(keyframe);
+                _colorAnimator.Add(keyframe);
             }
 
-            colorAnimator.Property = SolidColorBrush.ColorProperty;
+            _colorAnimator.Property = SolidColorBrush.ColorProperty;
         }
 
         public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> match, Action onComplete)
@@ -48,7 +48,7 @@ namespace Avalonia.Animation.Animators
             // Continue if target prop is not empty & is a SolidColorBrush derivative. 
             if (typeof(ISolidColorBrush).IsAssignableFrom(targetVal.GetType()))
             {
-                if (colorAnimator == null)
+                if (_colorAnimator == null)
                     InitializeColorAnimator();
 
                 SolidColorBrush finalTarget;
@@ -63,7 +63,7 @@ namespace Avalonia.Animation.Animators
 
                 finalTarget = targetVal as SolidColorBrush;
 
-                return colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete);
+                return _colorAnimator.Apply(animation, finalTarget, clock ?? control.Clock, match, onComplete);
             }
 
             return Disposable.Empty;

+ 14 - 19
src/Avalonia.Visuals/Animation/Animators/TransformAnimator.cs

@@ -9,7 +9,7 @@ namespace Avalonia.Animation.Animators
     /// </summary>
     public class TransformAnimator : Animator<double>
     {
-        DoubleAnimator childAnimator;
+        DoubleAnimator _doubleAnimator;
 
         /// <inheritdoc/>
         public override IDisposable Apply(Animation animation, Animatable control, IClock clock, IObservable<bool> obsMatch, Action onComplete)
@@ -27,7 +27,7 @@ namespace Avalonia.Animation.Animators
                     // default RenderTransform order.
 
                     normalTransform.Children.Add(new ScaleTransform());
-                    normalTransform.Children.Add(new SkewTransform()); 
+                    normalTransform.Children.Add(new SkewTransform());
                     normalTransform.Children.Add(new RotateTransform());
                     normalTransform.Children.Add(new TranslateTransform());
 
@@ -36,15 +36,22 @@ namespace Avalonia.Animation.Animators
 
                 var renderTransformType = ctrl.RenderTransform.GetType();
 
-                if (childAnimator == null)
+                if (_doubleAnimator == null)
                 {
-                    InitializeChildAnimator();
+                    _doubleAnimator = new DoubleAnimator();
+
+                    foreach (AnimatorKeyFrame keyframe in this)
+                    {
+                        _doubleAnimator.Add(keyframe);
+                    }
+
+                    _doubleAnimator.Property = Property;
                 }
 
                 // It's a transform object so let's target that.
                 if (renderTransformType == Property.OwnerType)
                 {
-                    return childAnimator.Apply(animation, ctrl.RenderTransform, clock ?? control.Clock, obsMatch, onComplete);
+                    return _doubleAnimator.Apply(animation, ctrl.RenderTransform, clock ?? control.Clock, obsMatch, onComplete);
                 }
                 // It's a TransformGroup and try finding the target there.
                 else if (renderTransformType == typeof(TransformGroup))
@@ -53,7 +60,7 @@ namespace Avalonia.Animation.Animators
                     {
                         if (transform.GetType() == Property.OwnerType)
                         {
-                            return childAnimator.Apply(animation, transform, clock ?? control.Clock, obsMatch, onComplete);
+                            return _doubleAnimator.Apply(animation, transform, clock ?? control.Clock, obsMatch, onComplete);
                         }
                     }
                 }
@@ -75,17 +82,5 @@ namespace Avalonia.Animation.Animators
 
         /// <inheritdocs/> 
         public override double Interpolate(double p, double o, double n) => 0;
-
-        void InitializeChildAnimator()
-        {
-            childAnimator = new DoubleAnimator();
-
-            foreach (AnimatorKeyFrame keyframe in this)
-            {
-                childAnimator.Add(keyframe);
-            }
-
-            childAnimator.Property = Property;
-        }
     }
-}
+}

+ 6 - 4
tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs

@@ -18,15 +18,17 @@ namespace Avalonia.Animation.UnitTests
         {
             var keyframe1 = new KeyFrame()
             {
-                Setters = {
+                Setters =
+                {
                     new Setter(Border.WidthProperty, 200d),
                 },
                 Cue = new Cue(1d)
             };
-  
+
             var keyframe2 = new KeyFrame()
             {
-                Setters = {
+                Setters =
+                {
                     new Setter(Border.WidthProperty, 100d),
                 },
                 Cue = new Cue(0d)
@@ -72,4 +74,4 @@ namespace Avalonia.Animation.UnitTests
             Assert.Equal(border.Width, 100d);
         }
     }
-}
+}