Browse Source

Fixed transition backend, transitions are now working.

pull/1461/head
Jumar Macato 8 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="Margin" Value="0"/>
<Setter Property="Padding" Value="16"/>
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity" Easing="CircularEaseIn" Duration="0:0:0.5"/>
</Transitions>
</Setter>
</Style>
<Style Selector="TabControl.sidebar TabStripItem:pointerover">
<Setter Property="Opacity" Value="0.5"/>
</Style>
<Style Selector="TabControl.sidebar TabStripItem:selected">
<Setter Property="Background" Value="{DynamicResource ThemeAccentBrush2}"/>
</Style>

82
src/Avalonia.Animation/Animatable.cs

@ -13,35 +13,24 @@ namespace Avalonia.Animation
/// </summary>
public class Animatable : AvaloniaObject
{
private Transitions _transitions;
/// <summary>
///
/// </summary>
public static readonly StyledProperty<Transitions> TransitionsProperty =
AvaloniaProperty.Register<Animatable, Transitions>(nameof(Transitions));
/// <summary>
/// Gets or sets the property transitions for the control.
/// </summary>
public Transitions Transitions
{
get
{
return _transitions ?? (_transitions = new Transitions());
}
set
{
SetAndRaise(TransitionsProperty, ref _transitions, value);
}
get { return GetValue(TransitionsProperty); }
set { SetValue(TransitionsProperty, 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>
/// Reacts to a change in a <see cref="AvaloniaProperty"/> value in
/// order to animate the change if a <see cref="ITransition"/>
/// is set for the property.
/// order to animate the change if a <see cref="ITransition"/> is set for the property.
/// </summary>
/// <param name="e">The event args.</param>
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
@ -50,65 +39,12 @@ namespace Avalonia.Animation
{
var match = Transitions.FirstOrDefault(x => x.Property == e.Property);
if (match != null)
{
// //BindAnimateProperty(this, e.Property, e.OldValue, e.NewValue, match.Easing, match.Duration);
match.Apply(this, e.OldValue, e.NewValue);
}
}
}
///// <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 System;
using System.Reactive.Linq;
namespace Avalonia.Animation
{
@ -12,21 +13,14 @@ namespace Avalonia.Animation
public class DoubleTransition : Transition<double>
{
/// <inheritdocs/>
public DoubleTransition() : base()
public override void DoInterpolation(Animatable control, IObservable<double> progress, double oldValue, double newValue)
{
}
/// <inheritdocs/>
public override AvaloniaProperty Property { get; set; }
/// <inheritdocs/>
public override void Apply(Animatable control)
{
//throw new NotImplementedException();
var delta = newValue - oldValue;
var transition = progress.Select(p =>
{
return Easing.Ease(p) * delta + oldValue;
});
control.Bind(Property, transition.Select(p=>(object)p), Data.BindingPriority.Animation);
}
}
}

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

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

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

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

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

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

Loading…
Cancel
Save