AvaloniaUI / Avalonia.Labs

Experimental Controls for Avalonia
MIT License
209 stars 31 forks source link

Support For Lottie Animation Start/Stop #93

Open asliujinhe opened 5 days ago

asliujinhe commented 5 days ago

I attempted to use reflection to invoke the private Start and Stop methods in Lottie.cs. While this approach works in certain scenarios, some specific Lottie files exhibit issues where the animation continues to play indefinitely, even after invoking Stop. It seems that these problematic files also render the RepeatCount property ineffective, as the property value does not appear to influence the playback behavior.

private void ChangeLottieStatus(bool animating)
    {
        var lottie = LottieLoading;

        var type = lottie.GetType();

        var methodName = animating ? "Start" : "Stop";

        var methodInfo = type.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);

        if (methodInfo != null)
        {
            methodInfo.Invoke(lottie, null);
        }
        else
        {
            Console.WriteLine($"Method '{methodName}' Not Found.");
        }
    }

Thanks!

emmauss commented 4 days ago

There's already a PR for this. https://github.com/AvaloniaUI/Avalonia.Labs/pull/89