Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
Page.SendAppearing();
if (!_intialLayoutFinished)
{
_intialLayoutFinished = true;
SetInitialPresented();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewDidAppear() is much later in the lifecycle. Not a problem, but this could cause a visible delay where the flyout opens after the user sees the page.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@devanathan-vaithiyanathan if you do it via IUIViewLifeCycleEvents does ethat cause less delay?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen , PhoneFlyoutPageRenderer is derived from UIViewController, not UIView. Therefore, overriding MovedToWindow isn’t possible, and invoking the MovedToWindow event handler isn’t applicable in this case.

}
}

public override void ViewDidDisappear(bool animated)
Expand Down Expand Up @@ -158,19 +163,6 @@ void SetInitialPresented()
UpdateLeftBarButton();
}

public override void ViewWillLayoutSubviews()
{
// Orientation doesn't seem to be set to a stable correct value until here.
// So, we officially process orientation here.
if (!_intialLayoutFinished)
{
_intialLayoutFinished = true;
SetInitialPresented();
}

base.ViewWillLayoutSubviews();
}

public override void ViewDidLoad()
{
base.ViewDidLoad();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.ViewWillLayoutSubviews() -> void
~Microsoft.Maui.Controls.Element.transientNamescope -> Microsoft.Maui.Controls.Internals.INameScope
Microsoft.Maui.Controls.FlexLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Controls.ContentPresenter.OnSizeAllocated(double width, double height) -> void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.ViewWillLayoutSubviews() -> void
~Microsoft.Maui.Controls.Element.transientNamescope -> Microsoft.Maui.Controls.Internals.INameScope
Microsoft.Maui.Controls.FlexLayout.CrossPlatformMeasure(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Controls.ContentPresenter.OnSizeAllocated(double width, double height) -> void
Expand Down
59 changes: 59 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31372.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 31372, "IsPresented=true Not Working on Initial Value in FlyoutPage", PlatformAffected.UWP | PlatformAffected.macOS)]

public class Issue31372 : NavigationPage
{
public Issue31372()
{
PushAsync(new Issue31372Page());
}
}

public class Issue31372Page : FlyoutPage
{
public Issue31372Page()
{

// Create Flyout Page
var flyoutPage = new ContentPage
{
Title = "Flyout",
Content = new StackLayout
{
Children =
{
new Label
{
Text = "This is Flyout",
AutomationId = "FlyoutLabel"
}
}
}
};

// Create Detail Page
var detailPage = new ContentPage
{
Title = "Detailpage",
Content = new StackLayout
{
Padding = 16,
Spacing = 16,
Children =
{
new Label
{
Text = "This is Detail Page which displays additional information."
},
}
}
};

// Assign Flyout and Detail
Flyout = flyoutPage;
Detail = new NavigationPage(detailPage);
FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover;
IsPresented = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue31372 : _IssuesUITest
{
public override string Issue => "IsPresented=true Not Working on Initial Value in FlyoutPage";

public Issue31372(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.FlyoutPage)]
public void VerifyIsPresentedInitialValue()
{
App.WaitForElement("FlyoutLabel");
}
}
}
10 changes: 10 additions & 0 deletions src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,22 @@ protected override void ConnectHandler(RootNavigationView platformView)
_navigationRootManager = MauiContext?.GetNavigationRootManager();
platformView.PaneOpened += OnPaneOpened;
platformView.PaneClosed += OnPaneClosed;
platformView.Loaded += OnLoaded;
}

void OnLoaded(object sender, RoutedEventArgs e)
{
if (VirtualView is not null)
{
PlatformView.IsPaneOpen = VirtualView.IsPresented;
}
}
Comment on lines +27 to 33
Copy link

Copilot AI Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The OnLoaded event handler will fire every time the control is loaded, but the IsPresented synchronization only needs to happen once. Consider unsubscribing from the Loaded event after the first execution to avoid unnecessary repeated executions.

Copilot uses AI. Check for mistakes.

protected override void DisconnectHandler(RootNavigationView platformView)
{
platformView.PaneOpened -= OnPaneOpened;
platformView.PaneClosed -= OnPaneClosed;
platformView.Loaded -= OnLoaded;
}

void OnPaneOpened(NavigationView sender, object args)
Expand Down
Loading