Skip to content

Commit

Permalink
Remove generator (temporarily), as Rider does not like it.
Browse files Browse the repository at this point in the history
  • Loading branch information
softlion committed Nov 7, 2024
1 parent ea4b3e2 commit d8ee1b4
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 92 deletions.
43 changes: 34 additions & 9 deletions src/Models/AnchorDetent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion src/Models/ContentDetent.cs
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
25 changes: 15 additions & 10 deletions src/Models/Detent.cs
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Models/FullscreenDetent.cs
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
18 changes: 10 additions & 8 deletions src/Models/HeightDetent.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 10 additions & 8 deletions src/Models/RatioDetent.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
14 changes: 11 additions & 3 deletions src/Platforms/Android/BottomSheetController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -351,7 +353,7 @@ public void UpdateHandleColor()
}
}

static void EnsureStayOnFrontView(Context context)
private void EnsureStayOnFrontView(Context context)
{
if (_stayOnFront is null || !_stayOnFront.IsAttachedToWindow)
{
Expand All @@ -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)
{
Expand Down
20 changes: 0 additions & 20 deletions src/Platforms/Android/Models/AnchorDetent.cs

This file was deleted.

17 changes: 0 additions & 17 deletions src/Platforms/iOS/Models/AnchorDetent.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/Resources/Raw/AboutAssets.txt

This file was deleted.

0 comments on commit d8ee1b4

Please sign in to comment.