Browse Source

Merge branch 'master' into fixes/3179-cross-root-reparenting

Jumar Macato 6 years ago
parent
commit
3e15465961

+ 1 - 0
src/Avalonia.Animation/Properties/AssemblyInfo.cs

@@ -10,3 +10,4 @@ using System.Runtime.CompilerServices;
 [assembly: XmlnsDefinition("https://github.com/avaloniaui", "Avalonia.Animation.Animators")]
 
 [assembly: InternalsVisibleTo("Avalonia.LeakTests")]
+[assembly: InternalsVisibleTo("Avalonia.Animation.UnitTests")]

+ 1 - 1
src/Avalonia.Animation/TransitionInstance.cs

@@ -28,7 +28,7 @@ namespace Avalonia.Animation
 
         private void TimerTick(TimeSpan t)
         {
-            var interpVal = (double)t.Ticks / _duration.Ticks;
+            var interpVal = _duration.Ticks == 0 ? 1d : (double)t.Ticks / _duration.Ticks;
 
             // Clamp interpolation value.
             if (interpVal >= 1d | interpVal < 0d)

+ 6 - 6
src/Avalonia.Base/ValueStore.cs

@@ -57,7 +57,8 @@ namespace Avalonia
                 {
                     if (priority == (int)BindingPriority.LocalValue)
                     {
-                        _propertyValues.SetValue(property, Validate(property, value));
+                        Validate(property, ref value);
+                        _propertyValues.SetValue(property, value);
                         Changed(property, priority, v, value);
                         return;
                     }
@@ -78,7 +79,8 @@ namespace Avalonia
 
                 if (priority == (int)BindingPriority.LocalValue)
                 {
-                    _propertyValues.AddValue(property, Validate(property, value));
+                    Validate(property, ref value);
+                    _propertyValues.AddValue(property, value);
                     Changed(property, priority, AvaloniaProperty.UnsetValue, value);
                     return;
                 }
@@ -166,16 +168,14 @@ namespace Avalonia
                 validate2);
         }
 
-        private object Validate(AvaloniaProperty property, object value)
+        private void Validate(AvaloniaProperty property, ref object value)
         {
             var validate = ((IStyledPropertyAccessor)property).GetValidationFunc(_owner.GetType());
 
             if (validate != null && value != AvaloniaProperty.UnsetValue)
             {
-                return validate(_owner, value);
+                value = validate(_owner, value);
             }
-
-            return value;
         }
 
         private DeferredSetter<T> GetDeferredSetter<T>(AvaloniaProperty property)

+ 21 - 7
tests/Avalonia.Animation.UnitTests/TransitionsTests.cs

@@ -1,14 +1,7 @@
 using System;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Avalonia.Animation;
 using Avalonia.Controls;
-using Avalonia.Styling;
 using Avalonia.UnitTests;
-using Avalonia.Data;
 using Xunit;
-using Avalonia.Animation.Easings;
 
 namespace Avalonia.Animation.UnitTests
 {
@@ -69,5 +62,26 @@ namespace Avalonia.Animation.UnitTests
                 Assert.Equal(0, border.Opacity);
             }
         }
+
+        [Fact]
+        public void TransitionInstance_With_Zero_Duration_Is_Completed_On_First_Tick()
+        {
+            var clock = new MockGlobalClock();
+
+            using (UnitTestApplication.Start(new TestServices(globalClock: clock)))
+            {
+                int i = 0;
+                var inst = new TransitionInstance(clock, TimeSpan.Zero).Subscribe(nextValue =>
+                {
+                    switch (i++)
+                    {
+                        case 0: Assert.Equal(0, nextValue); break;
+                        case 1: Assert.Equal(1d, nextValue); break;
+                    }
+                });
+
+                clock.Pulse(TimeSpan.FromMilliseconds(10));
+            }
+        }
     }
 }

+ 12 - 0
tests/Avalonia.Base.UnitTests/AvaloniaObjectTests_Validation.cs

@@ -78,6 +78,18 @@ namespace Avalonia.Base.UnitTests
             Assert.Equal(10, target.GetValue(Class1.AttachedProperty));
         }
 
+        [Fact]
+        public void PropertyChanged_Event_Uses_Coerced_Value()
+        {
+            var inst = new Class1();
+            inst.PropertyChanged += (sender, e) =>
+            {
+                Assert.Equal(10, e.NewValue);
+            };
+
+            inst.SetValue(Class1.QuxProperty, 15);
+        }
+
         private class Class1 : AvaloniaObject
         {
             public static readonly StyledProperty<int> QuxProperty =