Browse Source

Fixed transition backend, transitions are now working.

pull/1461/head
Jumar Macato 9 years ago
parent
commit
378bdc6c8c
  1. 9
      samples/RenderTest/SideBar.xaml
  2. 82
      src/Avalonia.Animation/Animatable.cs
  3. 22
      src/Avalonia.Animation/Transitions/DoubleTransition.cs
  4. 41
      src/Avalonia.Animation/Transitions/Transition.cs
  5. 8
      src/Avalonia.Visuals/Animation/PageSlide.cs
  6. 1
      src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs

9
samples/RenderTest/SideBar.xaml

@ -32,8 +32,17 @@
<Setter Property="FontSize" Value="14"/> <Setter Property="FontSize" Value="14"/>
<Setter Property="Margin" Value="0"/> <Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="16"/> <Setter Property="Padding" Value="16"/>
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity" Easing="CircularEaseIn" Duration="0:0:0.5"/>
</Transitions>
</Setter>
</Style> </Style>
<Style Selector="TabControl.sidebar TabStripItem:pointerover">
<Setter Property="Opacity" Value="0.5"/>
</Style>
<Style Selector="TabControl.sidebar TabStripItem:selected"> <Style Selector="TabControl.sidebar TabStripItem:selected">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/> <Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/>
</Style> </Style>

82
src/Avalonia.Animation/Animatable.cs

@ -13,35 +13,24 @@ namespace Avalonia.Animation
/// </summary> /// </summary>
public class Animatable : AvaloniaObject public class Animatable : AvaloniaObject
{ {
/// <summary>
private Transitions _transitions; ///
/// </summary>
public static readonly StyledProperty<Transitions> TransitionsProperty =
AvaloniaProperty.Register<Animatable, Transitions>(nameof(Transitions));
/// <summary> /// <summary>
/// Gets or sets the property transitions for the control. /// Gets or sets the property transitions for the control.
/// </summary> /// </summary>
public Transitions Transitions public Transitions Transitions
{ {
get get { return GetValue(TransitionsProperty); }
{ set { SetValue(TransitionsProperty, value); }
return _transitions ?? (_transitions = new Transitions());
}
set
{
SetAndRaise(TransitionsProperty, ref _transitions, value);
}
} }
/// <summary>
/// Gets or sets the property transitions for the control.
/// </summary>
public static readonly DirectProperty<Animatable, Transitions> TransitionsProperty =
AvaloniaProperty.RegisterDirect<Animatable, Transitions>(nameof(Transitions), o => o.Transitions);
/// <summary> /// <summary>
/// Reacts to a change in a <see cref="AvaloniaProperty"/> value in /// Reacts to a change in a <see cref="AvaloniaProperty"/> value in
/// order to animate the change if a <see cref="ITransition"/> /// order to animate the change if a <see cref="ITransition"/> is set for the property.
/// is set for the property.
/// </summary> /// </summary>
/// <param name="e">The event args.</param> /// <param name="e">The event args.</param>
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e) protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
@ -50,65 +39,12 @@ namespace Avalonia.Animation
{ {
var match = Transitions.FirstOrDefault(x => x.Property == e.Property); var match = Transitions.FirstOrDefault(x => x.Property == e.Property);
if (match != null) if (match != null)
{ {
match.Apply(this, e.OldValue, e.NewValue);
// //BindAnimateProperty(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration);
} }
} }
} }
///// <summary>
///// Animates a <see cref="AvaloniaProperty"/>.
///// </summary>
///// <param name="target">The target object.</param>
///// <param name="property">The target property.</param>
///// <param name="start">The value of the property at the start of the animation.</param>
///// <param name="finish">The value of the property at the end of the animation.</param>
///// <param name="easing">The easing function to use.</param>
///// <param name="duration">The duration of the animation.</param>
///// <returns>An <see cref="Animation"/> that can be used to track or stop the animation.</returns>
//public static Animation BindAnimateProperty(
// IAvaloniaObject target,
// AvaloniaProperty property,
// object start,
// object finish,
// IEasing easing,
// TimeSpan duration)
//{
// var k = start.GetType();
// if (k == typeof(double))
// {
// var o = Timing.GetTimer(duration).Select(progress => easing.Ease(progress, start, finish));
// return new Animation(o, target.Bind(property, o, BindingPriority.Animation));
// }
// else
// return null;
//}
///// <summary>
///// Animates a <see cref="AvaloniaProperty"/>.
///// </summary>
///// <typeparam name="T">The property type.</typeparam>
///// <param name="target">The target object.</param>
///// <param name="property">The target property.</param>
///// <param name="start">The value of the property at the start of the animation.</param>
///// <param name="finish">The value of the property at the end of the animation.</param>
///// <param name="easing">The easing function to use.</param>
///// <param name="duration">The duration of the animation.</param>
///// <returns>An <see cref="Animation"/> that can be used to track or stop the animation.</returns>
//public static Animation<T> Property<T>(
// IAvaloniaObject target,
// AvaloniaProperty<T> property,
// T start,
// T finish,
// IEasing<T> easing,
// TimeSpan duration)
//{
// var o = Timing.GetTimer(duration).Select(progress => easing.Ease(progress, start, finish));
// return new Animation<T>(o, target.Bind(property, o, BindingPriority.Animation));
//}
} }
} }

22
src/Avalonia.Animation/Transitions/DoubleTransition.cs

@ -3,6 +3,7 @@
using Avalonia.Metadata; using Avalonia.Metadata;
using System; using System;
using System.Reactive.Linq;
namespace Avalonia.Animation namespace Avalonia.Animation
{ {
@ -12,21 +13,14 @@ namespace Avalonia.Animation
public class DoubleTransition : Transition<double> public class DoubleTransition : Transition<double>
{ {
/// <inheritdocs/> /// <inheritdocs/>
public DoubleTransition() : base() public override void DoInterpolation(Animatable control, IObservable<double> progress, double oldValue, double newValue)
{ {
var delta = newValue - oldValue;
} var transition = progress.Select(p =>
{
/// <inheritdocs/> return Easing.Ease(p) * delta + oldValue;
public override AvaloniaProperty Property { get; set; } });
control.Bind(Property, transition.Select(p=>(object)p), Data.BindingPriority.Animation);
/// <inheritdocs/>
public override void Apply(Animatable control)
{
//throw new NotImplementedException();
} }
} }
} }

41
src/Avalonia.Animation/Transitions/Transition.cs

@ -11,13 +11,14 @@ namespace Avalonia.Animation
/// <summary> /// <summary>
/// Applies the transition to the specified <see cref="Animatable"/>. /// Applies the transition to the specified <see cref="Animatable"/>.
/// </summary> /// </summary>
/// <param name="control"></param> void Apply(Animatable control, object oldValue, object newValue);
void Apply(Animatable control);
/// <summary> /// <summary>
/// Gets the property to be animated. /// Gets the property to be animated.
/// </summary> /// </summary>
AvaloniaProperty Property { get; set; } AvaloniaProperty Property { get; set; }
} }
/// <summary> /// <summary>
@ -29,29 +30,41 @@ namespace Avalonia.Animation
/// Gets the duration of the animation. /// Gets the duration of the animation.
/// </summary> /// </summary>
public TimeSpan Duration { get; set; } public TimeSpan Duration { get; set; }
/// <summary> /// <summary>
/// Instantiates the base abstract class <see cref="Transition{T}"/>. /// Gets the easing class to be used.
/// </summary> /// </summary>
public Transition() public IEasing Easing { get; set; }
private AvaloniaProperty _prop;
/// <inheritdocs/>
public AvaloniaProperty Property
{ {
if(!(typeof(T) == Property.PropertyType)) get
{ {
throw new InvalidCastException return _prop;
($"Invalid property type {typeof(T).Name} for this {this.GetType().Name}"); }
set
{
if (!(typeof(T) == value.PropertyType))
throw new InvalidCastException
($"Invalid property type {typeof(T).Name} for this {GetType().Name}");
_prop = value;
} }
} }
/// <summary> /// <summary>
/// Gets the easing class to be used. /// Apply interpolation to the property.
/// </summary> /// </summary>
public IEasing Easing { get; set; } public abstract void DoInterpolation(Animatable control, IObservable<double> progress, T oldValue, T newValue);
/// <inheritdocs/> /// <inheritdocs/>
public abstract AvaloniaProperty Property { get; set; } public void Apply(Animatable control, object oldValue, object newValue)
{
/// <inheritdocs/> DoInterpolation(control, Timing.GetTimer(Duration), (T)oldValue, (T)newValue);
public abstract void Apply(Animatable control); }
} }

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

@ -76,8 +76,8 @@ namespace Avalonia.Animation
if (from != null) if (from != null)
{ {
var transform = new TranslateTransform(); //var transform = new TranslateTransform();
from.RenderTransform = transform; //from.RenderTransform = transform;
//tasks.Add(Animate.Property( //tasks.Add(Animate.Property(
// transform, // transform,
// translateProperty, // translateProperty,
@ -89,8 +89,8 @@ namespace Avalonia.Animation
if (to != null) if (to != null)
{ {
var transform = new TranslateTransform(); //var transform = new TranslateTransform();
to.RenderTransform = transform; //to.RenderTransform = transform;
to.IsVisible = true; to.IsVisible = true;
//tasks.Add(Animate.Property( //tasks.Add(Animate.Property(
// transform, // transform,

1
src/Markup/Avalonia.Markup.Xaml/PortableXaml/AvaloniaDefaultTypeConverters.cs

@ -49,6 +49,7 @@ namespace Avalonia.Markup.Xaml.PortableXaml
{ typeof(Cursor), typeof(CursorTypeConverter) }, { typeof(Cursor), typeof(CursorTypeConverter) },
{ typeof(WindowIcon), typeof(IconTypeConverter) }, { typeof(WindowIcon), typeof(IconTypeConverter) },
{ typeof(Easing), typeof(EasingTypeConverter) }, { typeof(Easing), typeof(EasingTypeConverter) },
{ typeof(IEasing), typeof(EasingTypeConverter) },
//{ typeof(FontWeight), typeof(FontWeightConverter) }, //{ typeof(FontWeight), typeof(FontWeightConverter) },
}; };

Loading…
Cancel
Save