Skip to content

[iOS] [MacCatalyst] Provide an API through which SetNeedsLayout can be intercepted when InvalidateMeasure is invoked #28410

@APopatanasov

Description

@APopatanasov

Description

After #26629, the behavior of SetNeedsLayout in .NET MAUI’s iOS platform has changed. Previously, I could override SetNeedsLayout in a custom MauiView (MauiView.cs#L142) to intercept SetNeedsLayout calls propagating to the Superview. This allowed me to prevent unnecessary Arrange calls in my custom xplat layouts by controlling the layout updates.

The change in #26629 moved this logic out of SetNeedsLayout, breaking my ability to intercept and filter these calls. Additionally, I need similar control over InvalidateAncestorsMeasures, such as in MauiScrollView’s LayoutSubviews method (MauiScrollView.cs#L62). When ContentSize changes, InvalidateAncestorsMeasures triggers SetNeedsLayout up the view hierarchy, and I want to prevent this propagation in certain cases to optimize performance.

Public API Changes

  1. Intercept and optionally cancel SetNeedsLayout calls triggered by InvalidateMeasure, restoring the ability to customize layout updates.
  2. Hook into InvalidateAncestorsMeasures to control whether SetNeedsLayout propagates up the tree.

This would enable more efficient layout handling in custom controls, avoiding redundant Arrange calls.

Intended Use-Case

Intercepting SetNeedsLayout lets me skip updates when measurements are unchanged, eliminating unnecessary Arrange calls. Likewise, in MauiScrollView, blocking InvalidateAncestorsMeasures from triggering SetNeedsLayout - when ContentSize shifts but the scroll frame stays fixed - boosts scrolling performance for specific scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterproposal/open

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions