From af8add0c51d9c62294782a040e0a51f104676725 Mon Sep 17 00:00:00 2001 From: praveenkumarkarunanithi Date: Fri, 3 Oct 2025 17:49:14 +0530 Subject: [PATCH 1/6] fix updated. --- .../NavigationPage/NavigationPageToolbar.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs index 54c9ff6e41b9..2c84f6a7008d 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs @@ -34,6 +34,15 @@ public NavigationPageToolbar(Maui.IElement parent, Page rootPage) : base(parent) RootPage = rootPage; _toolbarTracker.PageAppearing += OnPageAppearing; _toolbarTracker.Target = RootPage; + +#if ANDROID || WINDOWS + // Subscribe to orientation changes to update FlyoutPage toolbar button visibility + // Android/Windows need manual orientation detection, iOS/Mac handle this automatically + if (parent is FlyoutPage) + { + Microsoft.Maui.Devices.DeviceDisplay.MainDisplayInfoChanged += OnOrientationChanged; + } +#endif } void OnToolbarItemsChanged(object sender, EventArgs e) @@ -41,6 +50,17 @@ void OnToolbarItemsChanged(object sender, EventArgs e) ToolbarItems = _toolbarTracker.ToolbarItems; } +#if ANDROID || WINDOWS + void OnOrientationChanged(object sender, Microsoft.Maui.Devices.DisplayInfoChangedEventArgs e) + { + // Re-evaluate toolbar button visibility when orientation changes + if (_currentNavigationPage is not null) + { + ApplyChanges(_currentNavigationPage); + } + } +#endif + void OnPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.IsOneOf(NavigationPage.HasNavigationBarProperty, @@ -328,6 +348,13 @@ internal void Disconnect() navPage.ChildRemoved -= NavigationPageChildrenChanged; } } + +#if ANDROID || WINDOWS + if (Parent is FlyoutPage) + { + Microsoft.Maui.Devices.DeviceDisplay.MainDisplayInfoChanged -= OnOrientationChanged; + } +#endif } } } From fe5ef77e8e8c12be229e503a949ec1fe009b00c3 Mon Sep 17 00:00:00 2001 From: praveenkumarkarunanithi Date: Mon, 6 Oct 2025 11:11:19 +0530 Subject: [PATCH 2/6] updated test case --- .../TestCases.HostApp/Issues/Issue24468.cs | 55 +++++++++++++++++++ .../Tests/Issues/Issue24468.cs | 26 +++++++++ 2 files changed, 81 insertions(+) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs new file mode 100644 index 000000000000..710070aeeb22 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs @@ -0,0 +1,55 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 24468, "FlyoutPage toolbar button not updating on orientation change on Android", + PlatformAffected.Android)] +public class Issue24468 : TestFlyoutPage +{ + private Label _statusLabel; + private int _callCount = 0; + + protected override void Init() + { + Title = "Issue 24468"; + + _statusLabel = new Label + { + Text = "ShouldShowToolbarButton is not called", + AutomationId = "StatusLabel" + }; + + Flyout = new ContentPage + { + Title = "Menu", + Content = new Label { Text = "Flyout Menu" } + }; + + Detail = new NavigationPage(new ContentPage + { + Title = "Detail", + Content = new StackLayout + { + Children = + { + new Label { Text = "Rotate device to test toolbar button updates" }, + _statusLabel + } + }, + AutomationId = "ContentPage" + }); + + FlyoutLayoutBehavior = FlyoutLayoutBehavior.SplitOnLandscape; + } + + public override bool ShouldShowToolbarButton() + { + _callCount++; + var shouldShow = base.ShouldShowToolbarButton(); + + if (_callCount > 1) + { + _statusLabel.Text = "ShouldShowToolbarButton is called"; + } + + return shouldShow; + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs new file mode 100644 index 000000000000..e8163b6a33fa --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs @@ -0,0 +1,26 @@ +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; +public class Issue24468 : _IssuesUITest +{ + public Issue24468(TestDevice device) : base(device) + { + } + + public override string Issue => "FlyoutPage toolbar button not updating on orientation change on Android"; + +#if ANDROID || IOS //The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms iOS and Android. + [Test] + [Category(UITestCategories.Navigation)] + public void FlyoutPageToolbarButtonUpdatesOnOrientationChange() + { + App.WaitForElement("ContentPage"); + + App.SetOrientationLandscape(); + + var text = App.FindElement("StatusLabel").GetText(); + Assert.That(text, Contains.Substring("ShouldShowToolbarButton is called")); + App.SetOrientationPortrait(); + } +#endif +} From d2d2f06750a3f3912360bdf1b685c302f6974e0a Mon Sep 17 00:00:00 2001 From: praveenkumarkarunanithi Date: Fri, 10 Oct 2025 12:54:01 +0530 Subject: [PATCH 3/6] Update Issue24468.cs --- .../tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs index e8163b6a33fa..4707133f13f4 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs @@ -1,3 +1,4 @@ +#if ANDROID || IOS //The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms iOS and Android. using UITest.Core; namespace Microsoft.Maui.TestCases.Tests.Issues; @@ -8,8 +9,6 @@ public Issue24468(TestDevice device) : base(device) } public override string Issue => "FlyoutPage toolbar button not updating on orientation change on Android"; - -#if ANDROID || IOS //The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms iOS and Android. [Test] [Category(UITestCategories.Navigation)] public void FlyoutPageToolbarButtonUpdatesOnOrientationChange() @@ -22,5 +21,5 @@ public void FlyoutPageToolbarButtonUpdatesOnOrientationChange() Assert.That(text, Contains.Substring("ShouldShowToolbarButton is called")); App.SetOrientationPortrait(); } -#endif } +#endif From c52062e5fc7cc9bac89ed41535093490dcb536ac Mon Sep 17 00:00:00 2001 From: praveenkumarkarunanithi Date: Tue, 14 Oct 2025 17:53:40 +0530 Subject: [PATCH 4/6] updated try and finally block --- .../Tests/Issues/Issue24468.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs index 4707133f13f4..fda8041bdc6f 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs @@ -1,4 +1,6 @@ #if ANDROID || IOS //The test fails on Windows and MacCatalyst because the SetOrientation method, which is intended to change the device orientation, is only supported on mobile platforms iOS and Android. +using NUnit.Framework; +using UITest.Appium; using UITest.Core; namespace Microsoft.Maui.TestCases.Tests.Issues; @@ -15,11 +17,17 @@ public void FlyoutPageToolbarButtonUpdatesOnOrientationChange() { App.WaitForElement("ContentPage"); - App.SetOrientationLandscape(); + try + { + App.SetOrientationLandscape(); - var text = App.FindElement("StatusLabel").GetText(); - Assert.That(text, Contains.Substring("ShouldShowToolbarButton is called")); - App.SetOrientationPortrait(); + var text = App.FindElement("StatusLabel").GetText(); + Assert.That(text, Contains.Substring("ShouldShowToolbarButton is called")); + } + finally + { + App.SetOrientationPortrait(); + } } } #endif From 584b9d2703051b66b20ee224f193850448be9835 Mon Sep 17 00:00:00 2001 From: praveenkumarkarunanithi Date: Tue, 28 Oct 2025 13:14:43 +0530 Subject: [PATCH 5/6] test case updates. --- .../TestCases.HostApp/Issues/Issue24468.cs | 19 ++++++++++++++----- .../Tests/Issues/Issue24468.cs | 12 ++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs index 710070aeeb22..fe4caead8531 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs @@ -4,17 +4,24 @@ namespace Maui.Controls.Sample.Issues; PlatformAffected.Android)] public class Issue24468 : TestFlyoutPage { - private Label _statusLabel; + private Label _eventLabel; + private Label _countLabel; private int _callCount = 0; protected override void Init() { Title = "Issue 24468"; - _statusLabel = new Label + _eventLabel = new Label { Text = "ShouldShowToolbarButton is not called", - AutomationId = "StatusLabel" + AutomationId = "EventLabel" + }; + + _countLabel = new Label + { + Text = "0", + AutomationId = "CountLabel" }; Flyout = new ContentPage @@ -31,7 +38,8 @@ protected override void Init() Children = { new Label { Text = "Rotate device to test toolbar button updates" }, - _statusLabel + _eventLabel, + _countLabel } }, AutomationId = "ContentPage" @@ -47,7 +55,8 @@ public override bool ShouldShowToolbarButton() if (_callCount > 1) { - _statusLabel.Text = "ShouldShowToolbarButton is called"; + _eventLabel.Text = "ShouldShowToolbarButton called"; + _countLabel.Text = _callCount.ToString(); } return shouldShow; diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs index fda8041bdc6f..3a94405423b5 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs @@ -15,14 +15,18 @@ public Issue24468(TestDevice device) : base(device) [Category(UITestCategories.Navigation)] public void FlyoutPageToolbarButtonUpdatesOnOrientationChange() { + App.SetOrientationLandscape(); App.WaitForElement("ContentPage"); try { - App.SetOrientationLandscape(); - - var text = App.FindElement("StatusLabel").GetText(); - Assert.That(text, Contains.Substring("ShouldShowToolbarButton is called")); + App.WaitForElement("EventLabel"); + var eventText = App.FindElement("EventLabel").GetText(); + Assert.That(eventText, Is.EqualTo("ShouldShowToolbarButton called")); + + var callCount = int.Parse(App.FindElement("CountLabel").GetText() ?? "0"); + Assert.That(callCount, Is.GreaterThan(1).And.LessThan(5), + $"Expected call count between 2-4, but got {callCount}. Method should not be called excessively."); } finally { From 5e35085f1e68c3c951b581c960f48a1725732251 Mon Sep 17 00:00:00 2001 From: praveenkumarkarunanithi Date: Wed, 18 Feb 2026 15:50:58 +0530 Subject: [PATCH 6/6] updated fix as per Agent try-fix analysis --- .../src/Core/FlyoutPage/FlyoutPage.cs | 6 ++++ .../NavigationPage/NavigationPageToolbar.cs | 30 ++----------------- .../TestCases.HostApp/Issues/Issue24468.cs | 4 +-- .../Tests/Issues/Issue24468.cs | 2 +- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs index c2570bdfb132..580652749e05 100644 --- a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs +++ b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs @@ -351,6 +351,12 @@ void OnWindowChanged(object sender, EventArgs e) void OnMainDisplayInfoChanged(object sender, DisplayInfoChangedEventArgs e) { Handler?.UpdateValue(nameof(FlyoutBehavior)); + +#if ANDROID || WINDOWS + // Trigger toolbar re-evaluation on orientation change. iOS handles this natively + // via PhoneFlyoutPageRenderer.ViewWillTransitionToSize(). + OnPropertyChanged(nameof(FlyoutLayoutBehavior)); +#endif } IView IFlyoutView.Flyout => this.Flyout; diff --git a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs index 2c84f6a7008d..5933f6f3445d 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs @@ -34,15 +34,6 @@ public NavigationPageToolbar(Maui.IElement parent, Page rootPage) : base(parent) RootPage = rootPage; _toolbarTracker.PageAppearing += OnPageAppearing; _toolbarTracker.Target = RootPage; - -#if ANDROID || WINDOWS - // Subscribe to orientation changes to update FlyoutPage toolbar button visibility - // Android/Windows need manual orientation detection, iOS/Mac handle this automatically - if (parent is FlyoutPage) - { - Microsoft.Maui.Devices.DeviceDisplay.MainDisplayInfoChanged += OnOrientationChanged; - } -#endif } void OnToolbarItemsChanged(object sender, EventArgs e) @@ -50,17 +41,6 @@ void OnToolbarItemsChanged(object sender, EventArgs e) ToolbarItems = _toolbarTracker.ToolbarItems; } -#if ANDROID || WINDOWS - void OnOrientationChanged(object sender, Microsoft.Maui.Devices.DisplayInfoChangedEventArgs e) - { - // Re-evaluate toolbar button visibility when orientation changes - if (_currentNavigationPage is not null) - { - ApplyChanges(_currentNavigationPage); - } - } -#endif - void OnPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.IsOneOf(NavigationPage.HasNavigationBarProperty, @@ -75,7 +55,8 @@ void OnPagePropertyChanged(object sender, System.ComponentModel.PropertyChangedE NavigationPage.BarTextColorProperty) || e.IsOneOf( PlatformConfiguration.WindowsSpecific.Page.ToolbarDynamicOverflowEnabledProperty, - PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty)) + PlatformConfiguration.WindowsSpecific.Page.ToolbarPlacementProperty) || + e.Is(FlyoutPage.FlyoutLayoutBehaviorProperty)) { ApplyChanges(_currentNavigationPage); } @@ -348,13 +329,6 @@ internal void Disconnect() navPage.ChildRemoved -= NavigationPageChildrenChanged; } } - -#if ANDROID || WINDOWS - if (Parent is FlyoutPage) - { - Microsoft.Maui.Devices.DeviceDisplay.MainDisplayInfoChanged -= OnOrientationChanged; - } -#endif } } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs index fe4caead8531..a007ab9a93a7 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs @@ -1,7 +1,7 @@ namespace Maui.Controls.Sample.Issues; -[Issue(IssueTracker.Github, 24468, "FlyoutPage toolbar button not updating on orientation change on Android", - PlatformAffected.Android)] +[Issue(IssueTracker.Github, 24468, "FlyoutPage toolbar button not updating on orientation change on Android and Windows", + PlatformAffected.Android | PlatformAffected.UWP)] public class Issue24468 : TestFlyoutPage { private Label _eventLabel; diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs index 3a94405423b5..a9f7b4505085 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs @@ -10,7 +10,7 @@ public Issue24468(TestDevice device) : base(device) { } - public override string Issue => "FlyoutPage toolbar button not updating on orientation change on Android"; + public override string Issue => "FlyoutPage toolbar button not updating on orientation change on Android and Windows"; [Test] [Category(UITestCategories.Navigation)] public void FlyoutPageToolbarButtonUpdatesOnOrientationChange()