React Native 插件系列之lottie-react-native


1、背景

  首先,什么是lottie?

  Lottie是Airbnb開源的一個支持 Android、iOS 以及 ReactNative,利用json文件的方式快速實現動畫效果的庫。

  其次,為什么需要lottie?

  因為我的APP想要酷炫一點呀,其實就想加一個首頁動畫,不至於太朴素和單調。

2、安裝

 ios安裝方式:

npm i --save lottie-react-native

react-native link lottie-ios

react-native link lottie-react-native

 

3、代碼示例

  

import React from 'react';
import { Animated } 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),
    };
  }

  componentDidMount() {
    Animated.timing(this.state.progress, {
      toValue: 1,
      duration: 5000,
    }).start();
  }

  render() {
    return (
      <Animation
        style={{
          width: 200,
          height: 200,
        }}
        source={require('../path/to/animation.json')}
        progress={this.state.progress}
      />
    );
  }
}

4,遇到的問題以及解決方案

  1,報錯 Warning: Failed prop type: undefined is not an object (evaluating  '_reactNative.ViewPropTypes,style')

  我當時用的React-Native版本是0.42.3 后來升級到0.47.0,解決這個問題

 

  升級rn后,又報如下錯誤:

  

  這是因為升級版本后,腳本換了,

  

 

  但是后來又報錯了,還是起不來,

  

  這是因為react,react-native,react-dom安裝有問題,刪除node_modules。

  react和react-dom我安裝的是16.0.0-alpha.12版本

   

  在模擬器上跑起來沒問題,但是打包報錯:

  

  解決如下,在LottieReactNative中配置如下:

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM