Potential fix for backpress

This commit is contained in:
Tyson Elliot Hooker
2023-02-06 17:08:26 +11:00
parent eb7c4caeb7
commit a6b8480cfc
2 changed files with 22 additions and 14 deletions

View File

@@ -23,6 +23,7 @@ public static class AppHostBuilderExtensions
{
d.OnBackPressed(activity => Droid.Implementation.AndroidMopups.SendBackPressed());
});
#endif
})
.ConfigureMauiHandlers(handlers =>

View File

@@ -1,4 +1,5 @@
using System;
using Microsoft.Maui.Platform;
using Mopups.Interfaces;
using Mopups.Pages;
@@ -26,22 +27,28 @@ namespace Mopups.Windows.Implementation
//SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
}
// Probably wire this through the life cycle parats like you have with android
//private async void OnBackRequested(object sender, BackRequestedEventArgs e)
//{
// var lastPopupPage = PopupNavigationInstance.PopupStack.LastOrDefault();
public static bool SendBackPressed(Action? backPressedHandler = null)
{
var popupNavigationInstance = MopupService.Instance;
// if (lastPopupPage != null)
// {
// var isPrevent = lastPopupPage.DisappearingTransactionTask != null || lastPopupPage.SendBackButtonPressed();
if (popupNavigationInstance.PopupStack.Count > 0)
{
var lastPage = popupNavigationInstance.PopupStack[popupNavigationInstance.PopupStack.Count - 1];
// if (!isPrevent)
// {
// e.Handled = true;
// await PopupNavigationInstance.PopAsync();
// }
// }
//}
var isPreventClose = lastPage.SendBackButtonPressed();
if (!isPreventClose)
{
popupNavigationInstance.PopAsync().SafeFireAndForget();
}
return true;
}
backPressedHandler?.Invoke();
return false;
}
public async Task AddAsync(PopupPage page)
{