React Native 0.62 警告 Animated: "useNativeDriver" was not specified

React Native 2020-05-07 阅读 1318 评论 0

问题描述

React Native 项目升级到 0.62,之前写的有关 Animated 方法,出现了警告。

WARN Animated: "useNativeDriver" was not specified. This is a required option and must be explicitly set to "true" or "false"

解决方法

如提示所说,需要明确指定 useNativeDriver 选项,并且设置为 true 或者 false 。

1. Composing animations

参考 官网的 Animated api ,包括 Animated.decay()Animated.timing()Animated.spring()Animated.parallel()Animated.sequence()等创作动画的方法,配置 config 参数时指定  useNativeDriver 。如:

Animated.timing(this.state.animatedValue, {
  toValue: 1,
  duration: 500,
  useNativeDriver: true, // 添加这一行
}).start();

2. Animatable components 组件

包括 Animated.ImageAnimated.ScrollViewAnimated.TextAnimated.ViewAnimated.FlatListAnimated.SectionList 等动画视图,绑定Animated.event() 时, config 参数添加 useNativeDriver 。如:

<Animated.ScrollView
  scrollEventThrottle={1}
  onScroll={Animated.event(
    [{ nativeEvent: { contentOffset: { y: this.state.animatedValue } } }],
    { useNativeDriver: true } // 添加这一行
  )}
>
  {content}
</Animated.ScrollView>
最后更新 2020-05-07
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });