reactjs - react native : how to make TouchableOpacity take specific action when user holds it down?

标签 reactjs react-native touchableopacity

在我的 React Native 应用程序中,我有一个 TouchableOpacity,当我单击它时,它会执行特定操作。但我希望如果用户按住它一秒钟,它会采取不同的操作。有办法做到这一点吗?

最佳答案

记录到文档:https://reactnative.dev/docs/handling-touches

handlerLongClick = () => {
    console.log('Button pressed long');
};

handlerClick = () => {
    console.log('Button pressed');
};

<TouchableOpacity
    onLongPress={this.handlerLongClick}
    onPress={this.handlerClick}
/>

关于reactjs - react native : how to make TouchableOpacity take specific action when user holds it down?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61857617/

相关文章:

reactjs - Storybook + formik,控件不显示

reactjs - 可触摸的不透明度标题 React Native

带有 TouchableOpacity onpress 的图像在 React Native 中不起作用

javascript - 在 React-Native 中手动设置不透明度的音量 onPress of TouchableOpacity

javascript - react : how to change page when using react-navigation and react-router?

css - 将 Lighten Css 特性嵌入到 Jsx/React

reactjs - 暴露一个 React 组件的函数

javascript - React-Native:使用 require() 访问文件中包含的方法

reactjs - react native 传奇 yield 调用不起作用

react-native - 为什么 Dimensions.get ('window' ).height 在 iOS 上返回 0?