maui icon indicating copy to clipboard operation
maui copied to clipboard

.NET MAUI regression: OnSizeAllocated not called on position change in AbsoluteLayout (v9.0.40+)

Open KishoreJey opened this issue 5 months ago • 5 comments

Description

In .NET MAUI version 9.0.50 and above, the View.OnSizeAllocated method is no longer invoked when a view’s position changes using AbsoluteLayout.SetLayoutBounds, but its size remains the same. This is a regression from version 9.0.40, where OnSizeAllocated would be triggered even when the view’s position was updated. This change in behavior breaks custom views that rely on OnSizeAllocated to perform updates based on layout position or visibility logic.

Version : 9.0.40

https://github.com/user-attachments/assets/66a1c209-49e9-4310-98b7-6300274b741c

Version : 9.0.51

https://github.com/user-attachments/assets/8674f957-1989-46f3-b3e5-4331985506a5

Issue Reproduceable Sample :

SimpleSample.zip

Steps to Reproduce

  1. Create a custom view by extending from View and override OnSizeAllocated.
  2. Add it to an AbsoluteLayout with initial bounds (position and size).
  3. Use a button to change only the position (not the size) of the view.
  4. Observe that OnSizeAllocated is not called in version 9.0.50 and above versions, but is called in version 9.0.40.

Link to public reproduction project repository

No response

Version with bug

9.0.50 SR5

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.40 SR4

Affected platforms

Android, iOS, Windows, macOS

Affected platform versions

No response

Did you find any workaround?

NA

Relevant log output


KishoreJey avatar Jun 16 '25 06:06 KishoreJey

This issue has been verified in Visual Studio Code 1.99.3 with MAUI versions (9.0.80, 9.0.70 & 9.0.51), This issue has been reproduced. The issue is not reproducible in MAUI version 9.0.40 or earlier.

SuthiYuvaraj avatar Jun 16 '25 10:06 SuthiYuvaraj

I see the code that calls it is wrapped with a if (previousHeight != Height || previousWidth != Width):

https://github.com/dotnet/maui/blob/bc16a0697c5003b1447afc48d028b82794334517/src/Controls/src/Core/VisualElement/VisualElement.cs#L1773-L1777

This is correct since the size has not changed. This was an optimization that was made in https://github.com/dotnet/maui/pull/27476

Why trigger a "size has changed" event when the size has not, in fact, changed.

This is a behaviour change, so I can understand the break for you. But, let me see what the folks have to say about an alternative "Frame has changed" or "parent has changed" events.

mattleibow avatar Jun 16 '25 14:06 mattleibow

~~@KishoreJey if you use ArrangeOverride does that give you what you need?~~

Nevermind

Still reviewing

PureWeen avatar Jun 16 '25 14:06 PureWeen

@KishoreJey as @mattleibow noted we fixed that event to fire more accurate to its name.

If you want an override to use ArrangeOverride will fire everytime the frame is moved

Image

PureWeen avatar Jun 16 '25 14:06 PureWeen

Hi @@KishoreJey. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.