Commit 02c986f0 authored by Martin Finkel's avatar Martin Finkel

Enable Xamarin.Forms crossplatform animations for iOS by implementing IVisualElementRenderer

https://github.com/xamarin/Xamarin.Forms/issues/4885
parent addc1074
......@@ -5,19 +5,21 @@ using LibVLCSharp.Forms.Shared;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using UIKit;
using System;
[assembly: ExportRenderer(typeof(VideoView), typeof(VideoViewRenderer))]
[assembly: ExportRenderer(typeof(LibVLCSharp.Forms.Shared.VideoView), typeof(VideoViewRenderer))]
namespace LibVLCSharp.Forms.Platforms.iOS
{
public class VideoViewRenderer : ViewRenderer<LibVLCSharp.Forms.Shared.VideoView, LibVLCSharp.Platforms.iOS.VideoView>
{
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> e)
protected override void OnElementChanged(ElementChangedEventArgs<LibVLCSharp.Forms.Shared.VideoView> e)
{
base.OnElementChanged(e);
if(Control == null)
{
SetNativeControl(new LibVLCSharp.Platforms.iOS.VideoView());
SetNativeControl(new LibVLCSharp.Forms.Platforms.iOS.VideoView());
}
if (e.OldElement != null)
......@@ -36,4 +38,26 @@ namespace LibVLCSharp.Forms.Platforms.iOS
Control.MediaPlayer = e.NewMediaPlayer;
}
}
public class VideoView : LibVLCSharp.Platforms.iOS.VideoView, IVisualElementRenderer
{
public VisualElement Element { get; private set; }
public UIView NativeView => this;
public UIViewController ViewController => ViewController;
public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint) => this.GetSizeRequest(widthConstraint, heightConstraint);
public void SetElement(VisualElement element)
{
Element = element;
ElementChanged?.Invoke(this, new VisualElementChangedEventArgs(null, Element));
}
public void SetElementSize(Size size) => Element.Layout(new Rectangle(Element.X, Element.Y, size.Width, size.Height));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment