简体   繁体   English

如何启动本机onTouchDown动画

[英]How to start react-native onTouchDown anination

I am using Expo and the latest version of React-Native and I want to provide a subtle tactile feedback for Components like a View or Button. 我正在使用Expo和最新版本的React-Native,并且想为诸如“视图”或“按钮”之类的组件提供微妙的触觉反馈。

I currently use animatable to start a pulse animation on the onPress() event but the animation only fires once the finger is released. 我目前使用ananitable在onPress()事件上启动脉冲动画,但是仅在松开手指后才触发动画。

I want a subtle size reduction whilst press then a smooth tween back when released - that would feel elegant and not annoying to me. 我希望在缩小尺寸的同时按下,然后在松开时进行平滑的补间,这会让我感觉优雅而不烦人。

Can this be done? 能做到吗? I thought Animation or Animatable would have easily supported this but I can't find any similar examples. 我以为Animation或Animatable可以轻松支持此功能,但是我找不到任何类似的示例。

You could make your own touchable using the Gesture Responder System 您可以使用Gesture Responder系统使自己的触摸效果

Basically you'll use the props onStartShouldSetResponder , onResponderGrant , and onResponderRelease passed to an Animated.View . 基本上,您将使用传递给Animated.View的道具onStartShouldSetResponderonResponderGrantonResponderRelease

class MyTouchable extends React.PureComponent {
  render(){
    <Animated.View
      style={{ your styles, and animation values }} 
      onStartShouldSetResponder={() => true}
      onResponderGrant={({ nativeEvent }) => {
        //run your animations here
      }}
      onResponderRelease={({ nativeEvent }) => {
        //animate back to zero, call your onPress function
        //passed via props
      }}
    />
  }
}

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

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