Skip to content

[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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

BagavathiPerumal
Copy link
Contributor

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.

  • Windows
  • Mac
  • iOS
  • Android

Issues Fixed

Fixes #22045

Output

Before Issue Fix After Issue Fix
BeforeFix-OnSizeAllocated.mov
AfterFix-OnSizeAllocated.mov

…awerOpened event and updating Content so OnSizeAllocated is called with correct values when drawer opens.
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Jun 19, 2025
Copy link
Contributor

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.

@dotnet-policy-service dotnet-policy-service bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Jun 19, 2025
@BagavathiPerumal BagavathiPerumal marked this pull request as ready for review June 20, 2025 04:48
@Copilot Copilot AI review requested due to automatic review settings June 20, 2025 04:48
@BagavathiPerumal BagavathiPerumal requested a review from a team as a code owner June 20, 2025 04:48
Copy link
Contributor

@Copilot Copilot AI left a 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.

Comment on lines +472 to +476
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();
Copy link
Preview

Copilot AI Jun 20, 2025

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.

Suggested change
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.

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] OnSizeAllocated not reported for Android AppShell Flyout content
3 participants