Skip to content

Commit

Permalink
Merge pull request #19245 from unoplatform/mergify/bp/release/stable/…
Browse files Browse the repository at this point in the history
…5.6/pr-19228

perf(anim): Don't refresh triggers and transitions during parsing (backport #19228)
  • Loading branch information
jeromelaban authored Jan 16, 2025
2 parents 2c9c2be + dd52acc commit cccbfba
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/Uno.UI/UI/Xaml/VisualStateGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public sealed partial class VisualStateGroup : DependencyObject
private readonly SerialDisposable _parentLoadedDisposable = new();

private (VisualState state, VisualTransition transition) _current;
private bool _pendingOnOwnerElementChanged;

public event VisualStateChangedEventHandler CurrentStateChanging;

Expand Down Expand Up @@ -159,11 +160,27 @@ private void OnParentChanged(object instance, object key, DependencyObjectParent
}
}

private void OnOwnerElementChanged() =>
private void OnOwnerElementChanged()
{
if (this.GetParent() is IFrameworkElement { IsParsing: true })
{
_pendingOnOwnerElementChanged = true;
return;
}

ExecuteOnTriggers(t => t.OnOwnerElementChanged());
}

private void OnOwnerElementLoaded(object sender, RoutedEventArgs args)
{
if (_pendingOnOwnerElementChanged)
{
_pendingOnOwnerElementChanged = false;
OnOwnerElementChanged();
}

private void OnOwnerElementLoaded(object sender, RoutedEventArgs args) =>
ExecuteOnTriggers(t => t.OnOwnerElementLoaded());
}

private void OnOwnerElementUnloaded(object sender, RoutedEventArgs args) =>
ExecuteOnTriggers(t => t.OnOwnerElementUnloaded());
Expand Down Expand Up @@ -500,6 +517,11 @@ static bool Match(VisualTransition transition, string from, string to)

internal void RefreshStateTriggers(bool force = false)
{
if (this.GetParent() is IFrameworkElement { IsParsing: true })
{
return;
}

var newState = GetActiveTrigger();
var oldState = CurrentState;
if (newState == oldState)
Expand Down

0 comments on commit cccbfba

Please sign in to comment.