2023-07-31 17:11:39 +08:00

24 lines
901 B
C#

using Google.Android.Material.BottomSheet;
using Microsoft.Maui.Platform;
namespace Blahblah.FlowerApp;
public static partial class PageExtensions
{
public static BottomSheetDialog ShowBottomSheet(this Page page, IView content, bool dimDismiss = false)
{
var dialog = new BottomSheetDialog(Platform.CurrentActivity?.Window?.DecorView.FindViewById(Android.Resource.Id.Content)?.Context ?? throw new InvalidOperationException("Context is null"));
dialog.SetContentView(content.ToPlatform(page.Handler?.MauiContext ?? throw new Exception("MauiContext is null")));
dialog.Behavior.Hideable = dimDismiss;
dialog.SetCanceledOnTouchOutside(dimDismiss);
dialog.Behavior.FitToContents = true;
dialog.Show();
return dialog;
}
public static void CloseBottomSheet(this BottomSheetDialog dialog)
{
dialog.Dismiss();
}
}