mono / SkiaSharp.Extended

SkiaSharp is a cross-platform, comprehensive 2D graphics API for all .NET platforms. And, here is where you will find all sorts of extras that you can use with it.
https://mono.github.io/SkiaSharp.Extended
MIT License
218 stars 69 forks source link

[BUG] Animation is not being started for the first time in the popup after showing that popup #279

Closed Alex-Dobrynin closed 2 months ago

Alex-Dobrynin commented 2 months ago

Description

I'm developer of MPowerKit.Popups library. And one of the users of this library experiencing an issue, when he has lottie animation in that popup and tries to open popup and the animation is not started for the first opening. but if user closes popup and open again the animation is started. Other views being rendered in the popup as expected all the time

There is workaround that forces to start lottie animation in the codebehind of the popup, that works, but it is ugly. Shortly, you can add the lottie animation view to the view tree from the codebehind after task delay. that code is below

Related issues: https://github.com/MPowerKit/Popups/issues/1 https://github.com/mono/SkiaSharp.Extended/issues/264

Code

<?xml version="1.0" encoding="utf-8" ?>
<popup:PopupPage x:Class="MauiApp1.LoadingMopup"
                 xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:local="clr-namespace:MauiApp1"
                 xmlns:popup="clr-namespace:MPowerKit.Popups;assembly=MPowerKit.Popups"
                 xmlns:skia="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
                 Title="PopupTestPage"
                 BackgroundColor="#80000000"
                 BackgroundInputTransparent="False"
                 CloseOnBackgroundClick="True">

    <ContentView BackgroundColor="Orange"
                 VerticalOptions="Center">
        <VerticalStackLayout x:Name="stack"
                             BackgroundColor="Purple"
                             HorizontalOptions="Center">
            <Label Text="kdjsnslhnsdhm;lsdhs" />
            <!--  comment here and uncomment in the codebehind  -->
            <skia:SKLottieView x:Name="LottieAnimation"
                               Margin="20"
                               Padding="0"
                               BackgroundColor="Blue"
                               HeightRequest="150"
                               IsAnimationEnabled="True"
                               RepeatCount="-1"
                               Source="cat.json"
                               WidthRequest="150" />
        </VerticalStackLayout>
    </ContentView>
</popup:PopupPage>
using SkiaSharp.Extended.UI.Controls;

namespace MauiApp1;

public partial class LoadingMopup : MPowerKit.Popups.PopupPage
{
    public LoadingMopup()
    {
        InitializeComponent();
        // Uncomment here
        //InitializeLottieAsync();
    }

    public async void InitializeLottieAsync()
    {
        await Task.Delay(1);
        SKLottieView myanimatedview = new()
        {
            Source = new SKFileLottieImageSource()
            {
                File = "cat.json"
            },
            RepeatCount = -1,
            IsAnimationEnabled = true,
            IsVisible = true,
            WidthRequest = 150,
            HeightRequest = 150,
            BackgroundColor = Colors.Blue,
            Margin = new Thickness(20),
        };
        stack.Add(myanimatedview);
    }
}

Expected Behavior

The animation started each time user opens the popup

Actual Behavior

The animation is not being started for the first time, after closing the popup and opening again the animation is being started.

Basic Information

Reproduction Link

LottiePopupTest.zip

Alex-Dobrynin commented 2 months ago

fixed in my lib