简体   繁体   English

React Native:自定义TouchableOpacity动画速度

[英]React Native: Customizing TouchableOpacity Animation Speed

According to the TouchableOpacity docs , there is an activeOpacity prop to change the end opacity level and there is a setOpacityTo function to animate the component to any opacity level. 根据TouchableOpacity 文档 ,有一个activeOpacity丙改变端不透明度水平并有一个setOpacityTo函数到组件动画到任何不透明度水平。 There doesn't seem to be anything about changing how fast the animation should take. 似乎没有任何改变动画应该多快的时间。

How would I go about changing the animation speed? 如何更改动画速度? Is there a props for this? 为此有道具吗? Do I need to make my own custom Animated.View ? 我需要制作自己的自定义Animated.View吗?

That'd be the duration part of the method... 那就是方法的持续时间部分...

setOpacityTo(value: number, duration: number)

React-native is using setOpacityTo in the background to animate the opacity using the setNativeProps with TouchableOpacity . React-native在后台使用setOpacityTo通过setNativeProps with TouchableOpacity设置不透明度的动画。

setOpacityTo(value) {
  // Redacted: animation related code
  this.refs[CHILD_REF].setNativeProps({
    opacity: value
  });
},

So, it looks like you can also just create your own Animated event if you wanted to. 因此,如果您愿意,您似乎也可以只创建自己的Animated事件。 Here's how touchable opacity uses setOpacityTo , making sure to set the useNativeDriver to true . 这是可触摸的不透明度使用setOpacityTo ,请确保将useNativeDriver设置为true

  setOpacityTo: function(value: number, duration: number) {
    Animated.timing(
      this.state.anim,
      {
        toValue: value,
        duration: duration,
        easing: Easing.inOut(Easing.quad),
        useNativeDriver: true,
      }
    ).start();
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM