Skip to content

Commit

Permalink
Merge pull request #71 from lucacivale/#66
Browse files Browse the repository at this point in the history
[Performance] Run handler mapping only if BottomSheet is already open
  • Loading branch information
lucacivale authored Mar 2, 2025
2 parents 66a8959 + 9f8abc1 commit baec03b
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,61 +36,122 @@ protected override void DisconnectHandler(MauiBottomSheet platformView)

private static void MapIsCancelable(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsCancelable();
}

private static void MapHasHandle(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetHasHandle();
}

private static void MapShowHeader(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetShowHeader();
}

private static void MapIsOpen(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.IsConnecting
&& bottomSheet.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsOpen();
}

private static void MapIsDraggable(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsDraggable();
}

private static void MapHeader(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetHeader();
}

private static void MapStates(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

MauiBottomSheet.SetStates();
}

private static void MapCurrentState(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetCurrentState();
}

private static void MapPeekHeight(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetPeekHeight();
}

private static void MapContent(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetContent();
}

private static void MapPadding(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetPadding();
}

private static void MapBackgroundColor(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetBottomSheetBackgroundColor();
}

Expand All @@ -101,21 +162,41 @@ private static void MapIgnoreSafeArea(BottomSheetHandler handler, IBottomSheet b

private static void MapCornerRadius(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetCornerRadius();
}

private static void MapWindowBackgroundColor(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetWindowBackgroundColor();
}

private static void MapIsModal(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsModal();
}

private static void MapBottomSheetStyle(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetBottomSheetStyle();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ internal sealed partial class BottomSheetHandler
/// </summary>
/// <param name="mapper"><see cref="IPropertyMapper{TVirtualView,TViewHandler}"/>.</param>
/// <param name="commandMapper"><see cref="CommandMapper"/>.</param>
// ReSharper disable once UnusedParameter.Local
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "S1118:Utility classes should not have public constructors", Justification = "Must be public.")]
public BottomSheetHandler(IPropertyMapper? mapper, CommandMapper? commandMapper)
: base(mapper ?? BottomSheetMapper)
: base(mapper ?? BottomSheetMapper, commandMapper)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BottomSheetHandler"/> class.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "S1118:Utility classes should not have public constructors", Justification = "Must be public.")]
public BottomSheetHandler()
: base(BottomSheetMapper)
{
Expand All @@ -52,9 +53,22 @@ public BottomSheetHandler()
/// Initializes a new instance of the <see cref="BottomSheetHandler"/> class.
/// </summary>
/// <param name="context"><see cref="IMauiContext"/>.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "S1118:Utility classes should not have public constructors", Justification = "Must be public.")]
public BottomSheetHandler(IMauiContext context)
: base(BottomSheetMapper)
{
SetMauiContext(context);
}

/// <summary>
/// Gets a value indicating whether handler connecting.
/// </summary>
public bool IsConnecting { get; private set; }

public override void SetVirtualView(IView view)
{
IsConnecting = true;
base.SetVirtualView(view);
IsConnecting = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,86 +33,168 @@ protected override void DisconnectHandler(Platform.MaciOS.MauiBottomSheet platfo

private static void MapIsCancelable(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsCancelable();
}

private static void MapHasHandle(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetHasHandle();
}

private static void MapShowHeader(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetShowHeader();
}

private static void MapIsOpen(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.IsConnecting
&& bottomSheet.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsOpenAsync().SafeFireAndForget(continueOnCapturedContext: false);
}

private static void MapIsDraggable(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsDraggable();
}

private static void MapHeader(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetHeader();
}

private static void MapStates(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetStates();
}

private static void MapCurrentState(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetCurrentState();
}

private static void MapPeekHeight(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
// Always set peek height!
handler.PlatformView.SetPeekHeight();
}

private static void MapContent(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetContent();
}

private static void MapPadding(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetPadding();
}

private static void MapBackgroundColor(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetBottomSheetBackgroundColor();
}

private static void MapIgnoreSafeArea(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIgnoreSafeArea();
}

private static void MapCornerRadius(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetCornerRadius();
}

private static void MapWindowBackgroundColor(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetWindowBackgroundColor();
}

private static void MapIsModal(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetIsModal();
}

private static void MapBottomSheetStyle(BottomSheetHandler handler, IBottomSheet bottomSheet)
{
if (handler.PlatformView.IsOpen == false)
{
return;
}

handler.PlatformView.SetBottomSheetStyle();
}
}
Loading

0 comments on commit baec03b

Please sign in to comment.