Skip to content

[BUG] MAUI.iOS does not work with SKLottieView or SKCanvasView #148

Open
@MrDeej

Description

@MrDeej

Description

It does work on Android and Windows. But not on iOS

Does not work (no exception, no animation):
<skia:SKLottieView Source="lottieoppgaver.json" HeightRequest="200" WidthRequest="200" RepeatCount="-1" RepeatMode="Restart" HorizontalOptions="Center"/>

Also does not work:

<skia2:SKCanvasView
                x:Name="skiaView"
                PaintSurface="OnPaintSurface"
                IgnorePixelScaling="True"
                HorizontalOptions="Center"/>


using CommunityToolkit.Maui.Views;
using SkiaSharp;
using SkiaSharp.Views.Maui;

namespace Fa.Maui2.Views.Oppgaver
{
    public partial class StartPage: ContentPage
    {
        SkiaSharp.Skottie.Animation animation;
        double time;
        public StartPage()
        {
            InitializeComponent();
        }

      


        protected override void OnDisappearing()
        {
            base.OnDisappearing();

            animation = null;
        }

        protected override async void OnAppearing()
        {
            base.OnAppearing();

            // Lottie file from https://lottiefiles.com/107653-trophy
            var json = await FileSystem.OpenAppPackageFileAsync("lottieoppgaver.json");

            // load Lottie animation
            SkiaSharp.Skottie.Animation.TryCreate(json, out animation);

            // Read important values
            var duration = animation.Duration.TotalSeconds;
            var interval = 1.0 / 60.0;

            // Start a timer to tick
            Dispatcher.StartTimer(TimeSpan.FromSeconds(interval), () =>
            {
                // null means the page is going away
                if (animation is null)
                    return false;

                // Move to the next frame
                animation.SeekFrameTime(time);

                // Increase the time for the next frame
                time = (time + interval) % duration;

                // Invalidate the canvas
                skiaView.InvalidateSurface();

                return true;
            });
        }

        private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            // Clear the canvas
            canvas.Clear(SKColors.Transparent);

            // Render the animation
            animation?.Render(canvas, e.Info.Rect);
        }
    }
}



Expected Behavior

Animation should show

Actual Behavior

SKLottieView- Does not show anything
SKCanvasView - Crashes with exception:
image

Basic Information

	<PackageReference Include="SkiaSharp.Skottie" Version="2.88.4-preview.3" />
	<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.4-preview.3" />
	<PackageReference Include="SkiaSharp.Extended.UI.Maui" Version="2.0.0-preview.63" />
  • Last known good version: NA

  • IDE: Microsoft Visual Studio Professional 2022 (2) (64-bit) - Preview
    Version 17.4.0 Preview 3.0

  • Platform Target Frameworks:

    • iOS: net7.0-ios
      image
  • Target Devices:

    • Device IPhone 12


Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions