version up
This commit is contained in:
23
FlowerApp/Platforms/Android/PageExtensions.cs
Normal file
23
FlowerApp/Platforms/Android/PageExtensions.cs
Normal file
@ -0,0 +1,23 @@
|
||||
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();
|
||||
}
|
||||
}
|
39
FlowerApp/Platforms/iOS/PageExtensions.cs
Normal file
39
FlowerApp/Platforms/iOS/PageExtensions.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using Microsoft.Maui.Platform;
|
||||
using UIKit;
|
||||
|
||||
namespace Blahblah.FlowerApp;
|
||||
|
||||
public static partial class PageExtensions
|
||||
{
|
||||
public static UIViewController ShowBottomSheet(this Page page, IView content, bool dimDismiss = false)
|
||||
{
|
||||
var mauiContext = page.Handler?.MauiContext ?? throw new Exception("MauiContext is null");
|
||||
var viewController = page.ToUIViewController(mauiContext);
|
||||
|
||||
var viewControllerToPresent = content.ToUIViewController(mauiContext);
|
||||
viewControllerToPresent.ModalInPresentation = !dimDismiss;
|
||||
|
||||
var sheet = viewControllerToPresent.SheetPresentationController;
|
||||
if (sheet != null)
|
||||
{
|
||||
sheet.Detents = new[]
|
||||
{
|
||||
UISheetPresentationControllerDetent.CreateLargeDetent()
|
||||
};
|
||||
//sheet.LargestUndimmedDetentIdentifier = dimDismiss ?
|
||||
// UISheetPresentationControllerDetentIdentifier.Unknown :
|
||||
// UISheetPresentationControllerDetentIdentifier.Medium;
|
||||
sheet.PrefersScrollingExpandsWhenScrolledToEdge = false;
|
||||
sheet.PrefersEdgeAttachedInCompactHeight = true;
|
||||
sheet.WidthFollowsPreferredContentSizeWhenEdgeAttached = true;
|
||||
}
|
||||
|
||||
viewController.PresentViewController(viewControllerToPresent, true, null);
|
||||
return viewControllerToPresent;
|
||||
}
|
||||
|
||||
public static void CloseBottomSheet(this UIViewController sheet)
|
||||
{
|
||||
sheet.DismissViewController(true, null);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user