Skip to content

Commit 62caa3f

Browse files
committed
Revert "Revert "Cleanup virtual layer measure invalidation (dotnet#28756)" (dotnet#28872)"
This reverts commit 4ff875a.
1 parent 4ff875a commit 62caa3f

File tree

16 files changed

+205
-218
lines changed

16 files changed

+205
-218
lines changed

src/Controls/src/Core/ContentPresenter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,5 @@ Size ICrossPlatformLayout.CrossPlatformArrange(Rect bounds)
130130
this.ArrangeContent(bounds);
131131
return bounds.Size;
132132
}
133-
134-
private protected override void InvalidateMeasureLegacy(InvalidationTrigger trigger, int depth, int depthLeveltoInvalidate)
135-
{
136-
base.InvalidateMeasureLegacy(trigger, depth, 1);
137-
}
138133
}
139134
}

src/Controls/src/Core/InvalidationEventArgs.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ public InvalidationEventArgs(InvalidationTrigger trigger)
1010
{
1111
Trigger = trigger;
1212
}
13-
public InvalidationEventArgs(InvalidationTrigger trigger, int depth) : this(trigger)
14-
{
15-
CurrentInvalidationDepth = depth;
16-
}
17-
1813

1914
public InvalidationTrigger Trigger { get; private set; }
20-
21-
22-
public int CurrentInvalidationDepth { set; get; }
2315
}
2416
}

src/Controls/src/Core/LegacyLayouts/Layout.cs

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,12 @@ public override SizeRequest Measure(double widthConstraint, double heightConstra
202202
SizeRequest size = base.Measure(widthConstraint - Padding.HorizontalThickness, heightConstraint - Padding.VerticalThickness, flags);
203203
#pragma warning restore CS0618 // Type or member is obsolete
204204
#pragma warning disable CS0618 // Type or member is obsolete
205-
return new SizeRequest(new Size(size.Request.Width + Padding.HorizontalThickness, size.Request.Height + Padding.VerticalThickness),
206-
new Size(size.Minimum.Width + Padding.HorizontalThickness, size.Minimum.Height + Padding.VerticalThickness));
205+
var request = new Size(size.Request.Width + Padding.HorizontalThickness, size.Request.Height + Padding.VerticalThickness);
206+
var minimum = new Size(size.Minimum.Width + Padding.HorizontalThickness, size.Minimum.Height + Padding.VerticalThickness);
207+
208+
DesiredSize = request;
209+
210+
return new SizeRequest(request, minimum);
207211
#pragma warning restore CS0618 // Type or member is obsolete
208212
}
209213
#pragma warning restore CS0672 // Member overrides obsolete member
@@ -320,14 +324,19 @@ public void RaiseChild(View view)
320324
[Obsolete("Use InvalidateMeasure depending on your scenario")]
321325
protected virtual void InvalidateLayout()
322326
{
323-
_hasDoneLayout = false;
327+
SetNeedsLayout();
324328
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
325329
if (!_hasDoneLayout)
326330
{
327331
ForceLayout();
328332
}
329333
}
330334

335+
void SetNeedsLayout()
336+
{
337+
_hasDoneLayout = false;
338+
}
339+
331340
/// <summary>
332341
/// Positions and sizes the children of a layout.
333342
/// </summary>
@@ -341,10 +350,18 @@ protected virtual void InvalidateLayout()
341350
[Obsolete("Use ArrangeOverride")]
342351
protected abstract void LayoutChildren(double x, double y, double width, double height);
343352

344-
internal override void OnChildMeasureInvalidatedInternal(VisualElement child, InvalidationTrigger trigger, int depth)
353+
internal override void OnChildMeasureInvalidated(VisualElement child, InvalidationTrigger trigger)
345354
{
346-
// TODO: once we remove old Xamarin public signatures we can invoke `OnChildMeasureInvalidated(VisualElement, InvalidationTrigger)` directly
347-
OnChildMeasureInvalidated(child, new InvalidationEventArgs(trigger, depth));
355+
SetNeedsLayout();
356+
InvalidateMeasureCache();
357+
358+
OnChildMeasureInvalidated(child, new InvalidationEventArgs(trigger));
359+
360+
var propagatedTrigger = GetPropagatedTrigger(trigger);
361+
InvokeMeasureInvalidated(propagatedTrigger);
362+
363+
// Behavior of legacy layouts is to always propagate the measure invalidation to the parent
364+
(Parent as VisualElement)?.OnChildMeasureInvalidated(this, propagatedTrigger);
348365
}
349366

350367
/// <summary>
@@ -356,19 +373,6 @@ internal override void OnChildMeasureInvalidatedInternal(VisualElement child, In
356373
/// <remarks>This method has a default implementation and application developers must call the base implementation.</remarks>
357374
protected void OnChildMeasureInvalidated(object sender, EventArgs e)
358375
{
359-
var depth = 0;
360-
InvalidationTrigger trigger;
361-
if (e is InvalidationEventArgs args)
362-
{
363-
trigger = args.Trigger;
364-
depth = args.CurrentInvalidationDepth;
365-
}
366-
else
367-
{
368-
trigger = InvalidationTrigger.Undefined;
369-
}
370-
371-
OnChildMeasureInvalidated((VisualElement)sender, trigger, depth);
372376
OnChildMeasureInvalidated();
373377
}
374378

@@ -542,55 +546,6 @@ internal static void LayoutChildIntoBoundingRegion(View child, Rect region, Size
542546
child.Layout(region);
543547
}
544548

545-
internal virtual void OnChildMeasureInvalidated(VisualElement child, InvalidationTrigger trigger, int depth)
546-
{
547-
IReadOnlyList<Element> children = LogicalChildrenInternal;
548-
int count = children.Count;
549-
for (var index = 0; index < count; index++)
550-
{
551-
if (LogicalChildrenInternal[index] is VisualElement v && v.IsVisible && (!v.IsPlatformEnabled || !v.IsPlatformStateConsistent))
552-
{
553-
return;
554-
}
555-
}
556-
557-
if (child is View view)
558-
{
559-
// we can ignore the request if we are either fully constrained or when the size request changes and we were already fully constrained
560-
if ((trigger == InvalidationTrigger.MeasureChanged && view.Constraint == LayoutConstraint.Fixed) ||
561-
(trigger == InvalidationTrigger.SizeRequestChanged && view.ComputedConstraint == LayoutConstraint.Fixed))
562-
{
563-
return;
564-
}
565-
if (trigger == InvalidationTrigger.HorizontalOptionsChanged || trigger == InvalidationTrigger.VerticalOptionsChanged)
566-
{
567-
ComputeConstraintForView(view);
568-
}
569-
}
570-
571-
InvalidateMeasureLegacy(trigger, depth, int.MaxValue);
572-
}
573-
574-
// This lets us override the rules for invalidation on MAUI controls that unfortunately still inheirt from the legacy layout
575-
private protected virtual void InvalidateMeasureLegacy(InvalidationTrigger trigger, int depth, int depthLeveltoInvalidate)
576-
{
577-
if (depth <= depthLeveltoInvalidate)
578-
{
579-
if (trigger == InvalidationTrigger.RendererReady)
580-
{
581-
InvalidateMeasureInternal(new InvalidationEventArgs(InvalidationTrigger.RendererReady, depth));
582-
}
583-
else
584-
{
585-
InvalidateMeasureInternal(new InvalidationEventArgs(InvalidationTrigger.MeasureChanged, depth));
586-
}
587-
}
588-
else
589-
{
590-
FireMeasureChanged(trigger, depth);
591-
}
592-
}
593-
594549
internal override void OnIsVisibleChanged(bool oldValue, bool newValue)
595550
{
596551
base.OnIsVisibleChanged(oldValue, newValue);
@@ -708,19 +663,6 @@ bool ShouldLayoutChildren()
708663
return true;
709664
}
710665

711-
protected override void InvalidateMeasureOverride()
712-
{
713-
base.InvalidateMeasureOverride();
714-
715-
foreach (var child in ((IElementController)this).LogicalChildren)
716-
{
717-
if (child is IView fe)
718-
{
719-
fe.InvalidateMeasure();
720-
}
721-
}
722-
}
723-
724666
protected override Size ArrangeOverride(Rect bounds)
725667
{
726668
base.ArrangeOverride(bounds);

src/Controls/src/Core/LegacyLayouts/StackLayout.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ protected override SizeRequest OnMeasure(double widthConstraint, double heightCo
9292
return result;
9393
}
9494

95+
internal override void OnChildMeasureInvalidated(VisualElement child, InvalidationTrigger trigger)
96+
{
97+
_layoutInformation = new LayoutInformation();
98+
base.OnChildMeasureInvalidated(child, trigger);
99+
}
100+
95101
internal override void ComputeConstraintForView(View view)
96102
{
97103
ComputeConstraintForView(view, false);
98104
}
99105

100-
internal override void InvalidateMeasureInternal(InvalidationEventArgs trigger)
106+
internal override void InvalidateMeasureInternal(InvalidationTrigger trigger)
101107
{
102108
_layoutInformation = new LayoutInformation();
103109
base.InvalidateMeasureInternal(trigger);

src/Controls/src/Core/Page/Page.cs

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,11 @@ protected override void OnBindingContextChanged()
506506
}
507507

508508

509-
internal override void OnChildMeasureInvalidatedInternal(VisualElement child, InvalidationTrigger trigger, int depth)
509+
internal override void OnChildMeasureInvalidated(VisualElement child, InvalidationTrigger trigger)
510510
{
511-
// TODO: once we remove old Xamarin public signatures we can invoke `OnChildMeasureInvalidated(VisualElement, InvalidationTrigger)` directly
512-
OnChildMeasureInvalidated(child, new InvalidationEventArgs(trigger, depth));
511+
OnChildMeasureInvalidated(child, new InvalidationEventArgs(trigger));
512+
var propagatedTrigger = GetPropagatedTrigger(trigger);
513+
InvokeMeasureInvalidated(propagatedTrigger);
513514
}
514515

515516
/// <summary>
@@ -519,19 +520,6 @@ internal override void OnChildMeasureInvalidatedInternal(VisualElement child, In
519520
/// <param name="e">The event arguments.</param>
520521
protected virtual void OnChildMeasureInvalidated(object sender, EventArgs e)
521522
{
522-
var depth = 0;
523-
InvalidationTrigger trigger;
524-
if (e is InvalidationEventArgs args)
525-
{
526-
trigger = args.Trigger;
527-
depth = args.CurrentInvalidationDepth;
528-
}
529-
else
530-
{
531-
trigger = InvalidationTrigger.Undefined;
532-
}
533-
534-
OnChildMeasureInvalidated((VisualElement)sender, trigger, depth);
535523
}
536524

537525
/// <summary>
@@ -610,36 +598,6 @@ protected void UpdateChildrenLayout()
610598
}
611599
}
612600

613-
internal virtual void OnChildMeasureInvalidated(VisualElement child, InvalidationTrigger trigger, int depth)
614-
{
615-
var container = this as IPageContainer<Page>;
616-
if (container != null)
617-
{
618-
Page page = container.CurrentPage;
619-
if (page != null && page.IsVisible && (!page.IsPlatformEnabled || !page.IsPlatformStateConsistent))
620-
return;
621-
}
622-
else
623-
{
624-
var logicalChildren = this.InternalChildren;
625-
for (var i = 0; i < logicalChildren.Count; i++)
626-
{
627-
var v = logicalChildren[i] as VisualElement;
628-
if (v != null && v.IsVisible && (!v.IsPlatformEnabled || !v.IsPlatformStateConsistent))
629-
return;
630-
}
631-
}
632-
633-
if (depth <= 1)
634-
{
635-
InvalidateMeasureInternal(new InvalidationEventArgs(InvalidationTrigger.MeasureChanged, depth));
636-
}
637-
else
638-
{
639-
FireMeasureChanged(trigger, depth);
640-
}
641-
}
642-
643601
internal void OnAppearing(Action action)
644602
{
645603
if (_hasAppeared)

src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const Microsoft.Maui.Controls.TitleBar.TrailingHiddenState = "TrailingContentCol
6969
const Microsoft.Maui.Controls.TitleBar.TrailingVisibleState = "TrailingContentVisible" -> string!
7070
Microsoft.Maui.Controls.Embedding.EmbeddingExtensions
7171
Microsoft.Maui.Controls.HandlerProperties
72+
*REMOVED*override Microsoft.Maui.Controls.Compatibility.Layout.InvalidateMeasureOverride() -> void
7273
Microsoft.Maui.Controls.HybridWebView
7374
Microsoft.Maui.Controls.HybridWebView.DefaultFile.get -> string?
7475
Microsoft.Maui.Controls.HybridWebView.DefaultFile.set -> void

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ const Microsoft.Maui.Controls.TitleBar.TrailingHiddenState = "TrailingContentCol
206206
const Microsoft.Maui.Controls.TitleBar.TrailingVisibleState = "TrailingContentVisible" -> string!
207207
Microsoft.Maui.Controls.Embedding.EmbeddingExtensions
208208
Microsoft.Maui.Controls.HandlerProperties
209+
*REMOVED*override Microsoft.Maui.Controls.Compatibility.Layout.InvalidateMeasureOverride() -> void
209210
*REMOVED*Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker
210211
*REMOVED*Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker.Dispose() -> void
211212
*REMOVED*Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker.OnLayoutSubviews() -> void

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ const Microsoft.Maui.Controls.TitleBar.TrailingHiddenState = "TrailingContentCol
207207
const Microsoft.Maui.Controls.TitleBar.TrailingVisibleState = "TrailingContentVisible" -> string!
208208
Microsoft.Maui.Controls.Embedding.EmbeddingExtensions
209209
Microsoft.Maui.Controls.HandlerProperties
210+
*REMOVED*override Microsoft.Maui.Controls.Compatibility.Layout.InvalidateMeasureOverride() -> void
210211
*REMOVED*Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker
211212
*REMOVED*Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker.Dispose() -> void
212213
*REMOVED*Microsoft.Maui.Controls.Handlers.Compatibility.ShellScrollViewTracker.OnLayoutSubviews() -> void

src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const Microsoft.Maui.Controls.TitleBar.TitleVisibleState = "TitleVisible" -> str
6868
const Microsoft.Maui.Controls.TitleBar.TrailingHiddenState = "TrailingContentCollapsed" -> string!
6969
const Microsoft.Maui.Controls.TitleBar.TrailingVisibleState = "TrailingContentVisible" -> string!
7070
Microsoft.Maui.Controls.HandlerProperties
71+
*REMOVED*override Microsoft.Maui.Controls.Compatibility.Layout.InvalidateMeasureOverride() -> void
7172
Microsoft.Maui.Controls.HybridWebView
7273
Microsoft.Maui.Controls.HybridWebView.DefaultFile.get -> string?
7374
Microsoft.Maui.Controls.HybridWebView.DefaultFile.set -> void

src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const Microsoft.Maui.Controls.TitleBar.TrailingHiddenState = "TrailingContentCol
7070
const Microsoft.Maui.Controls.TitleBar.TrailingVisibleState = "TrailingContentVisible" -> string!
7171
Microsoft.Maui.Controls.Embedding.EmbeddingExtensions
7272
Microsoft.Maui.Controls.HandlerProperties
73+
*REMOVED*override Microsoft.Maui.Controls.Compatibility.Layout.InvalidateMeasureOverride() -> void
7374
Microsoft.Maui.Controls.HybridWebView
7475
Microsoft.Maui.Controls.HybridWebView.DefaultFile.get -> string?
7576
Microsoft.Maui.Controls.HybridWebView.DefaultFile.set -> void

0 commit comments

Comments
 (0)