LottieUWP embedded into Xamarin.Forms

假装没事ソ 提交于 2021-02-10 14:53:53

问题


I made a custom renderer for LottieUWP

[assembly: ExportRenderer(typeof(LottieView), typeof(LottieViewRenderer))]
namespace Gorilla.Forms.UWP.Source.Renderer.Lottie
{
public class LottieViewRenderer : ViewRenderer<LottieView, LottieAnimationView>
{
    private LottieAnimationView AnimationView;

    protected override void OnElementChanged(ElementChangedEventArgs<LottieView> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            if (e.NewElement == null) return;

            AnimationView = new LottieAnimationView()
            {
                Name = e.NewElement.AnimationPath,
                FileName = e.NewElement.AnimationPath,
                AutoPlay = true,
                RepeatCount = -1
            };

            SetNativeControl(AnimationView);
        }
    }
}
}

And here is the LottieView

public class LottieView : View
{
    public static readonly BindableProperty AnimationPathProperty = BindableProperty.Create(
        propertyName: nameof(AnimationPath),
        returnType: typeof(string),
        declaringType: typeof(LottieView));

    public string AnimationPath
    {
        get => (string)GetValue(AnimationPathProperty);
        set => SetValue(AnimationPathProperty, value);
    }
}

This works, but sometimes when hovering or waiting some seconds, I get an error:

WinRT information: Attempting to close a CanvasActiveLayer that is not top of the stack. The most recently created layer must be closed first.

at System.Runtime.InteropServices.WindowsRuntime.IClosable.Close() at System.Runtime.InteropServices.WindowsRuntime.IClosableToIDisposableAdapter.Dispose() at LottieUWP.LottieDrawable.Draw(CanvasDevice device, BitmapCanvas bitmapCanvas, CompositionLayer compositionLayer, Rect bounds, Single scale, Byte alpha, Matrix3X3 matrix, Double width, Double height, CanvasDrawingSession canvasDrawingSession) at LottieUWP.LottieDrawable.CanvasControlOnDraw(ICanvasAnimatedControl canvasControl, CanvasAnimatedDrawEventArgs args) at Windows.ApplicationModel.Core.UnhandledError.Propagate() at Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object sender, UnhandledErrorDetectedEventArgs eventArgs) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object sender, UnhandledErrorDetectedEventArgs eventArgs)

This seems to be a bug inside LottieUWP or is my implementation incorrect?

来源:https://stackoverflow.com/questions/53412067/lottieuwp-embedded-into-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!