Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #88 from PrismLibrary/android-back
Browse files Browse the repository at this point in the history
add Android Back Button override
  • Loading branch information
dansiegel authored Jul 16, 2022
2 parents 35171bc + f378204 commit 72ecde3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Prism.Maui/PrismAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Prism.Regions.Adapters;
using Prism.Regions.Behaviors;
using Prism.Services;
using Microsoft.Maui.LifecycleEvents;
using TabbedPage = Microsoft.Maui.Controls.TabbedPage;

namespace Prism;
Expand Down Expand Up @@ -45,6 +46,28 @@ internal PrismAppBuilder(IContainerExtension containerExtension, MauiAppBuilder

MauiBuilder = builder;
MauiBuilder.ConfigureContainer(new PrismServiceProviderFactory(RegistrationCallback));
MauiBuilder.ConfigureLifecycleEvents(lifecycle =>
{
#if ANDROID
lifecycle.AddAndroid(android =>
{
android.OnBackPressed(activity =>
{
var app = Application.Current;
if (app is null || !app.Windows.OfType<PrismWindow>().Any())
return true;

var window = app.Windows.OfType<PrismWindow>().First();
var currentPage = MvvmHelpers.GetCurrentPage(window.Page);
var container = currentPage.GetContainerProvider();
var navigation = container.Resolve<INavigationService>();
navigation.GoBackAsync();

return false;
});
});
#endif
});

ContainerLocator.ResetContainer();
ContainerLocator.SetContainerExtension(() => containerExtension);
Expand Down

0 comments on commit 72ecde3

Please # to comment.