Browse Source

Use the target Animatible as an anchor for the binding.

pull/1768/head
Jeremy Koritzinsky 8 years ago
parent
commit
a52d9c812d
  1. 18
      src/Avalonia.Animation/Animation.cs
  2. 6
      src/Avalonia.Animation/AnimatorKeyFrame.cs

18
src/Avalonia.Animation/Animation.cs

@ -80,7 +80,7 @@ namespace Avalonia.Animation
this.CollectionChanged += delegate { _isChildrenChanged = true; }; this.CollectionChanged += delegate { _isChildrenChanged = true; };
} }
private void InterpretKeyframes() private IList<IAnimator> InterpretKeyframes(Animatable control)
{ {
var handlerList = new List<(Type type, AvaloniaProperty property)>(); var handlerList = new List<(Type type, AvaloniaProperty property)>();
var animatorKeyFrames = new List<AnimatorKeyFrame>(); var animatorKeyFrames = new List<AnimatorKeyFrame>();
@ -108,7 +108,7 @@ namespace Avalonia.Animation
var newKF = new AnimatorKeyFrame(handler, cue); var newKF = new AnimatorKeyFrame(handler, cue);
_subscription.Add(newKF.BindSetter(setter)); _subscription.Add(newKF.BindSetter(setter, control));
animatorKeyFrames.Add(newKF); animatorKeyFrames.Add(newKF);
} }
@ -130,9 +130,7 @@ namespace Avalonia.Animation
animator.Add(keyframe); animator.Add(keyframe);
} }
foreach(var instance in newAnimatorInstances) return newAnimatorInstances;
_animators.Add(instance);
} }
/// <summary> /// <summary>
@ -149,15 +147,9 @@ namespace Avalonia.Animation
/// <inheritdocs/> /// <inheritdocs/>
public IDisposable Apply(Animatable control, IObservable<bool> matchObs) public IDisposable Apply(Animatable control, IObservable<bool> matchObs)
{ {
if (_isChildrenChanged) foreach (IAnimator animator in InterpretKeyframes(control))
{
InterpretKeyframes();
_isChildrenChanged = false;
}
foreach (IAnimator keyframes in _animators)
{ {
_subscription.Add(keyframes.Apply(this, control, matchObs)); _subscription.Add(animator.Apply(this, control, matchObs));
} }
return this; return this;
} }

6
src/Avalonia.Animation/AnimatorKeyFrame.cs

@ -41,18 +41,18 @@ namespace Avalonia.Animation
set => SetAndRaise(ValueProperty, ref _value, value); set => SetAndRaise(ValueProperty, ref _value, value);
} }
public IDisposable BindSetter(IAnimationSetter setter) public IDisposable BindSetter(IAnimationSetter setter, Animatable targetControl)
{ {
Property = setter.Property; Property = setter.Property;
var value = setter.Value; var value = setter.Value;
if (value is IBinding binding) if (value is IBinding binding)
{ {
return this.Bind(ValueProperty, binding); return this.Bind(ValueProperty, binding, targetControl);
} }
else else
{ {
return this.Bind(ValueProperty, ObservableEx.SingleValue(value)); return this.Bind(ValueProperty, ObservableEx.SingleValue(value).ToBinding(), targetControl);
} }
} }

Loading…
Cancel
Save