[C] reset children animation on repeat (#974)

This commit is contained in:
Stephane Delcroix 2017-06-08 20:38:45 +02:00 коммит произвёл GitHub
Родитель 0d3611ccce
Коммит 3a0aa90164
4 изменённых файлов: 56 добавлений и 5 удалений

Просмотреть файл

@ -0,0 +1,33 @@
using NUnit.Framework;
using System.Threading.Tasks;
namespace Xamarin.Forms.Core.UnitTests
{
[TestFixture]
public class AnimationTests : BaseTestFixture
{
[Test]
//https://bugzilla.xamarin.com/show_bug.cgi?id=51424
public async void AnimationRepeats()
{
var box = new BoxView();
Assume.That(box.Rotation, Is.EqualTo(0d));
var sb = new Animation();
var animcount = 0;
var rot45 = new Animation(d =>
{
box.Rotation = d;
if (d > 44)
animcount++;
}, box.Rotation, box.Rotation + 45);
sb.Add(0, .5, rot45);
Assume.That(box.Rotation, Is.EqualTo(0d));
var i = 0;
sb.Commit(box, "foo", length: 100, repeat: () => ++i < 2);
await Task.Delay(250);
Assert.That(animcount, Is.EqualTo(2));
}
}
}

Просмотреть файл

@ -183,6 +183,7 @@
<Compile Include="AppLinkEntryTests.cs" />
<Compile Include="NativeBindingTests.cs" />
<Compile Include="TypedBindingUnitTests.cs" />
<Compile Include="AnimationTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Xamarin.Forms.Core\Xamarin.Forms.Core.csproj">

Просмотреть файл

@ -112,6 +112,12 @@ namespace Xamarin.Forms
return result;
}
internal void ResetChildren()
{
foreach (var anim in _children)
anim._finishedTriggered = false;
}
public Animation Insert(double beginAt, double finishAt, Animation animation)
{
Add(beginAt, finishAt, animation);

Просмотреть файл

@ -71,7 +71,18 @@ namespace Xamarin.Forms
public static void Animate(this IAnimatable self, string name, Animation animation, uint rate = 16, uint length = 250, Easing easing = null, Action<double, bool> finished = null,
Func<bool> repeat = null)
{
self.Animate(name, animation.GetCallback(), rate, length, easing, finished, repeat);
if (repeat == null)
self.Animate(name, animation.GetCallback(), rate, length, easing, finished, null);
else {
Func<bool> r = () =>
{
var val = repeat();
if (val)
animation.ResetChildren();
return val;
};
self.Animate(name, animation.GetCallback(), rate, length, easing, finished, r);
}
}
public static void Animate(this IAnimatable self, string name, Action<double> callback, double start, double end, uint rate = 16, uint length = 250, Easing easing = null,
@ -232,15 +243,15 @@ namespace Xamarin.Forms
Info info;
if (tweener != null && s_animations.TryGetValue(tweener.Handle, out info))
{
var repeat = false;
if (info.Repeat != null)
repeat = info.Repeat();
IAnimatable owner;
if (info.Owner.TryGetTarget(out owner))
owner.BatchBegin();
info.Callback(tweener.Value);
var repeat = false;
if (info.Repeat != null)
repeat = info.Repeat();
if (!repeat)
{
s_animations.Remove(tweener.Handle);