首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当道具发生变化时,我如何重新设置动画的反应-本地动画?

当道具发生变化时,我如何重新设置动画的反应-本地动画?
EN

Stack Overflow用户
提问于 2019-10-30 06:35:33
回答 1查看 869关注 0票数 1

我想重置动画和重播,因为道具的变化,但它只工作一次,在一开始。我使用了react-native-animatable npm库,无法找到重置动画的解决方案。

这是我的动画代码。

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

function ResetAnimation (changeAnimation) {
   const zoomAnimation = {
    0: {
      scale: 1
    },
    0.5: {
      scale: 2
    },
    1: {
      scale: 1
    }
  };
  return (
    <View>
       <Animatable.View animation = {zoomAnimation}>
         <View>
          // At first it works well but next no animation.
          .......
         </View>
       </Animatable.View>
    </View>
 );
}

帮帮我。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-30 07:45:37

可以将动画定义为状态:

代码语言:javascript
复制
construstor(props){
  super(props)
  this.state = {
     zoomAnimation = {
    0: {
      scale: 1
    },
    0.5: {
      scale: 2
    },
    1: {
      scale: 1
    }
  }
   }
}

// then use it in the view
<Animatable.View animation = {this.state.zoomAnimation}>
         <View>
          // At first it works well but next no animation.
          .......
         </View>
       </Animatable.View>

// when you want reset it, you call this.setState,
this.setState({
zoomAnimation = {
    0: {
      scale: 1
    },
    0.5: {
      scale: 2
    },
    1: {
      scale: 1
    }
  }

})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58619801

复制
相关文章

相似问题

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