-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Android] Fix for OnSizeAllocated is not reported for Android AppShell Flyout content. #30069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…awerOpened event and updating Content so OnSizeAllocated is called with correct values when drawer opens.
Hey there @@BagavathiPerumal! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue on Android where the ContentView within Shell.FlyoutContent is not being properly measured, causing OnSizeAllocated to report zero dimensions. The changes include new tests for Issue22045, updates to the HostApp to use the new flyout content, and a refactoring in ShellFlyoutTemplatedContentRenderer.cs to correctly update the content frame.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22045.cs | Added automated test for validating non-zero width and height in flyout content. |
src/Controls/tests/TestCases.HostApp/Issues/Issue22045.cs | Updated HostApp to include the new flyout content and trigger the measurement logic. |
src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutTemplatedContentRenderer.cs | Refactored code to extract frame updating into SetContentViewFrame() and added a fallback condition in OnFlyoutViewLayoutChanging to handle cases with zero frame dimensions. |
else if (_contentView?.PlatformView is not null && | ||
((_contentView.PlatformView.MeasuredHeight > 0 && _contentView.View.Frame.Width == 0) || | ||
(_contentView.PlatformView.MeasuredWidth > 0 && _contentView.View.Frame.Height == 0))) | ||
{ | ||
SetContentViewFrame(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compound condition checking for measured dimensions and zero frame values could be refactored into a well-named boolean variable or helper method to improve readability.
else if (_contentView?.PlatformView is not null && | |
((_contentView.PlatformView.MeasuredHeight > 0 && _contentView.View.Frame.Width == 0) || | |
(_contentView.PlatformView.MeasuredWidth > 0 && _contentView.View.Frame.Height == 0))) | |
{ | |
SetContentViewFrame(); | |
else | |
{ | |
bool ShouldSetContentViewFrame = _contentView?.PlatformView is not null && | |
((_contentView.PlatformView.MeasuredHeight > 0 && _contentView.View.Frame.Width == 0) || | |
(_contentView.PlatformView.MeasuredWidth > 0 && _contentView.View.Frame.Height == 0)); | |
if (ShouldSetContentViewFrame) | |
{ | |
SetContentViewFrame(); | |
} |
Copilot uses AI. Check for mistakes.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Root cause
The issue arises because, in .NET MAUI on Android, when a ContentView is placed inside Shell.FlyoutContent with FlyoutBehavior values set as Flyout, the Android layout system does not fully measure and lay out the flyout content at the appropriate time. As a result, the OnSizeAllocated method receives zero values for width and height, and OnFlyoutViewLayoutChanging() is triggered before the view is fully measured. This prevents the correct dimensions from being propagated, so the layout system does not update the content size as expected.
Description of Issue Fix
The fix involves updating the ContentView frame inside the OnFlyoutViewLayoutChanging() method after the view has been measured, ensuring that the correct width and height are applied to the content, allowing the layout system to update the content size properly and display the content as expected.
Tested the behavior in the following platforms.
Issues Fixed
Fixes #22045
Output
BeforeFix-OnSizeAllocated.mov
AfterFix-OnSizeAllocated.mov