react-native-loader集成问题记录

Android iOS通用的;一个可用于做loading动画的组件:https://github.com/mohebifar/react-native-loader

感觉动画效果还可以,就拿来用了。
但是在新版RN上有些问题,需要修改。
在此记录下

基于RN-0.62.2 React-16.11.0,存在以下问题
在这里插入图片描述

查看https://github.com/react-native-community/art下的说明:

Migrating from the core react-native module

To migrate to this module you need to follow all the installation instructions above and change your imports from:

import {ART} from 'react-native';
const {Surface, Shape} = ART;

to:

import {Surface, Shape} from '@react-native-community/art';

因此需要安装@react-native-community/art,并修改ART模块下的数据导入方式

npm install @react-native-community/art --save

回到react-native-loader中,修改/src/下组件内导入ART模块的方式;
以Bar.js为例:


// const { Surface } = ART;  //原来的方式修改为下面的方式
import { Surface } from '@react-native-community/art';

完成!

代码跑起来以后,又出现了一个warning提示
在这里插入图片描述
大致原因是新版下Animated使用动画过程需要制定userNativeDriver属性,取值为true或false。因此看下/src/目录下的组件代码里面使用Animated是不是没设置。
以Bar.js为例:

animate(index) {
    Animated
      .sequence([
        Animated.timing(this.state.bars[index], {
          toValue: this.props.size * 2.5,
          duration: 600,
          useNativeDriver: false, // 添加这一行
        }),
        Animated.timing(this.state.bars[index], {
          toValue: this.props.size,
          duration: 600,
          useNativeDriver: false, // 添加这一行
        })
      ])
      .start(() => {
        if (!this.unmounted) {
          this.animate(index);
        }
      });
  }

OK,重新reload下,warning窗口没了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章