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 54c9ff6e41b9..5933f6f3445d 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs @@ -55,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); } 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..a007ab9a93a7 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue24468.cs @@ -0,0 +1,64 @@ +namespace Maui.Controls.Sample.Issues; + +[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; + private Label _countLabel; + private int _callCount = 0; + + protected override void Init() + { + Title = "Issue 24468"; + + _eventLabel = new Label + { + Text = "ShouldShowToolbarButton is not called", + AutomationId = "EventLabel" + }; + + _countLabel = new Label + { + Text = "0", + AutomationId = "CountLabel" + }; + + 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" }, + _eventLabel, + _countLabel + } + }, + AutomationId = "ContentPage" + }); + + FlyoutLayoutBehavior = FlyoutLayoutBehavior.SplitOnLandscape; + } + + public override bool ShouldShowToolbarButton() + { + _callCount++; + var shouldShow = base.ShouldShowToolbarButton(); + + if (_callCount > 1) + { + _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 new file mode 100644 index 000000000000..a9f7b4505085 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24468.cs @@ -0,0 +1,37 @@ +#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; +public class Issue24468 : _IssuesUITest +{ + public Issue24468(TestDevice device) : base(device) + { + } + + public override string Issue => "FlyoutPage toolbar button not updating on orientation change on Android and Windows"; + [Test] + [Category(UITestCategories.Navigation)] + public void FlyoutPageToolbarButtonUpdatesOnOrientationChange() + { + App.SetOrientationLandscape(); + App.WaitForElement("ContentPage"); + + try + { + 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 + { + App.SetOrientationPortrait(); + } + } +} +#endif