javascript - React Native 中同一元素上的出/入动画

标签 javascript reactjs react-native react-native-animatable

我有一个TextView,它将在下一次渲染时fadeOutDown旧数据和fadeInDown新数据。我该如何实现这个目标?我正在使用 react-native-animatable 库,并已成功制作一个动画,但不知道如何制作两个动画。

<Animatable.View animation={this.props.animation} style = {styles.innerView2}>
  <Text text = "abcd" style = {{alignItems: 'flex-start', width: DEVICE_WIDTH - 20, textAlign: 'left'}}/>
</Animatable.View>

最佳答案

为 Animatable 组件分配一个 ref,然后在 componentDidUpdate 上,您可以重新触发动画

componentDidUpdate() {
  if (this.view !== undefined && this.view !== null) {
    this.view.fadeIn(1000);
  }
}

<Animatable.View
  ref={ref => (this.view = ref)}
  animation="fadeIn"
  easing="ease-in">
  <Text>{this.state.newText}</Text>
</Animatable.View>

这是一个snack供您引用

关于javascript - React Native 中同一元素上的出/入动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52150383/

相关文章:

javascript - 什么时候浏览器会在 SSL 站点上抛出不安全内容警告

reactjs - 为什么在主题 UI 上使用 Rebass?

reactjs - Ant Design 表单设置值表单 props

reactjs - 如何在react js中检查 Material ui主题的类型? (浅色或深色)

javascript - 为什么外部 javascript 库会阻止我页面上的 javascript?

php - 当代理*总是*声明安全连接时检测 SSL

javascript - 如何在 Three.js 中加载 .obj 3D 模型?

react-native - react-native 中带有可折叠部分标题的部分列表

javascript - 在 React-Native 中获取 'TypeError: interpolate is not a function'

react-native - 在 native react 中获得 GPS 精度