如何在 React Native 中同时启用多个按钮的触摸? [英] How do I enable touch on multiple buttons simultaneously in react native?

查看:50
本文介绍了如何在 React Native 中同时启用多个按钮的触摸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要当我触摸并按住一个按钮时,我也应该能够触摸按钮 1.

I need that when I am touching and holding one button then I should also be able to touch on the button 1.

<View>
  
  <View 
  onStartShouldSetResponder={()=>this.console("Button 2 Clicked")}>
    <Text>BUTTON 2</Text>
  </View>
  
  <TouchableOpacity 
  onPressIn={()=>this.console('Button 1 pressed')}
  onPressOut={()=>this.console('Button 1 released')}>
    <View>
      <Text>BUTTON 1</Text>
    </View>
  </TouchableOpacity>

</View>

基本上,我有一个屏幕,我可以通过点击并按住录制按钮(按钮 1)来录制视频.在同一屏幕上,我有一个翻转相机按钮(按钮 2).我希望我可以在录制视频时点击翻转相机按钮.

Basically, I have a screen where I can record a video by tapping and holding the record button(Button 1). On the same screen, I have a flip camera button (Button 2). I want that I should be able to click on the flip camera button while I am recording the video.

推荐答案

这个问题可以使用View组件的onTouchStart、onTouchEnd props轻松解决,无需使用手势响应方法.

This problem can easily be resolved using onTouchStart, onTouchEnd props of View component without using gesture responder methods.

所以修改后的代码看起来像

So the modified code will look like

<View>

  <View onTouchStart={()=>this.console("Button 2 Clicked")}>
    <Text>BUTTON 2</Text>
  </View>

  <View 
    onTouchStart={()=>this.console('Button 1 pressed')}
    onTouchEnd={()=>this.console('Button 1 released')}>
      <Text>BUTTON 1</Text>
  </View>

</View>

这篇关于如何在 React Native 中同时启用多个按钮的触摸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆