Skip to content

Commit

Permalink
Merge branch 'main' into Replace-FrozenSet-with-IReadOnlyList
Browse files Browse the repository at this point in the history
  • Loading branch information
pictos committed Apr 28, 2024
2 parents 1b2ac31 + 176f515 commit 0192d2d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
<Button Text="Remove Pin" Clicked="RemovePin_Clicked" />
<Button Text="Add 10 Pins" Clicked="Add10Pins_Clicked" />
</HorizontalStackLayout>
<maps:Map x:Name="PinsMap" Grid.Row="1" MapClicked="PinsMap_MapClicked" />
<maps:Map x:Name="PinsMap" Grid.Row="1" IsShowingUser="True" MapClicked="PinsMap_MapClicked" />
</Grid>
</pages:BasePage>
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,13 @@ function removeLocationPin()
function removeAllPins()
{
map.entities.clear();
locationPin = null;
if (locationPin != null )
{
map.entities.push(locationPin);
map.setView({
center: location
});
}
}
function addPin(latitude, longitude, label, address, id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommunityToolkit.Maui.Core.Views;
using System.Diagnostics.CodeAnalysis;
using CommunityToolkit.Maui.Core.Views;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;

namespace CommunityToolkit.Maui.Core.Handlers;

Expand All @@ -21,7 +21,14 @@ protected override MauiMediaElement CreatePlatformView()
Dispatcher.GetForCurrentThread() ?? throw new InvalidOperationException($"{nameof(IDispatcher)} cannot be null"));

var (_, playerViewController) = mediaManager.CreatePlatformView();
return new(playerViewController);

if (VirtualView.TryFindParent<Page>(out var page))
{
var parentViewController = (page.Handler as PageHandler)?.ViewController;
return new(playerViewController, parentViewController);
}

return new(playerViewController, null);
}

/// <inheritdoc/>
Expand All @@ -37,4 +44,33 @@ protected override void DisconnectHandler(MauiMediaElement platformView)
Dispose();
base.DisconnectHandler(platformView);
}
}

static class ParentPage
{
/// <summary>
/// Extension method to find the Parent of <see cref="VisualElement"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="child"></param>
/// <param name="parent"></param>
/// <returns></returns>
public static bool TryFindParent<T>(this VisualElement? child, [NotNullWhen(true)] out T? parent) where T : VisualElement
{
while (true)
{
if (child is null)
{
parent = null;
return false;
}
if (child.Parent is T element)
{
parent = element;
return true;
}

child = child.Parent as VisualElement;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ public MauiMediaElement(Context context, StyledPlayerView playerView) : base(con
AddView(playerView);
}

public override void OnDetachedFromWindow()
{
if (isFullScreen)
{
OnFullscreenButtonClick(this, new StyledPlayerView.FullscreenButtonClickEventArgs(!isFullScreen));
}
base.OnDetachedFromWindow();
}

/// <summary>
/// Checks the visibility of the view
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@ public class MauiMediaElement : UIView
/// <param name="playerViewController">The <see cref="AVPlayerViewController"/> that acts as the platform media player.</param>
/// <param name="parentViewController">The <see cref="UIViewController"/> that acts as the parent for <paramref name="playerViewController"/>.</param>
/// <exception cref="NullReferenceException">Thrown when <paramref name="playerViewController"/><c>.View</c> is <see langword="null"/>.</exception>
[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete("Deprecated CTOR. UIViewController? parentViewController is obsolete")]
public MauiMediaElement(AVPlayerViewController playerViewController, UIViewController? parentViewController)
{
ArgumentNullException.ThrowIfNull(playerViewController.View);
playerViewController.View.Frame = Bounds;

#if IOS16_0_OR_GREATER || MACCATALYST16_1_OR_GREATER
// On iOS 16+ and macOS 13+ the AVPlayerViewController has to be added to a parent ViewController, otherwise the transport controls won't be displayed.
var viewController = parentViewController ?? WindowStateManager.Default.GetCurrentUIViewController();
Expand All @@ -38,50 +35,9 @@ public MauiMediaElement(AVPlayerViewController playerViewController, UIViewContr
new UIEdgeInsets(insets.Top * -1, insets.Left, insets.Bottom * -1, insets.Right);

// Add the View from the AVPlayerViewController to the parent ViewController
if (viewController is not ShellFlyoutRenderer && viewController is not PageViewController && viewController is not UICollectionViewController)
{
viewController.AddChildViewController(playerViewController);
}
viewController.View.AddSubview(playerViewController.View);
viewController.AddChildViewController(playerViewController);
}

#endif

AddSubview(playerViewController.View);
}

/// <summary>
/// Initializes a new instance of the <see cref="MauiMediaElement"/> class.
/// </summary>
/// <param name="playerViewController">The <see cref="AVPlayerViewController"/> that acts as the platform media player.</param>
/// <exception cref="NullReferenceException">Thrown when <paramref name="playerViewController"/><c>.View</c> is <see langword="null"/>.</exception>
public MauiMediaElement(AVPlayerViewController playerViewController)
{
ArgumentNullException.ThrowIfNull(playerViewController.View);
playerViewController.View.Frame = Bounds;

#if IOS16_0_OR_GREATER || MACCATALYST16_1_OR_GREATER
// On iOS 16+ and macOS 13+ the AVPlayerViewController has to be added to a parent ViewController, otherwise the transport controls won't be displayed.
var viewController = WindowStateManager.Default.GetCurrentUIViewController();

// If we don't find the viewController, assume it's not Shell and still continue, the transport controls will still be displayed
if (viewController?.View is not null)
{
// Zero out the safe area insets of the AVPlayerViewController
UIEdgeInsets insets = viewController.View.SafeAreaInsets;
playerViewController.AdditionalSafeAreaInsets =
new UIEdgeInsets(insets.Top * -1, insets.Left, insets.Bottom * -1, insets.Right);

// Add the View from the AVPlayerViewController to the parent ViewController
if (viewController is not ShellFlyoutRenderer && viewController is not PageViewController && viewController is not UICollectionViewController)
{
viewController.AddChildViewController(playerViewController);
}
viewController.View.AddSubview(playerViewController.View);
}

#endif

AddSubview(playerViewController.View);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void OnPlayerError(PlaybackException? error)

if (!string.IsNullOrWhiteSpace(error?.ErrorCodeName))
{
errorCode = $"Error codename: {error?.ErrorCodeName}";
errorCodeName = $"Error codename: {error?.ErrorCodeName}";
}

var message = string.Join(", ", new[]
Expand Down

0 comments on commit 0192d2d

Please sign in to comment.