Skip to content

Commit

Permalink
Speed-up Border rendering by avoiding useless pass during size alloca…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
albyrock87 committed Sep 25, 2024
1 parent 68524c8 commit cc1101e
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/Controls/src/Core/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Border : View, IContentView, IBorderView, IPaddingElement
PropertyChangedEventHandler? _strokeShapeChanged;
WeakNotifyPropertyChangedProxy? _strokeProxy = null;
PropertyChangedEventHandler? _strokeChanged;
bool _sizeChanged;

~Border()
{
Expand Down Expand Up @@ -309,16 +310,29 @@ protected override void OnPropertyChanged([CallerMemberName] string? propertyNam
{
base.OnPropertyChanged(propertyName);

if (propertyName == HeightProperty.PropertyName ||
propertyName == StrokeThicknessProperty.PropertyName ||
propertyName == StrokeShapeProperty.PropertyName ||
propertyName == WidthProperty.PropertyName)
if (propertyName == WidthProperty.PropertyName || propertyName == HeightProperty.PropertyName)
{
_sizeChanged = true;
}
else if (propertyName == StrokeThicknessProperty.PropertyName || propertyName == StrokeShapeProperty.PropertyName)
{
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
UpdateStrokeShape();
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
}
else if (propertyName == StrokeDashArrayProperty.PropertyName)
{
Handler?.UpdateValue(nameof(IBorderStroke.StrokeDashPattern));
}
}

protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
if (_sizeChanged)
{
_sizeChanged = false;
Handler?.UpdateValue(nameof(IBorderStroke.Shape));
}
}

void OnStrokeDashArrayChanged(object? sender, NotifyCollectionChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void
override Microsoft.Maui.Controls.Handlers.Compatibility.FrameRenderer.MovedToWindow() -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#nullable enable
override Microsoft.Maui.Controls.Border.OnSizeAllocated(double width, double height) -> void

0 comments on commit cc1101e

Please sign in to comment.