Browse Source

Make KeyFrame an AvaloniaObject and move the setters to a dedicated property.

pull/2163/head
Jumar Macato 8 years ago
parent
commit
660691da49
No known key found for this signature in database GPG Key ID: B19884DAC3A5BF3F
  1. 2
      src/Avalonia.Animation/Animation.cs
  2. 15
      src/Avalonia.Animation/KeyFrame.cs
  3. 40
      src/Avalonia.Visuals/Animation/CrossFade.cs
  4. 63
      src/Avalonia.Visuals/Animation/PageSlide.cs
  5. 15
      tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs

2
src/Avalonia.Animation/Animation.cs

@ -113,7 +113,7 @@ namespace Avalonia.Animation
foreach (var keyframe in Children)
{
foreach (var setter in keyframe)
foreach (var setter in keyframe.Setters)
{
var handler = GetAnimatorType(setter.Property);

15
src/Avalonia.Animation/KeyFrame.cs

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Avalonia.Collections;
using Avalonia.Metadata;
namespace Avalonia.Animation
{
@ -17,7 +18,7 @@ namespace Avalonia.Animation
/// Stores data regarding a specific key
/// point and value in an animation.
/// </summary>
public class KeyFrame : AvaloniaList<IAnimationSetter>
public class KeyFrame : AvaloniaObject
{
private TimeSpan _ktimeSpan;
private Cue _kCue;
@ -26,13 +27,11 @@ namespace Avalonia.Animation
{
}
public KeyFrame(IEnumerable<IAnimationSetter> items) : base(items)
{
}
public KeyFrame(params IAnimationSetter[] items) : base(items)
{
}
/// <summary>
/// Gets the setters of <see cref="KeyFrame"/>.
/// </summary>
[Content]
public AvaloniaList<IAnimationSetter> Setters { get; } = new AvaloniaList<IAnimationSetter>();
internal KeyFrameTimingMode TimingMode { get; private set; }

40
src/Avalonia.Visuals/Animation/CrossFade.cs

@ -33,36 +33,40 @@ namespace Avalonia.Animation
{
_fadeOutAnimation = new Animation
{
Children =
Children =
{
new KeyFrame
(
new Setter
{
Property = Visual.OpacityProperty,
Value = 0d
}
)
new KeyFrame()
{
Setters =
{
new Setter
{
Property = Visual.OpacityProperty,
Value = 0d
}
},
Cue = new Cue(1d)
}
}
};
_fadeInAnimation = new Animation
{
Children =
Children =
{
new KeyFrame
(
new Setter
{
Property = Visual.OpacityProperty,
Value = 0d
}
)
new KeyFrame()
{
Setters =
{
new Setter
{
Property = Visual.OpacityProperty,
Value = 0d
}
},
Cue = new Cue(0d)
}
}
};
_fadeOutAnimation.Duration = _fadeInAnimation.Duration = duration;

63
src/Avalonia.Visuals/Animation/PageSlide.cs

@ -81,27 +81,29 @@ namespace Avalonia.Animation
Children =
{
new KeyFrame
(
new Setter
{
Setters =
{
Property = translateProperty,
new Setter
{
Property = translateProperty,
Value = 0d
}
)
{
}
},
Cue = new Cue(0d)
},
new KeyFrame
(
new Setter
{
Property = translateProperty,
Value = forward ? -distance : distance
}
)
{
Setters =
{
new Setter
{
Property = translateProperty,
Value = forward ? -distance : distance
}
},
Cue = new Cue(1d)
}
}
}
};
animation.Duration = Duration;
@ -115,28 +117,31 @@ namespace Avalonia.Animation
{
Children =
{
new KeyFrame
(
new Setter
{
Property = translateProperty,
Value = forward ? distance : -distance
}
)
{
Setters =
{
new Setter
{
Property = translateProperty,
Value = forward ? distance : -distance
}
},
Cue = new Cue(0d)
},
new KeyFrame
(
new Setter
{
Property = translateProperty,
Value = 0d
}
)
{
Setters =
{
new Setter
{
Property = translateProperty,
Value = 0d
}
},
Cue = new Cue(1d)
},
}
}
};
animation.Duration = Duration;

15
tests/Avalonia.Animation.UnitTests/AnimationIterationTests.cs

@ -18,17 +18,20 @@ namespace Avalonia.Animation.UnitTests
{
var keyframe1 = new KeyFrame()
{
new Setter(Border.WidthProperty, 200d),
Setters = {
new Setter(Border.WidthProperty, 200d),
},
Cue = new Cue(1d)
};
var keyframe2 = new KeyFrame()
{
new Setter(Border.WidthProperty, 100d),
Setters = {
new Setter(Border.WidthProperty, 100d),
},
Cue = new Cue(0d)
};
keyframe1.Cue = new Cue(1d);
keyframe2.Cue = new Cue(0d);
var animation = new Animation()
{
Duration = TimeSpan.FromSeconds(3),

Loading…
Cancel
Save