我正在使用 Expo 和最新版本的 React-Native,我想为 View 或 Button 等组件提供微妙的触觉反馈。
我目前使用 animatable 在 onPress() 事件上启动脉冲动画,但动画只有在手指松开后才会触发。
我想要一个微妙的尺寸减小,同时按下然后在释放时平滑的补间 - 这会让我感觉优雅而不烦人。
这可以做到吗?我认为 Animation 或 Animatable 很容易支持这一点,但我找不到任何类似的例子。
我正在使用 Expo 和最新版本的 React-Native,我想为 View 或 Button 等组件提供微妙的触觉反馈。
我目前使用 animatable 在 onPress() 事件上启动脉冲动画,但动画只有在手指松开后才会触发。
我想要一个微妙的尺寸减小,同时按下然后在释放时平滑的补间 - 这会让我感觉优雅而不烦人。
这可以做到吗?我认为 Animation 或 Animatable 很容易支持这一点,但我找不到任何类似的例子。
您可以使用手势响应系统使自己的可触摸
基本上,您将使用 props onStartShouldSetResponder
、onResponderGrant
和onResponderRelease
传递给Animated.View
.
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
}}
/>
}
}