How do I enable touch on multiple buttons simultaneously in react native?

后端 未结 4 2068
旧巷少年郎
旧巷少年郎 2020-12-16 02:02

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

4条回答
  •  爱一瞬间的悲伤
    2020-12-16 02:33

    I used react-native-gesture-handler. Install it and just replace

    import { TouchableOpacity } from 'react-native';

    with

    import { TouchableOpacity } from 'react-native-gesture-handler';

    Example

    
    
      this.console('Button 2 pressed')}
      onPressOut={()=>this.console('Button 2 released')}>
        
          BUTTON 2
        
      
    
      this.console('Button 1 pressed')}
      onPressOut={()=>this.console('Button 1 released')}>
        
          BUTTON 1
        
      
    
    
    

    Link: https://software-mansion.github.io/react-native-gesture-handler/docs/component-touchables.html

    This library also offers button components which can be directly used instead of wrapping Text with TouchableOpacity

提交回复
热议问题