Skip to content

Commit

Permalink
Merge pull request #3255 from AvaloniaUI/refactor/value-store
Browse files Browse the repository at this point in the history
Make styled property storage typed
  • Loading branch information
grokys authored Jan 23, 2020
2 parents e3aa3bc + 527bac1 commit 6c40771
Show file tree
Hide file tree
Showing 100 changed files with 4,469 additions and 2,478 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.GetValueOrDefault(),
newValue.GetValueOrDefault());

_previousTransitions[e.Property] = instance;
_previousTransitions[property] = instance;
return;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Avalonia.Base/AttachedProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public class AttachedProperty<TValue> : StyledProperty<TValue>
/// <param name="ownerType">The class that is registering the property.</param>
/// <param name="metadata">The property metadata.</param>
/// <param name="inherits">Whether the property inherits its value.</param>
/// <param name="validate">A value validation callback.</param>
public AttachedProperty(
string name,
Type ownerType,
Type ownerType,
StyledPropertyMetadata<TValue> metadata,
bool inherits = false)
: base(name, ownerType, metadata, inherits)
bool inherits = false,
Func<TValue, bool> validate = null)
: base(name, ownerType, metadata, inherits, validate)
{
}

Expand Down
Loading

0 comments on commit 6c40771

Please sign in to comment.