Hot questions for Using Lottie in xamarin.forms

Top 10 Java Open Source / Lottie / xamarin.forms

Question:

I'm using Xamarin.Forms with Android and iOS. Trying to make Lottie animation work, but the latest version of Lottie (2.5.4) that supports .NET Standard 2.0 is giving a build error in the Android project:

The type or namespace name 'Droid' does not exist in the namespace 'Lottie.Forms' (are you missing an assembly reference?)

Looking at the Lottie GitHub source shows the namespace and class to be there, so I'm not sure why my Android project cannot find the reference.

I've tried downgrading Lottie, but no luck so far. The earliest version that contains the reference (2.5.0) does not work with .NET Standard.

Ideas?


Answer:

Turns out to be an issue with the Target Framework version for the Xamarin.Forms Android project.

The latest version of Visual Studio 2017 creates new Xamarin.Forms Android projects with Android 7.1 target framework.

Changing to Android 8.1 fixed the compiler issue that could not find the Lottie.Forms.Droid namespace.

Question:

I am trying to use Lottie to show animations, but I have a problem when I debug it for Android:

LottieAnimationView not displayed because it is too large to fit into a software layer (or drawing cache), needs 9072000 bytes, only 8294400 available

My XAML code:

<ContentPage.Content>
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    <forms:AnimationView
        x:Name="AnimationView"
        Animation="data.json"
        AutoPlay="True" Loop="true"
        VerticalOptions="FillAndExpand"
        HorizontalOptions="FillAndExpand"
        Scale="0.2"/>
</StackLayout>

Can anyone help me to fix this problem?


Answer:

you need to change the export settings of the animation in AfterEffects, to fit the software layer limit

Question:

I have created a content view , and inside this content view I've insert a lottie animation :

I'm trying to make it a common animation view so I can use it to multiple async Task

LoadingAnimation.xaml

<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:lottie="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"
             x:Class="Fit_Plans.Views.Common.LoadingAnimation">
  <ContentView.Content>
      <StackLayout>
          <lottie:AnimationView
              Grid.Column="0"
              Margin="-20"
              x:Name="LoadingAnimationView"
              Animation="loading_animation.json"

              AutoPlay="false"
              HeightRequest="160"
              WidthRequest="160"
              VerticalOptions="FillAndExpand"
              HorizontalOptions="FillAndExpand"/>
        </StackLayout>
  </ContentView.Content>
</ContentView>

Now in my SomeView.Xaml.cs

 async protected override void OnAppearing()
        {
            Product produits = new Product();          
            if(getListProduit ==null || getListProduit.Count<=0)
            {  
                getListProduit = await produits.loadMenuAsync(api, siteUrl);
                PopulateProductsLists(getListProduit);
            }
            base.OnAppearing();

        }

You can notice that I have a await asynch task :

getListProduit = await produits.loadMenuAsync(api, siteUrl);

Is it possible to make my lottie animation pop-up the animation.jason , and when the task is done close the popup? Or , what would be the best way to do such thing?


Answer:

If you want to show lottie animation in a popup, I encourage you to use the great Rg.Plugins.Popup library. You can get it from nuget and then create a popup page in which you should add your lottie animation (the same as you did above). This way you'll be able to reuse this popup animation page.

XAML of your popup page would look similar to this:

<pages:PopupPage 
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
    xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
    x:Class="MyProject.MyPopupPage">
    <!--You can set an animation in the xaml file or in the csharp code behind-->
    <pages:PopupPage.Animation>
        <animations:ScaleAnimation 
            PositionIn="Center"
            PositionOut="Center"
            ScaleIn="1.2"
            ScaleOut="0.8"
            DurationIn="400"
            DurationOut="300"
            EasingIn="SinOut"
            EasingOut="SinIn"
            HasBackgroundAnimation="True"/>
    </pages:PopupPage.Animation>
    <!--You can use any elements here which are extended from Xamarin.Forms.View-->
     <lottie:AnimationView
          Grid.Column="0"
          Margin="-20"
          x:Name="LoadingAnimationView"
          Animation="loading_animation.json"

          AutoPlay="true"
          HeightRequest="160"
          WidthRequest="160"
          VerticalOptions="FillAndExpand"
          HorizontalOptions="FillAndExpand"/>
</pages:PopupPage>

Here you can find the code to use your new popup page.

Question:

Is it possible to have a lottie animation when the splash screen is launched?

any examples out there on xamarin?

thanks


Answer:

No, it's impossible on iOS. The launch screen on iOS only accepts the static image and we can't add any code behind to adjust its display.

If you want to implement it on Xamarin. I recommend you to use a splash page as the App's MainPage first. Place your animation there. Then change the App's MainPage to your first page after the animation has finished.