Merge branch 'master' into android-popup-handler-null
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using Android.Views;
|
||||
using Android.Views;
|
||||
using Android.Widget;
|
||||
using AndroidX.Activity;
|
||||
using AndroidX.Fragment.App;
|
||||
using AsyncAwaitBestPractices;
|
||||
using Mopups.Extensions;
|
||||
using Microsoft.Maui.Platform;
|
||||
using Mopups.Interfaces;
|
||||
using Mopups.Pages;
|
||||
using Mopups.Services;
|
||||
@@ -10,7 +13,7 @@ namespace Mopups.Droid.Implementation;
|
||||
|
||||
public class AndroidMopups : IPopupPlatform
|
||||
{
|
||||
private static FrameLayout? DecoreView => Platform.CurrentActivity?.Window?.DecorView as FrameLayout;
|
||||
private static FrameLayout? DecoreView => GetTopFragmentDecorView();
|
||||
|
||||
public static bool SendBackPressed(Action? backPressedHandler = null)
|
||||
{
|
||||
@@ -45,13 +48,11 @@ public class AndroidMopups : IPopupPlatform
|
||||
var handler = page.Handler ??= new PopupPageHandler(page.Parent.FindMauiContext());
|
||||
|
||||
var androidNativeView = handler.PlatformView as Android.Views.View;
|
||||
var decoreView = Platform.CurrentActivity?.Window?.DecorView as FrameLayout;
|
||||
|
||||
decoreView?.AddView(androidNativeView);
|
||||
DecoreView?.AddView(androidNativeView);
|
||||
|
||||
return PostAsync(androidNativeView);
|
||||
}
|
||||
|
||||
|
||||
public Task RemoveAsync(PopupPage page)
|
||||
{
|
||||
var renderer = IPopupPlatform.GetOrCreateHandler<PopupPageHandler>(page);
|
||||
@@ -172,4 +173,28 @@ public class AndroidMopups : IPopupPlatform
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
static FrameLayout? GetTopFragmentDecorView()
|
||||
{
|
||||
if (Platform.CurrentActivity is not ComponentActivity componentActivity)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var fragments = componentActivity.GetFragmentManager()?.Fragments;
|
||||
|
||||
if (fragments is null || !fragments.Any())
|
||||
{
|
||||
return Platform.CurrentActivity?.Window?.DecorView as FrameLayout;;
|
||||
}
|
||||
|
||||
var topFragment = fragments[^1];
|
||||
|
||||
if (topFragment is DialogFragment dialogFragment)
|
||||
{
|
||||
return dialogFragment.Dialog?.Window?.DecorView as FrameLayout;
|
||||
}
|
||||
|
||||
return topFragment.Activity?.Window?.DecorView as FrameLayout;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user