lottie-react-native: Lottie animation not showing on iOS
Description
Hello, I’m having an issue with an asset, that isn’t showing on iOS. I’ve recently updated react-native to 0.61.2. Previously to this update this asset was showing up. In Android the asset is showing up as is intended. This only happen with this particularly asset.
Steps to Reproduce
import React, { Component } from 'react';
import { Animated, Easing } from 'react-native';
import PropTypes from 'prop-types';
import LottieView from 'lottie-react-native';
import { sourceModel } from '@propTypes/sourceModel';
class SingleTimeAnimation extends Component {
state = {
progress: new Animated.Value(0)
};
componentDidMount() {
this.animateLottie();
}
componentDidUpdate(prevProps) {
const { source } = this.props;
if (prevProps.source !== source) {
this.resetAnimation();
}
}
resetAnimation = () => {
this.setState({ progress: new Animated.Value(0) }, this.animateLottie);
};
animateLottie = () => {
const { progress } = this.state;
const { duration } = this.props;
Animated.timing(progress, {
toValue: 1,
duration,
easing: Easing.linear,
useNativeDriver: true
}).start();
};
render() {
const { progress } = this.state;
const { source, style } = this.props;
return <LottieView style={style} source={source} progress={progress} />;
}
}
SingleTimeAnimation.propTypes = {
duration: PropTypes.number.isRequired,
source: sourceModel
};
export default SingleTimeAnimation;
Versions
“react-native”: “0.61.2” “lottie-react-native”: “^3.1.1”
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 18
- Comments: 24
As of Expo SDK V44 (React Native V0.64.3), lottie-react-native V5.0.1 and lottie-ios V3.2.3. What I have found that works is to call the
.play()method on the ref from theLottieView, on mount of the component. I referenced this from the official Expo Lottie documentation: https://docs.expo.dev/versions/latest/sdk/lottie/.Hope I managed to help someone!
My animations didn’t play either after updating RN + Lottie to the latest versions. I am accessing the lottie-files from my asset bundle. To get it working again, I somehow needed to delete the
.json-suffix from the asset path:Hope it helps someone.
Great! this way worked for me! thanks my bro
I resolved this issue by updating the versions and Podfile.
and i added
use_frameworks!to Podfile in ios folderFor anyone (like me) coming across this thread later, I found the underlying problem caused by the switch to using Swift. The JSON for the animations is being decoded in Swift and throws an error if it encounters a value it does not expect. For me this was: “bm”: 16 (blend mode 16), the library only supports blend modes 0-15 and “tp”: “op” - shape type Offset Path. The Swift JSON decoder throws an error when encountering these values. You can fix it by modifying the animation either by code or manually to remove the offending entries. There may be others I haven’t found that also trip it up.
I have written a JS function that makes the animations I’ve tried work (and they look fine):
This also includes a component that wraps LottieView and does it on the source automatically.
If you are having problems and want to see why Lottie can’t load a JSON file on IOS then you could go to the file node_modules/lottie-react-native/src/ios/LottieReactNative/ContainerView.swift and add replace @objc func setSourceJson to this - which will at least show the JSON parse error:
Same here
Also looking for a solution. Reinstalling didn’t work for me. On RN 60.4 With the recommended package versions for
lottie-react-nativeandlottie-ios.Hi, also happening in:
“react-native”: “0.61.2” “lottie-ios”: “3.1.3”, “lottie-react-native”: “3.2.1”,
In my case the asset I’m using works in Android and worked in IOS with previous* versions of react-native and lottie.
Other animations are working without problems.
* The animation works with: “react-native”: “0.61.2”, “lottie-ios”: “2.5.0”, “lottie-react-native”: “2.6.1”,
@a-j-douglass it sounds like you’re using expo which I’m not as familiar with. See if this section helps at all.
These logs typically show on xcode on a bare (non expo) react native build, but I’d be surprised if expo doesn’t provide some way of viewing these.
@henrykaasik , thanks a lot. It’s working for me. I have used this with
react-native-animated-loaderfrom hereAdded
use_frameworks!into Podfile in IOS folder as well.(This actually has solved my issue).I have the same issue. Any news about this or is there a workaround?