首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react原生如何在单个元素上使用多个动画

react原生如何在单个元素上使用多个动画
EN

Stack Overflow用户
提问于 2019-09-25 00:30:18
回答 1查看 474关注 0票数 1

我使用的是react-native-animatable插件,我想对同一文本使用多个动画。基本上,我想要做的是zoomIn一个文本,它的持续时间是1s,延迟是0s,然后当它完成后,用1s的持续时间和3s的延迟对相同的文本执行脉冲动画。然后最后zoomOut相同的文本,持续时间为1s,延迟为5s

到目前为止,只有最后一个动画执行

以下是我的代码

代码语言:javascript
复制
import * as Animatable from 'react-native-animatable';

<View style={{ backgroundColor: '#203546', flex: 1, alignItems: 'center', }}>
    <Animatable.Text animation="zoomIn" duration={1000} delay={0} 
                     animation="pulse" duration={1000} delay={3000} 
                     animation="zoomOut" duration={1000} delay={5000} 
                    style={{ color: 'white', fontSize: 20, position: 
                         'absolute', bottom: 0 }}>my text
   </Animatable.Text>
 </View>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-25 00:42:40

您可以在文本元素上设置ref并通过Imperative Usage触发动画。

示例:

代码语言:javascript
复制
componentDidMount() {
  this.textRef.zoomIn(1000).then(() => {
    setTimeout(() => {
        this.textRef.pulse(1000).then(() => {
          setTimeout(() => {
              this.textRef.zoomOut(1000)
          }, 5000)
      }, 3000)
    })
  });
}

render() {
  return (
    <Animatable.Text
        ref={el => this.textRef = el}
        style={{ color: 'white', fontSize: 20, position: 'absolute', bottom: 0 }}
      >
        my text
      </Animatable.Text>
  )
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58084629

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档