-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
BottomSheet Closed Event Not Triggered
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace Plugin.Maui.BottomSheet.Behaviors.BottomSheetPeekBehavior; | ||
|
||
using Microsoft.Maui.Platform; | ||
|
||
/// <summary> | ||
/// Android implementation. | ||
/// </summary> | ||
public sealed partial class BottomSheetPeekBehavior | ||
{ | ||
private WeakReference<IBottomSheet>? _weakBottomSheet; | ||
|
||
/// <inheritdoc/> | ||
protected override void OnAttachedTo(View bindable, Android.Views.View platformView) | ||
{ | ||
base.OnAttachedTo(bindable, platformView); | ||
|
||
var bottomSheet = bindable.FindBottomSheet(); | ||
|
||
if (bottomSheet is not null) | ||
{ | ||
_weakBottomSheet = new WeakReference<IBottomSheet>(bottomSheet); | ||
} | ||
|
||
platformView.LayoutChange += OnLayoutChange; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnDetachedFrom(View bindable, Android.Views.View platformView) | ||
{ | ||
base.OnDetachedFrom(bindable, platformView); | ||
|
||
platformView.LayoutChange -= OnLayoutChange; | ||
} | ||
|
||
private void OnLayoutChange(object? sender, Android.Views.View.LayoutChangeEventArgs e) | ||
{ | ||
if (sender is Android.Views.View view | ||
&& _weakBottomSheet?.TryGetTarget(out var bottomSheet) == true | ||
&& view.Context is not null) | ||
{ | ||
bottomSheet.PeekHeight = Convert.ToInt32(view.Context.FromPixels(view.Height)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace Plugin.Maui.BottomSheet.Behaviors.BottomSheetPeekBehavior; | ||
|
||
/// <inheritdoc /> | ||
public sealed partial class BottomSheetPeekBehavior : PlatformBehavior<View>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace Plugin.Maui.BottomSheet.Behaviors.BottomSheetPeekBehavior; | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using UIKit; | ||
|
||
/// <summary> | ||
/// iOS MacCatalyst implementation. | ||
/// </summary> | ||
public sealed partial class BottomSheetPeekBehavior | ||
{ | ||
private WeakReference<IBottomSheet>? _weakBottomSheet; | ||
|
||
/// <inheritdoc/> | ||
// ReSharper disable once RedundantNullableFlowAttribute | ||
protected override void OnAttachedTo([NotNull]View bindable, UIKit.UIView platformView) | ||
{ | ||
base.OnAttachedTo(bindable, platformView); | ||
var bottomSheetPage = bindable.FindBottomSheetPage(); | ||
|
||
if (bottomSheetPage?.BottomSheet is not null) | ||
{ | ||
_weakBottomSheet = new WeakReference<IBottomSheet>(bottomSheetPage.BottomSheet); | ||
bottomSheetPage.BottomSheet.PeekHeight = CalculateHeight(bindable); | ||
} | ||
|
||
bindable.MeasureInvalidated += OnMeasureInvalidated; | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnDetachedFrom(View bindable, UIView platformView) | ||
{ | ||
base.OnDetachedFrom(bindable, platformView); | ||
|
||
bindable.MeasureInvalidated -= OnMeasureInvalidated; | ||
} | ||
|
||
private static double CalculateHeight(View view) | ||
{ | ||
#if NET9_0 | ||
var size = view.Measure(double.PositiveInfinity, double.PositiveInfinity); | ||
return size.Height; | ||
#elif NET8_0 | ||
var size = view.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.IncludeMargins); | ||
return size.Request.Height; | ||
#endif | ||
} | ||
|
||
private void OnMeasureInvalidated(object? sender, EventArgs e) | ||
{ | ||
if (sender is View view | ||
&& _weakBottomSheet?.TryGetTarget(out var bottomSheet) == true) | ||
{ | ||
bottomSheet.PeekHeight = CalculateHeight(view); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Plugin.Maui.BottomSheet.Behaviors.BottomSheetPeekBehavior; | ||
|
||
/// <summary> | ||
/// dotnet implementation. | ||
/// </summary> | ||
public sealed partial class BottomSheetPeekBehavior; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,12 +131,12 @@ public void SetIsOpen() | |
} | ||
else | ||
{ | ||
_virtualView?.OnClosingBottomSheet(); | ||
if (_bottomSheet.IsShowing) | ||
{ | ||
_virtualView?.OnClosingBottomSheet(); | ||
_bottomSheet.Close(); | ||
_virtualView?.OnClosedBottomSheet(); | ||
} | ||
Check warning on line 138 in src/Plugin.Maui.BottomSheet/Plugin.Maui.BottomSheet/Platform/Android/MauiBottomSheet.android.cs
|
||
_virtualView?.OnClosedBottomSheet(); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
[assembly: XmlnsDefinition("http://pluginmauibottomsheet.com", "Plugin.Maui.BottomSheet")] | ||
[assembly: XmlnsDefinition("http://pluginmauibottomsheet.com", "Plugin.Maui.BottomSheet.Behaviors.BottomSheetPeekBehavior")] | ||
[assembly: XmlnsDefinition("http://pluginmauibottomsheet.com/platformconfiguration/android", "Plugin.Maui.BottomSheet.PlatformConfiguration.AndroidSpecific")] |