Skip to content

Commit

Permalink
(Windows) Fix backbutton not being drawn for other NavigationPages (#…
Browse files Browse the repository at this point in the history
…18451)

* Fix toolbar not being cleared on the flyoutpage, and make sure bindings get updated on the root nav view when the toolbar changes

* Add tests

---------

Co-authored-by: Mike Corsaro <mikecorsaro@microsoft.com>
  • Loading branch information
Foda and Mike Corsaro committed Nov 1, 2023
1 parent c745e23 commit fb82b83
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Controls/src/Core/NavigationPage/NavigationPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ void OnWindowChanged(object sender, EventArgs e)
{
w.Toolbar = null;
}

var flyoutPage = _toolbar.FindParentOfType<FlyoutPage>();
if (flyoutPage != null && flyoutPage.Parent is IWindow)
{
flyoutPage.Toolbar = null;
}

_toolbar.Disconnect();
_toolbar = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ public async Task BackButtonEnabledChangesWithPushPop()
});
}

[Fact(DisplayName = "Back Button Enabled Changes with push/pop + page change")]
public async Task BackButtonEnabledChangesWithPushPopAndPageChanges()
{
SetupBuilder();

var flyoutPage = new FlyoutPage();
flyoutPage.Title = "Hello world";
flyoutPage.FlyoutLayoutBehavior = FlyoutLayoutBehavior.Split;
flyoutPage.Flyout = new ContentPage() { Title = "Hello world" };

var first = new NavigationPage(new ContentPage());
var second = new NavigationPage(new ContentPage());

flyoutPage.Detail = first;

await CreateHandlerAndAddToWindow<FlyoutViewHandler>(flyoutPage, async (handler) =>
{
var navView = (RootNavigationView)GetMauiNavigationView(handler.MauiContext);
Assert.False(navView.IsBackEnabled);
await first.PushAsync(new ContentPage());
Assert.True(navView.IsBackEnabled);
flyoutPage.Detail = second;
Assert.False(navView.IsBackEnabled);
await second.PushAsync(new ContentPage());
Assert.True(navView.IsBackEnabled);
});
}

[Fact(DisplayName = "App Title Bar Margin Sets when Back Button Visible")]
public async Task AppTitleBarMarginSetsWhenBackButtonVisible()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void SetupBuilder()
handlers.AddHandler(typeof(NavigationPage), typeof(NavigationViewHandler));
handlers.AddHandler(typeof(TabbedPage), typeof(TabbedViewHandler));
#endif
handlers.AddHandler<Page, PageHandler>();
handlers.AddHandler(typeof(FlyoutPage), typeof(FlyoutViewHandler));
handlers.AddHandler<Page, PageHandler>();
handlers.AddHandler<Window, WindowHandlerStub>();
handlers.AddHandler<Frame, FrameRenderer>();
handlers.AddHandler<Label, LabelHandler>();
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/Platform/Windows/RootNavigationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public RootNavigationView()
}

UpdateToolbarPlacement();
UpdateHeaderPropertyBinding();
}
}

Expand Down

0 comments on commit fb82b83

Please sign in to comment.