Skip to content

Commit

Permalink
Make ValueStore typed.
Browse files Browse the repository at this point in the history
Major refactor of the Avalonia core to make the styled property store typed.
  • Loading branch information
grokys committed Nov 14, 2019
1 parent fc2439e commit 6be3acb
Show file tree
Hide file tree
Showing 74 changed files with 3,506 additions and 2,103 deletions.
26 changes: 15 additions & 11 deletions src/Avalonia.Animation/Animatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,30 @@ public Transitions 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.
/// </summary>
/// <param name="e">The event args.</param>
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
protected override void OnPropertyChanged<T>(
AvaloniaProperty<T> property,
Optional<T> oldValue,
BindingValue<T> newValue,
BindingPriority priority)
{
if (_transitions is null || _previousTransitions is null || e.Priority == BindingPriority.Animation) return;
if (_transitions is null || _previousTransitions is null || priority == BindingPriority.Animation)
return;

// PERF-SENSITIVE: Called on every property change. Don't use LINQ here (too many allocations).
foreach (var transition in _transitions)
{
if (transition.Property == e.Property)
if (transition.Property == property)
{
if (_previousTransitions.TryGetValue(e.Property, out var dispose))
if (_previousTransitions.TryGetValue(property, out var dispose))
dispose.Dispose();

var instance = transition.Apply(this, Clock ?? Avalonia.Animation.Clock.GlobalClock, e.OldValue, e.NewValue);
var instance = transition.Apply(
this,
Clock ?? Avalonia.Animation.Clock.GlobalClock,
oldValue.ValueOrDefault(),
newValue.ValueOrDefault());

_previousTransitions[e.Property] = instance;
_previousTransitions[property] = instance;
return;
}
}
Expand Down
Loading

0 comments on commit 6be3acb

Please sign in to comment.