如何在 React Native 中同时启用多个按钮的触摸?

如何在 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>