问题
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