@@ -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 ) ;
0 commit comments