React Native-如何在shouldComponentUpdate中比较两个Animated.Values?

问题描述

我正在优化清单项目(渐进式图像),并避免扩展React.PureComponent,我决定实现自己的shouldComponentUpdate生命周期方法。

我的progressive images具有两个动画值:

1. thumbnailOpacity
2. imageOpacity

我的应该组件更新必须看起来像这样:

state = {
   isLoading: true,thumbnailOpacity: new Animated.Value(0),imageOpacity: new Animated.Value(0)
}

shouldComponentUpdate(nextProps,nextState) {
  /*
    React's PureComponent implement a shouldComponentUpdate with shallow comparison.
    This is expensive here,because it need to check all our props. For a good bit-level performance,use the strictest rules for our list item.

    This component must re-render only when the state change.
  */

  return (
     nextState.isLoading !== this.state.isLoading ||
     nextState.thumbnailOpacity !== this.state.thumbnailOpacity ||
     nextState.imageOpacity !== this.state.imageOpacity
  );        
}

但是由于Animated值不是原始数据类型,所以我不知道如何进行浅浅的比较。

有什么想法吗?谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)