Skip to content

Commit 3fce1b2

Browse files
Fixed-ToolBar-Visibility-FlyoutPage (#28209)
1 parent f673046 commit 3fce1b2

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/Controls/src/Core/NavigationPage/NavigationPageToolbar.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ void OnPageAppearing(object sender, EventArgs e)
7070
if (sender is not ContentPage cp)
7171
return;
7272

73+
var pages = cp.GetParentPages();
74+
Page previous = null;
75+
foreach (var page in pages)
76+
{
77+
if (page is FlyoutPage fp)
78+
{
79+
if (fp.Flyout == cp || previous == fp.Flyout)
80+
return;
81+
}
82+
previous = page;
83+
}
84+
7385
_toolbarTracker.PagePropertyChanged -= OnPagePropertyChanged;
7486
_currentPage = cp;
7587
_currentNavigationPage = _currentPage.FindParentOfType<NavigationPage>();

src/Controls/tests/Core.UnitTests/FlyoutPageUnitTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Threading.Tasks;
23
using Microsoft.Maui.Controls.Internals;
34
using Microsoft.Maui.Devices;
45
using Microsoft.Maui.Graphics;
@@ -463,6 +464,59 @@ public void FlyoutPageAppearingAndDisappearingPropagatesToDetail()
463464
Assert.Equal(1, disappearing);
464465
Assert.Equal(1, appearing);
465466
}
467+
468+
[Theory]
469+
[InlineData(0)]
470+
[InlineData(1)]
471+
[InlineData(2)]
472+
[InlineData(3)]
473+
public async Task VerifyToolbarButtonVisibilityWhenFlyoutReset(int depth)
474+
{
475+
ContentPage detailContentPage = new ContentPage();
476+
477+
Page flyout = new ContentPage()
478+
{
479+
Title = "Initial Flyout"
480+
};
481+
482+
NavigationPage.SetHasNavigationBar(flyout, false);
483+
484+
var flyoutContentPage = flyout;
485+
486+
for (int i = 0; i < depth; i++)
487+
{
488+
flyout = new NavigationPage(flyout)
489+
{
490+
Title = "Flyout " + i
491+
};
492+
}
493+
494+
FlyoutPage flyoutPage = new FlyoutPage
495+
{
496+
Flyout = flyout,
497+
Detail = new NavigationPage(detailContentPage)
498+
};
499+
500+
_ = new TestWindow(flyoutPage);
501+
502+
Toolbar flyoutToolBar = flyoutPage.Toolbar;
503+
Assert.True(flyoutToolBar.IsVisible);
504+
505+
if (depth >= 1)
506+
{
507+
var page = new ContentPage();
508+
NavigationPage.SetHasNavigationBar(page, false);
509+
await flyoutContentPage.Navigation.PushAsync(page);
510+
}
511+
else
512+
{
513+
var page = new ContentPage { Title = "Reborn Flyout" };
514+
NavigationPage.SetHasNavigationBar(page, false);
515+
flyoutPage.Flyout = new ContentPage { Title = "Reborn Flyout" };
516+
}
517+
518+
Assert.True(flyoutToolBar.IsVisible);
519+
}
466520
}
467521

468522
}

0 commit comments

Comments
 (0)