-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from lucacivale/PeekHeight
[Breaking change] Enhanced PeekHeight API
- Loading branch information
Showing
20 changed files
with
660 additions
and
685 deletions.
There are no files selected for viewing
370 changes: 182 additions & 188 deletions
370
sample/Plugin.Maui.BottomSheet.Sample/Plugin.Maui.BottomSheet.Sample/ShowCasePage.xaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
src/Plugin.Maui.BottomSheet/Plugin.Maui.BottomSheet/BottomSheetPeek.cs
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
src/Plugin.Maui.BottomSheet/Plugin.Maui.BottomSheet/BottomSheetPeekBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
namespace Plugin.Maui.BottomSheet; | ||
|
||
/// <inheritdoc /> | ||
public sealed class BottomSheetPeekBehavior : PlatformBehavior<View> | ||
{ | ||
#if ANDROID || IOS || MACCATALYST | ||
private WeakReference<IBottomSheet>? _weakBottomSheet; | ||
#endif | ||
|
||
#if ANDROID | ||
/// <inheritdoc/> | ||
protected override void OnAttachedTo(View bindable, Android.Views.View platformView) | ||
{ | ||
base.OnAttachedTo(bindable, platformView); | ||
|
||
#pragma warning disable CA1062 | ||
bindable.SizeChanged += ViewOnSizeChanged; | ||
#pragma warning restore CA1062 | ||
var bottomSheet = bindable.FindBottomSheet(); | ||
|
||
if (bottomSheet is not null) | ||
{ | ||
_weakBottomSheet = new WeakReference<IBottomSheet>(bottomSheet); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnDetachedFrom(View bindable, Android.Views.View platformView) | ||
{ | ||
base.OnDetachedFrom(bindable, platformView); | ||
|
||
#pragma warning disable CA1062 | ||
bindable.SizeChanged -= ViewOnSizeChanged; | ||
#pragma warning restore CA1062 | ||
} | ||
|
||
#elif MACCATALYST || IOS | ||
/// <inheritdoc/> | ||
protected override void OnAttachedTo(View bindable, UIKit.UIView platformView) | ||
{ | ||
base.OnAttachedTo(bindable, platformView); | ||
|
||
double height = 0.00; | ||
#pragma warning disable CA1062 | ||
#if NET9 | ||
var size = bindable.Measure(double.PositiveInfinity, double.PositiveInfinity); | ||
height = size.Height; | ||
#elif NET8 | ||
var size = bindable.Measure(double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.IncludeMargins); | ||
height = size.Request.Height; | ||
#endif | ||
bindable.SizeChanged += ViewOnSizeChanged; | ||
#pragma warning restore CA1062 | ||
var bottomSheetPage = bindable.FindBottomSheetPage(); | ||
|
||
if (bottomSheetPage?.BottomSheet is not null) | ||
{ | ||
_weakBottomSheet = new WeakReference<IBottomSheet>(bottomSheetPage.BottomSheet); | ||
bottomSheetPage.BottomSheet.PeekHeight = height; | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override void OnDetachedFrom(View bindable, UIKit.UIView platformView) | ||
{ | ||
base.OnDetachedFrom(bindable, platformView); | ||
|
||
#pragma warning disable CA1062 | ||
bindable.SizeChanged -= ViewOnSizeChanged; | ||
#pragma warning restore CA1062 | ||
} | ||
#endif | ||
|
||
#if ANDROID || IOS || MACCATALYST | ||
private void ViewOnSizeChanged(object? sender, EventArgs e) | ||
{ | ||
if (sender is View view | ||
&& _weakBottomSheet?.TryGetTarget(out var bottomSheet) == true) | ||
{ | ||
bottomSheet.PeekHeight = view.Height; | ||
} | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Plugin.Maui.BottomSheet/Plugin.Maui.BottomSheet/IBottomSheetExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
namespace Plugin.Maui.BottomSheet; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
|
||
/// <summary> | ||
/// <see cref="IBottomSheet"/> extension methods. | ||
/// </summary> | ||
internal static class IBottomSheetExtensions | ||
{ | ||
/// <summary> | ||
/// Get the <see cref="ContentPage"/> parent of <see cref="IBottomSheet"/>. | ||
/// </summary> | ||
/// <param name="bottomSheet"><see cref="IBottomSheet"/>.</param> | ||
/// <returns><see cref="ContentPage"/> parent.</returns> | ||
internal static ContentPage? GetPageParent(this IBottomSheet bottomSheet) | ||
{ | ||
ContentPage? page = null; | ||
|
||
var parent = bottomSheet.Parent; | ||
while (parent is not null) | ||
{ | ||
if (parent is ContentPage contentPage) | ||
{ | ||
page = contentPage; | ||
break; | ||
} | ||
|
||
parent = parent.Parent; | ||
} | ||
|
||
return page; | ||
} | ||
} |
Oops, something went wrong.