Skip to content

Commit

Permalink
chore: reduce Update() calls due to LayoutUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Oct 14, 2024
1 parent 5d31deb commit 9a13603
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if !UNO_HAS_BORDER_VISUAL
using System;
using Windows.Foundation;
using Microsoft.UI.Xaml;
using Uno.Disposables;

Expand All @@ -15,6 +16,7 @@ internal partial class BorderLayerRenderer

#pragma warning disable CS0414 // _currentState is not used on reference build
private BorderLayerState _currentState;
private Size _sizeOnLastUpdate;
#pragma warning restore CS0414

public BorderLayerRenderer(FrameworkElement owner)
Expand All @@ -35,7 +37,13 @@ public BorderLayerRenderer(FrameworkElement owner)
// Using SizeChanged on other platforms SHOULD work. But it didn't work on Android
// for unknown reason. For now, we are using SizeChanged only on enhanced lifecycle
// platforms where we are sure it works correctly.
_owner.LayoutUpdated += (_, _) => Update();
_owner.LayoutUpdated += (_, _) =>
{
if (_owner.RenderSize != _sizeOnLastUpdate)
{
Update();
}
};
#endif
}

Expand All @@ -46,6 +54,7 @@ internal void Update()
{
if (_owner.IsLoaded)
{
_sizeOnLastUpdate = _owner.RenderSize;
UpdatePlatform();
}
}
Expand Down

0 comments on commit 9a13603

Please sign in to comment.