lottie-react-native: Lottie Editor-generated file crashes application on Android Expo app but not iOS Expo app

Lottie file generated by Lottie Editor works on one platform and crashes the other

When editing a working Lottie file in Lottie’s web-based editor, the resulting export crashes my Expo app on Android but renders properly on iOS. Prior to the edit, the original file works fine on both Android and iOS.

Steps to Reproduce

  1. Upload this Lottie file in the Lottie Editor and replace one of the images in it. (I used GIMP)
  2. Export the JSON for your edit and embed it in an Expo application (link to an example with one image edited already)
  3. Run the Expo application on an Android device and an iOS device

Expected behavior: The Lottie file renders as displayed in the editor on both platforms without issue

Actual behavior: The Android Expo app crashes immediately but the iOS app renders it properly

Versions

...
lottie-react-native@5.1.5
expo-image@1.0.0
expo@48.0.10
...

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 17

Commits related to this issue

Most upvoted comments

downloading and using a Json from lottiefiles.com directly works fine, but when you open it in the editor and download it from there, it crashes the app.

For those who are using their own dev client instead of expo go (you bundle your app with dev-client build) and not seeing any animation following this guide from Expo: https://docs.expo.dev/versions/latest/sdk/lottie/ , try to rebuild your dev-client build and install again. This works for me.

I guess it’s because our build doesn’t have the native component that’s required. It’s weird that it doesn’t throw any error or warning but instead render a blank component.

Hope this helps

Lottie is now updated for Expo Go in the next release of Expo SDK. However, those who are using Expo Prebuilt should not have any problems. Cheers!

Here is how I finally did it :

import Color from 'color';
import set from 'lodash.set';

export const colouriseLottie = (json: unknown, colorByPath: { [k: string]: string }) => {
  const nextJson = JSON.parse(JSON.stringify(json));

  Object.entries(colorByPath).forEach(([path, color]) => {
    // incase undefined/null/falsy is passed to color
    if (!color) return;
    const rgbValues = Color(color).object();
    const rFraction = rgbValues.r / 255;
    const gFraction = rgbValues.g / 255;
    const bFraction = rgbValues.b / 255;

    const pathParts = path.split('.');
    set(nextJson, [...pathParts, 0], rFraction);
    set(nextJson, [...pathParts, 1], gFraction);
    set(nextJson, [...pathParts, 2], bFraction);
  });

  return nextJson;
};

  • then apply it to the your animation
import LottieView from 'lottie-react-native';
import React, { useMemo } from 'react';
import WelcomingSquare from '@/assets/animations/welcoming-square.json';
import { colouriseLottie } from '@/helpers/colors';

const WelcomeAnimation = ({ color, ...props }: { color?: string }) => {
  const colorizedSource = useMemo(
    () =>
      colouriseLottie(WelcomingSquare, {
        // Shape Layer 1.Shape 1.Stroke 1
        'assets.0.layers.14.shapes.0.it.1.c.k': color || '#D4E0FF',
      }),
    [],
  );

  return <LottieView autoPlay loop source={colorizedSource} {...props} />;
};

export default WelcomeAnimation;

Hopefully it helps someone else

I’m experiencing the same problem. lottie-react-native @5.1.4

I have the same problem. Even with lottie-react-native@6.0.0-rc.3