🏗️
MauiReactor
  • What is MauiReactor?
  • What's new in Version 2
  • What's new in Version 3
  • Getting Started
  • Getting Started Version 2
  • Components
    • State-less Components
    • Stateful Components
      • Inline Components
    • Component life-cycle
    • Component Properties
    • Component with children
    • Component Parameters
    • Theming
    • Navigation
      • NavigationPage
      • Shell
      • Back button
    • Controls
      • Button
      • RadioButton
      • FlyoutPage
      • CollectionView
        • Interactions
        • Layout
        • Selection
        • Empty view
        • Scrolling
        • Grouping
      • IndicatorView
      • Picker
      • Shell
      • Label
    • Wrap 3rd party controls
      • Lottie animations
      • Provide DataTemplate to native controls
    • Accessing native controls
    • Animation
      • Property-Based
      • AnimationController
      • Timer
    • Graphics
      • CanvasView control
    • Window
    • Testing
    • XAML Integration
  • Deep dives
    • Native tree and Visual tree
    • Dependency injection
    • Working with the GraphicsView
    • Migrating from MVVM Model
    • Using XAML Resources
    • Behaviors
  • resources
    • Source and Sample Applications
  • Q&A
    • How to deal with state shared across Components?
    • Does this support ObservableCollection for CollectionView?
    • Do we need to add states to create simple animations such as ScaleTo, FadeTo, etc on tap?
    • How to deal with custom dialogs/popups?
  • How to create a Menu/ContextMenu?
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Components
  2. Wrap 3rd party controls

Lottie animations

Describe how integrate Lottie animation components in MauiReactor

PreviousWrap 3rd party controlsNextProvide DataTemplate to native controls

Last updated 2 years ago

Was this helpful?

This article is based on the package which it's currently in preview.

Since Xamarin Forms, developers can integrate powerful animations inside their applications thanks to animation system implementation.

In .NET MAUI, you have the ability to play Lottie files using a relatively recent Skia-based implementation available inside package.

Using Lottie controls in MauiReactor is straightforward, it just requires you to add a package reference in csproj and to create a few scaffold classes inside your project.

First of all, add the reference to and MauiReactor Scaffold Generator packages:

<PackageReference Include="Reactor.Maui.ScaffoldGenerator" Version="1.0.74-beta" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="SkiaSharp.Extended.UI.Maui" Version="2.0.0-preview.61" />

The next step is to call the method UseSkiaSharp() inside the MainProgram.cs file to enable SkiaSharp handlers.

var builder = MauiApp.CreateBuilder();
builder
    .UseMauiReactorApp<MainPage>()
    .UseSkiaSharp()

After that, you have to create a few MauiReactor wrappers for the control SKLottieView which can load and play the animation:

[Scaffold(typeof(SkiaSharp.Extended.UI.Controls.SKSurfaceView))]
partial class SKSurfaceView { }

[Scaffold(typeof(SkiaSharp.Extended.UI.Controls.SKAnimatedSurfaceView))]
partial class SKAnimatedSurfaceView { }

[Scaffold(typeof(SkiaSharp.Extended.UI.Controls.SKLottieView))]
partial class SKLottieView { }

Note that you can't just wrap the SKLottieView but you have to generate wrappers also for the ancestors SKAnimatedSurfaceView and SKSurfaceView up to the TemplateView class which is already wrapped by MauiReactor itself.

Finally, you can use the control inside your component:

new SKLottieView()
    .Source(new SkiaSharp.Extended.UI.Controls.SKFileLottieImageSource()
    {
        File = "dotnetbot.json"
    })
    .IsAnimationEnabled(true)
    .RepeatCount(-1)
    .HeightRequest(200)
    .WidthRequest(200)
    .HCenter()

The animation file (dotnetbot.json in the above example) must be placed inside the Resources\Raw folder.

This should be the final page with the animation running:

SkiaSharp.Extended.UI.Maui
Lottie
https://github.com/mono/SkiaSharp.Extended/
SkiaSharp.Extended.UI.Maui
Lottie animation in MauiReactor