0

I am using sample.json image file which is for bodymovin animation in my page through Lottie for React Native.

I am getting the image but the image is not fully retrieved, some parts of the image is missing and also in some side of the image, green color pasted on the image.

But i checked the sample.json through online json image viewr. But there is no issue with the image from the source

here is issue https://i.stack.imgur.com/yFZfg.jpg

here is original image https://i.stack.imgur.com/4sBzg.jpg

so here is my code

 import React from 'react';
    import { Animated, Easing, easing  } from 'react-native';
    import Animation from 'lottie-react-native';

    export default class BasicExample extends React.Component {
       constructor(props) {
        super(props);
        this.state = {
         progress: new Animated.Value(0.5),
      };
    }

    componentDidMount() {
     this.startAnimation();
    }
    startAnimation() {
    Animated.timing(
      this.state.progress,
      {
      toValue: 1,
      from: 0,
      to: 1,
      duration: 5000,
      }
    )
    .start(() => {
       // Restart at end
       this.state.progress.setValue(0);
       this.startAnimation();
     });
    }
    render() {
       const easing = Easing.inOut(Easing.quad);
       const { Animate } = this.props;
      return (
          <Animation
             style={{
              width: 300,
              height: 300,
            }}
           source={this.props.Animate}
           progress={this.state.progress}
          />
         );
       }
     }

i installed lottie npm also.

so this is my issue please help me to overcome this Thanks in advance

1 Answers1

0

UPDATE: Now that I looked your code closer I found out that you're animating by changing the value of progress prop. That's not how to do it. You need to use ref for referring the animation to.

return (
    <Animation
      ref={(animation) => this.myAnimation = animation}
      style={{
        width: 300,
        height: 300,
      }}
      source={this.props.Animate}
    />
);

And then:

componentDidMount() {
  this.startAnimation();
}

startAnimation() {
  this.myAnimation.play();
}

OLD ANSWER:

Your code seems perfectly legit and if you see an image, it proofs that you're doing it right.

I'd assume there's either something wrong with the JSON or then Lottie just interprets values wrong.

I've encountered small styling issues on Android devices, but not with iOS. And they're mostly related to alignment.

If you don't get any proper answers here in SO, I'd suggest you to file an issue to github (see this for instance: https://github.com/airbnb/lottie-react-native/issues/182)

Samuli Hakoniemi
  • 18,740
  • 1
  • 61
  • 74
  • yeah the same issue i am facing. this animation is coming in iPhone...in android even the image is not coming...when run in android the app is getting killed and closed... i am using CRNA through Expo –  Oct 04 '17 at 09:17
  • why because the animation is already done in json right...so we dont need to hard animate ..is not it ? @zvona –  Oct 04 '17 at 09:22
  • it says : Possible Unhandled Promise Rejection (id: 0): ReferenceError: Can't find variable: startAnimation –  Oct 04 '17 at 10:52
  • Sorry, it's `this.startAnimation()` (the function defined below). Or you could execute `this.myAnimation.start()` in `componentDidMount` as well. I'll update the answer. – Samuli Hakoniemi Oct 04 '17 at 11:07
  • Possible Unhandled Promise Rejection (id: 0): TypeError: this.myAnimation.start is not a function. (In 'this.myAnimation.start()', 'this.myAnimation.start' is undefined) ..... why it says its undefined , where we need to define it –  Oct 04 '17 at 11:09
  • app is getting terminating after a couple of minutes after says this error –  Oct 04 '17 at 11:12
  • @Vijay sorry, it was a typo. I fixed the answer again: correct execution in Lottie is `this.myAnimation.play()`, not `.start()`. – Samuli Hakoniemi Oct 04 '17 at 11:13
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/155900/discussion-between-vijay-and-zvona). @ zvona –  Oct 04 '17 at 11:13
  • can you come on chat please –  Oct 04 '17 at 11:19