diff --git a/src/Models/AnchorDetent.cs b/src/Models/AnchorDetent.cs index f598f27..ced1050 100644 --- a/src/Models/AnchorDetent.cs +++ b/src/Models/AnchorDetent.cs @@ -1,18 +1,43 @@ -using Maui.BindableProperty.Generator.Core; +namespace The49.Maui.BottomSheet; -namespace The49.Maui.BottomSheet; +#if ANDROID +using AView = Android.Views.View; +#elif IOS +using UIKit; +#endif -public partial class AnchorDetent: Detent +public class AnchorDetent: Detent { - double _height = 0; -#pragma warning disable CS0169 - [AutoBindable] - readonly VisualElement anchor; -#pragma warning restore CS0169 + public static readonly BindableProperty AnchorProperty = BindableProperty.Create(nameof(Anchor), typeof(VisualElement), typeof(AnchorDetent)); + + public VisualElement Anchor + { + get => (VisualElement)GetValue(AnchorProperty); + set => SetValue(AnchorProperty, value); + } + + double _height; public override double GetHeight(BottomSheet page, double maxSheetHeight) { - UpdateHeight(page, maxSheetHeight); + if (Anchor == null) + throw new Exception("Could not update Detent height: Anchor is not set"); + +#if ANDROID + var p = ((AView)Anchor.Handler.PlatformView).GetLocationOnScreen(); + var r = ((AView)page.Handler.PlatformView).GetLocationOnScreen(); + + var offset = p - r; + _height = offset.Height / DeviceDisplay.MainDisplayInfo.Density; + +#elif IOS + var pageView = (UIView)page.Handler.PlatformView; + var targetView = (UIView)Anchor.Handler.PlatformView; + var targetOrigin = targetView.Superview.ConvertPointToView(targetView.Frame.Location, pageView); + + _height = targetOrigin.Y; +#endif + return _height; } } diff --git a/src/Models/ContentDetent.cs b/src/Models/ContentDetent.cs index 4e8dfca..5706ccc 100644 --- a/src/Models/ContentDetent.cs +++ b/src/Models/ContentDetent.cs @@ -1,6 +1,6 @@ namespace The49.Maui.BottomSheet; -public partial class ContentDetent : Detent +public class ContentDetent : Detent { public override double GetHeight(BottomSheet page, double maxSheetHeight) { diff --git a/src/Models/Detent.cs b/src/Models/Detent.cs index c5bc94f..612abed 100644 --- a/src/Models/Detent.cs +++ b/src/Models/Detent.cs @@ -1,16 +1,21 @@ -using Maui.BindableProperty.Generator.Core; +namespace The49.Maui.BottomSheet; -namespace The49.Maui.BottomSheet; - -public abstract partial class Detent : BindableObject +public abstract class Detent : BindableObject { -#pragma warning disable CS0169 - [AutoBindable(DefaultValue = "true")] - readonly bool isEnabled; + public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Detent), defaultValue: true); + public static readonly BindableProperty IsDefaultProperty = BindableProperty.Create(nameof(IsDefault), typeof(bool), typeof(Detent)); - [AutoBindable] - readonly bool isDefault; -#pragma warning restore CS0169 + public bool IsEnabled + { + get => (bool)GetValue(IsEnabledProperty); + set => SetValue(IsEnabledProperty, value); + } + + public bool IsDefault + { + get => (bool)GetValue(IsDefaultProperty); + set => SetValue(IsDefaultProperty, value); + } public abstract double GetHeight(BottomSheet page, double maxSheetHeight); } diff --git a/src/Models/FullscreenDetent.cs b/src/Models/FullscreenDetent.cs index f9f3a35..47a45b9 100644 --- a/src/Models/FullscreenDetent.cs +++ b/src/Models/FullscreenDetent.cs @@ -1,6 +1,6 @@ namespace The49.Maui.BottomSheet; -public partial class FullscreenDetent : Detent +public class FullscreenDetent : Detent { public override double GetHeight(BottomSheet page, double maxSheetHeight) { diff --git a/src/Models/HeightDetent.cs b/src/Models/HeightDetent.cs index e25969b..e171054 100644 --- a/src/Models/HeightDetent.cs +++ b/src/Models/HeightDetent.cs @@ -1,14 +1,16 @@ -using Maui.BindableProperty.Generator.Core; - -namespace The49.Maui.BottomSheet; +namespace The49.Maui.BottomSheet; [ContentProperty(nameof(Height))] -public partial class HeightDetent : Detent +public class HeightDetent : Detent { -#pragma warning disable CS0169 - [AutoBindable] - readonly double height; -#pragma warning restore CS0169 + public static readonly BindableProperty HeightProperty = BindableProperty.Create(nameof(Height), typeof(double), typeof(HeightDetent), defaultValue: 0.0); + + public double Height + { + get => (double)GetValue(HeightProperty); + set => SetValue(HeightProperty, value); + } + public override double GetHeight(BottomSheet page, double maxSheetHeight) { return Height; diff --git a/src/Models/RatioDetent.cs b/src/Models/RatioDetent.cs index 60fd08a..4ed6a9a 100644 --- a/src/Models/RatioDetent.cs +++ b/src/Models/RatioDetent.cs @@ -1,14 +1,16 @@ -using Maui.BindableProperty.Generator.Core; - -namespace The49.Maui.BottomSheet; +namespace The49.Maui.BottomSheet; [ContentProperty(nameof(Ratio))] -public partial class RatioDetent : Detent +public class RatioDetent : Detent { -#pragma warning disable CS0169 - [AutoBindable] - readonly float ratio; -#pragma warning restore CS0169 + public static readonly BindableProperty RatioProperty = BindableProperty.Create(nameof(Ratio), typeof(float), typeof(RatioDetent), defaultValue: 0f); + + public float Ratio + { + get => (float)GetValue(RatioProperty); + set => SetValue(RatioProperty, value); + } + public override double GetHeight(BottomSheet page, double maxSheetHeight) { return maxSheetHeight * Ratio; diff --git a/src/Platforms/Android/BottomSheetController.cs b/src/Platforms/Android/BottomSheetController.cs index dd4c472..36d7fb1 100644 --- a/src/Platforms/Android/BottomSheetController.cs +++ b/src/Platforms/Android/BottomSheetController.cs @@ -1,4 +1,6 @@ -using Android.Views; +#define USE_MATERIAL3 + +using Android.Views; using Microsoft.Maui.Platform; using Google.Android.Material.BottomSheet; using Android.Widget; @@ -351,7 +353,7 @@ public void UpdateHandleColor() } } - static void EnsureStayOnFrontView(Context context) + private void EnsureStayOnFrontView(Context context) { if (_stayOnFront is null || !_stayOnFront.IsAttachedToWindow) { @@ -378,7 +380,13 @@ void EnsureWindowContainer() SoundEffectsEnabled = false }; - var bottomSheet = new FrameLayout(_mauiContext.Context, null, 0, Resource.Style.Widget_Material3_BottomSheet_Modal) +#if USE_MATERIAL3 + var frameStyle = Resource.Style.Widget_Material3_BottomSheet_Modal; +#else + var frameStyle = Resource.Style.Widget_MaterialComponents_BottomSheet_Modal; +#endif + + var bottomSheet = new FrameLayout(_mauiContext.Context, null, 0, frameStyle) { LayoutParameters = new CoordinatorLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent) { diff --git a/src/Platforms/Android/Models/AnchorDetent.cs b/src/Platforms/Android/Models/AnchorDetent.cs deleted file mode 100644 index 6e69ee4..0000000 --- a/src/Platforms/Android/Models/AnchorDetent.cs +++ /dev/null @@ -1,20 +0,0 @@ -using AView = Android.Views.View; - -namespace The49.Maui.BottomSheet; - -public partial class AnchorDetent : Detent -{ - void UpdateHeight(BottomSheet page, double maxSheetHeight) - { - if (Anchor == null) - { - throw new Exception("Could not update Detent height: Anchor is not set"); - } - var p = ((AView)Anchor.Handler.PlatformView).GetLocationOnScreen(); - var r = ((AView)page.Handler.PlatformView).GetLocationOnScreen(); - - var offset = p - r; - - _height = offset.Height / DeviceDisplay.MainDisplayInfo.Density; - } -} diff --git a/src/Platforms/iOS/Models/AnchorDetent.cs b/src/Platforms/iOS/Models/AnchorDetent.cs deleted file mode 100644 index 06451a7..0000000 --- a/src/Platforms/iOS/Models/AnchorDetent.cs +++ /dev/null @@ -1,17 +0,0 @@ -using UIKit; - -namespace The49.Maui.BottomSheet; - -public partial class AnchorDetent -{ - void UpdateHeight(BottomSheet page, double maxSheetHeight) - { - var pageView = (UIView)page.Handler.PlatformView; - var targetView = (UIView)Anchor.Handler.PlatformView; - - var targetOrigin = targetView.Superview.ConvertPointToView(targetView.Frame.Location, pageView); - - _height = targetOrigin.Y; - } -} - diff --git a/src/Resources/Raw/AboutAssets.txt b/src/Resources/Raw/AboutAssets.txt deleted file mode 100644 index 15d6244..0000000 --- a/src/Resources/Raw/AboutAssets.txt +++ /dev/null @@ -1,15 +0,0 @@ -Any raw assets you want to be deployed with your application can be placed in -this directory (and child directories). Deployment of the asset to your application -is automatically handled by the following `MauiAsset` Build Action within your `.csproj`. - - - -These files will be deployed with you package and will be accessible using Essentials: - - async Task LoadMauiAsset() - { - using var stream = await FileSystem.OpenAppPackageFileAsync("AboutAssets.txt"); - using var reader = new StreamReader(stream); - - var contents = reader.ReadToEnd(); - }