Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ protected override void DisconnectHandler(Popup platformView)
{
MauiContext.GetPlatformWindow().SizeChanged -= OnSizeChanged;
}
DetachSwipeControlEvent(platformView);
}

/// <inheritdoc/>
Expand All @@ -140,6 +141,7 @@ protected override void ConnectHandler(Popup platformView)
{
MauiContext.GetPlatformWindow().SizeChanged += OnSizeChanged;
}
AttachSwipeControlEvent(platformView);
base.ConnectHandler(platformView);
}

Expand Down Expand Up @@ -168,4 +170,60 @@ void OnSizeChanged(object? sender, WindowSizeChangedEventArgs e)
PopupExtensions.SetLayout(PlatformView, VirtualView, MauiContext);
}
}

void AttachSwipeControlEvent(Popup platformView)
{
if (platformView.Child is FrameworkElement frameworkElement)
{
if (frameworkElement is SwipeControl)
{
SwipeControl swipeControl = (SwipeControl)frameworkElement;
swipeControl.Loaded += OnLoadedSwipeControl;
}
else
{
var swipeControls = frameworkElement.GetChildren<SwipeControl>();
foreach (SwipeControl? swipeControl in swipeControls)
{
if (swipeControl is not null)
{
swipeControl.Loaded += OnLoadedSwipeControl;
}
}
}
}
}

void DetachSwipeControlEvent(Popup platformView)
{
if (platformView.Child is FrameworkElement frameworkElement)
{
if (frameworkElement is SwipeControl)
{
SwipeControl swipeControl = (SwipeControl)frameworkElement;
swipeControl.Loaded -= OnLoadedSwipeControl;
}
else
{
var swipeControls = frameworkElement.GetChildren<SwipeControl>();
foreach (SwipeControl? swipeControl in swipeControls)
{
if (swipeControl is not null)
{
swipeControl.Loaded -= OnLoadedSwipeControl;
}
}
}
}
}

void OnLoadedSwipeControl(object? sender, RoutedEventArgs e)
{
if (VirtualView is not null)
{
PopupExtensions.SetSize(PlatformView, VirtualView, MauiContext);
PopupExtensions.SetLayout(PlatformView, VirtualView, MauiContext);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ public static void ConfigureControl(this Popup mauiPopup, IPopup popup, IMauiCon
mauiPopup.SetLayout(popup, mauiContext);
}

static bool CanMeasureContent(Popup mauiPopup)
{
if (mauiPopup.Child is FrameworkElement frameworkElement)
{
if (frameworkElement is SwipeControl)
{
SwipeControl swipeControl = (SwipeControl)frameworkElement;
if (!swipeControl.IsLoaded)
{
return false;
}
}
else
{
var swipeControls = frameworkElement.GetChildren<SwipeControl>();
foreach (SwipeControl? swipeControl in swipeControls)
{
if (swipeControl is not null && !swipeControl.IsLoaded)
{
return false;
}
}
}
}
return true;
}

/// <summary>
/// Method to update the popup size based on the <see cref="Maui.Core.IPopup.Size"/>.
/// </summary>
Expand All @@ -79,7 +106,14 @@ public static void SetSize(this Popup mauiPopup, IPopup popup, IMauiContext? mau
{
if (double.IsNaN(popup.Content.Width) || (double.IsNaN(popup.Content.Height)))
{
currentSize = popup.Content.Measure(double.IsNaN(popup.Content.Width) ? popupParent.Bounds.Width : popup.Content.Width, double.IsNaN(popup.Content.Height) ? popupParent.Bounds.Height : popup.Content.Height);
if (CanMeasureContent(mauiPopup))
{
currentSize = popup.Content.Measure(double.IsNaN(popup.Content.Width) ? popupParent.Bounds.Width : popup.Content.Width, double.IsNaN(popup.Content.Height) ? popupParent.Bounds.Height : popup.Content.Height);
}
else
{
return;
}

if (double.IsNaN(popup.Content.Width))
{
Expand Down Expand Up @@ -129,7 +163,16 @@ public static void SetLayout(this Popup mauiPopup, IPopup popup, IMauiContext? m
ArgumentNullException.ThrowIfNull(popup.Content);

var popupParent = mauiContext.GetPlatformWindow();
popup.Content.Measure(double.PositiveInfinity, double.PositiveInfinity);

if (CanMeasureContent(mauiPopup))
{
popup.Content.Measure(double.PositiveInfinity, double.PositiveInfinity);
}
else
{
return;
}

var contentSize = popup.Content.ToPlatform(mauiContext).DesiredSize;
var popupParentFrame = popupParent.Bounds;

Expand Down
Loading