Browse Source

Fixed transitions with delay but no duration completing instantly (#18929)

pull/18950/head
Tom Edwards 11 months ago
committed by GitHub
parent
commit
edeca6a4db
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      src/Avalonia.Base/Animation/TransitionInstance.cs
  2. 43
      tests/Avalonia.Base.UnitTests/Animation/TransitionsTests.cs

12
src/Avalonia.Base/Animation/TransitionInstance.cs

@ -33,9 +33,17 @@ namespace Avalonia.Animation
// ^- normalizedDelayEnd
// [<---- normalizedInterpVal --->]
var normalizedInterpVal = 1d;
double normalizedInterpVal;
if (!MathUtilities.AreClose(_duration.TotalSeconds, 0d))
if (t < _delay)
{
normalizedInterpVal = 0d;
}
else if (MathUtilities.AreClose(_duration.TotalSeconds, 0d))
{
normalizedInterpVal = 1d;
}
else
{
var normalizedTotalDur = _delay + _duration;
var normalizedDelayEnd = _delay.TotalSeconds / normalizedTotalDur.TotalSeconds;

43
tests/Avalonia.Base.UnitTests/Animation/TransitionsTests.cs

@ -84,7 +84,8 @@ namespace Avalonia.Base.UnitTests.Animation
var clock = new TestClock();
var i = -1;
var completed = false;
new TransitionInstance(clock, TimeSpan.FromMilliseconds(30), TimeSpan.FromMilliseconds(70)).Subscribe(
nextValue =>
{
@ -124,12 +125,50 @@ namespace Avalonia.Base.UnitTests.Animation
Assert.Equal(1d, nextValue);
break;
}
});
}, () => completed = true);
for (var z = 0; z <= 10; z++)
{
clock.Pulse(TimeSpan.FromMilliseconds(10));
}
Assert.True(completed);
}
[Fact]
public void TransitionInstance_With_Delay_But_Zero_Duration_Is_Completed_After_Delay()
{
var clock = new TestClock();
var i = -1;
var completed = false;
new TransitionInstance(clock, TimeSpan.FromMilliseconds(30), TimeSpan.Zero).Subscribe(
nextValue =>
{
switch (i++)
{
case 0:
Assert.Equal(0, nextValue);
break;
case 1:
Assert.Equal(0, nextValue);
break;
case 2:
Assert.Equal(0, nextValue);
break;
case 3: // one iteration sooner than the test above, because the start of the transition is also the end
Assert.Equal(1, nextValue);
break;
}
}, () => completed = true);
for (var z = 0; z <= 4; z++)
{
clock.Pulse(TimeSpan.FromMilliseconds(10));
}
Assert.True(completed);
}
}
}

Loading…
Cancel
Save