diff --git a/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs b/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs index b910f6d2b..1c3618f83 100644 --- a/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs +++ b/src/CommunityToolkit.Maui.Core/Views/Popup/MauiPopup.macios.cs @@ -60,8 +60,8 @@ public override void ViewDidLayoutSubviews() if (VirtualView is not null) { - PopupExtensions.SetSize(this, VirtualView); - PopupExtensions.SetLayout(this, VirtualView); + this.SetSize(VirtualView); + this.SetLayout(VirtualView); } } @@ -76,8 +76,8 @@ public override void ViewWillTransitionToSize(CGSize toSize, IUIViewControllerTr // After screen rotate if (VirtualView is not null) { - PopupExtensions.SetSize(this, VirtualView); - PopupExtensions.SetLayout(this, VirtualView); + this.SetSize(VirtualView); + this.SetLayout(VirtualView); } }); diff --git a/src/CommunityToolkit.Maui.MediaElement/Extensions/ElementExtensions.shared.cs b/src/CommunityToolkit.Maui.MediaElement/Extensions/ElementExtensions.shared.cs index 95b7410c4..da7d88180 100644 --- a/src/CommunityToolkit.Maui.MediaElement/Extensions/ElementExtensions.shared.cs +++ b/src/CommunityToolkit.Maui.MediaElement/Extensions/ElementExtensions.shared.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using Microsoft.Maui.Platform; namespace CommunityToolkit.Maui.Extensions; static class ElementExtensions @@ -19,4 +20,21 @@ public static bool TryFindParent(this Element? child, [NotNullWhen(true)] out parent = null; return false; } + + public static bool TryFindParentPlatformView(this Element? child, [NotNullWhen(true)] out T? parentPlatformView) + { + while (child is not null) + { + if (child.Parent?.Handler?.PlatformView is T element) + { + parentPlatformView = element; + return true; + } + + child = child.Parent; + } + + parentPlatformView = default; + return false; + } } \ No newline at end of file diff --git a/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs b/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs index 1b1a7ff24..82fa4cc34 100644 --- a/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs +++ b/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.macios.cs @@ -29,8 +29,16 @@ public MauiMediaElement(AVPlayerViewController playerViewController, MediaElemen UIViewController? viewController; - // If Parent is not null, we can retrieve the PageHandler using the traversing `MediaElement.Parent` until the Page is located - if (virtualView.TryFindParent(out var page) + // If any of the Parents in the VisualTree of MediaElement uses a UIViewController for their PlatformView, use it as the child ViewController + // This enables support for UI controls like CommunityToolkit.Maui.Popup whose PlatformView is a UIViewController (e.g. `public class MauiPopup : UIViewController`) + // To find the UIViewController, we traverse `MediaElement.Parent` until a Parent using UIViewController is located + if (virtualView.TryFindParentPlatformView(out UIViewController? parentUIViewController)) + { + viewController = parentUIViewController; + } + // If none of the Parents in the VisualTree of MediaElement use a UIViewController, we can use the ViewController in the PageHandler + // To find the PageHandler, we traverse `MediaElement.Parent` until the Page is located + else if (virtualView.TryFindParent(out var page) && page.Handler is PageHandler { ViewController: not null } pageHandler) { viewController = pageHandler.ViewController;