React native 如何处理触摸2个按钮

React native 如何处理触摸2个按钮,react-native,React Native,我是react native的新手,我正在尝试在android上创建一个gamepad(使用手机在pc上玩游戏)。我有6个按钮:左,右,上,下,射击和跳跃 当我按下按钮时,它会将当前键发送到我的计算机vie socket.io上的nodejs 它起作用了。但问题是:当我按住左键然后按下射击键时,它就不能射击了。我如何分别处理多个按钮的上下 这是我的密码: import React, { Component } from 'react'; import { View, StyleS

我是react native的新手,我正在尝试在android上创建一个gamepad(使用手机在pc上玩游戏)。我有6个按钮:左,右,上,下,射击和跳跃

当我按下按钮时,它会将当前键发送到我的计算机vie socket.io上的nodejs

它起作用了。但问题是:当我按住左键然后按下射击键时,它就不能射击了。我如何分别处理多个按钮的上下

这是我的密码:

import React, { Component } from 'react';
import {
    View,
    StyleSheet,
    Text,
    StatusBar,
    TextInput,
} from 'react-native';
import io from 'socket.io-client';

class GameController extends Component {

    state = {
        settingModalVisible: false,
        socketIo: io.connect('http://192.168.0.105:3000')
    };

    render() {
        return (
            <View style={styles.container}>
                <StatusBar hidden />
                <View style={styles.row}>
                    <Text>Setting</Text>
                    <TextInput style={{ height: 40, borderColor: 'gray', borderWidth: 1 }} />
                </View>
                <View style={styles.row}>
                    <View
                        onTouchStart={(e) => {
                            this.state.socketIo.emit('buttonDown', 'a');
                            return true;
                        }}
                        onTouchEnd={(e) => {
                            this.state.socketIo.emit('buttonUp', 'a');
                            return true;
                        }}
                        style={styles.button}
                    >
                        <Text>Left</Text>
                    </View>
                    <View
                        onTouchStart={(e) => {
                            this.state.socketIo.emit('buttonDown', 'd');
                            return true;
                        }}
                        onTouchEnd={(e) => {
                            this.state.socketIo.emit('buttonUp', 'd');
                            return true;
                        }}
                        style={styles.button}
                    >
                        <Text>Right</Text>
                    </View>
                    <View
                        onTouchStart={(e) => {
                            this.state.socketIo.emit('buttonDown', 'w');
                            return true;
                        }}
                        onTouchEnd={(e) => {
                            this.state.socketIo.emit('buttonUp', 'w');
                            return true;
                        }}
                        style={styles.button}
                    >
                        <Text>Up</Text>
                    </View>
                    <View
                        onTouchStart={(e) => {
                            this.state.socketIo.emit('buttonDown', 's');
                            return true;
                        }}
                        onTouchEnd={(e) => {
                            this.state.socketIo.emit('buttonUp', 's');
                            return true;
                        }}
                        style={styles.button}
                    >
                        <Text>Down</Text>
                    </View>
                    <View
                        onTouchStart={(e) => {
                            this.state.socketIo.emit('buttonDown', 'j');
                            return true;
                        }}
                        onTouchEnd={(e) => {
                            this.state.socketIo.emit('buttonUp', 'j');
                            return true;
                        }}
                        style={styles.button}
                    >
                        <Text>Shoot</Text>
                    </View>
                    <View
                        onTouchStart={(e) => {
                            this.state.socketIo.emit('buttonDown', 'k');
                            return true;
                        }}
                        onTouchEnd={(e) => {
                            this.state.socketIo.emit('buttonUp', 'k');
                            return true;
                        }}
                        style={styles.button}
                    >
                        <Text>Jump</Text>
                    </View>
                </View>
            </View>
        );
    }

}
import React,{Component}来自'React';
进口{
看法
样式表,
文本,
状态栏,
文本输入,
}从“反应本机”;
从“socket.io客户端”导入io;
类GameController扩展组件{
状态={
设置ModalVisible:false,
socketIo:io.connect('http://192.168.0.105:3000')
};
render(){
返回(
背景
{
this.state.socketIo.emit('buttonDown','a');
返回true;
}}
onTouchEnd={(e)=>{
this.state.socketIo.emit('buttonUp','a');
返回true;
}}
style={style.button}
>
左边
{
this.state.socketIo.emit('buttonDown','d');
返回true;
}}
onTouchEnd={(e)=>{
this.state.socketIo.emit('buttonUp','d');
返回true;
}}
style={style.button}
>
赖特
{
this.state.socketIo.emit('buttonDown','w');
返回true;
}}
onTouchEnd={(e)=>{
this.state.socketIo.emit('buttonUp','w');
返回true;
}}
style={style.button}
>
向上的
{
this.state.socketIo.emit('buttonDown','s');
返回true;
}}
onTouchEnd={(e)=>{
this.state.socketIo.emit('buttonUp','s');
返回true;
}}
style={style.button}
>
向下
{
this.state.socketIo.emit('buttonDown','j');
返回true;
}}
onTouchEnd={(e)=>{
this.state.socketIo.emit('buttonUp','j');
返回true;
}}
style={style.button}
>
射击
{
this.state.socketIo.emit('buttonDown','k');
返回true;
}}
onTouchEnd={(e)=>{
this.state.socketIo.emit('buttonUp','k');
返回true;
}}
style={style.button}
>
跳跃
);
}
}

提前谢谢

您好,为什么不使用TouchableOpacity、TouchableHighlight甚至一个按钮?@FreakyCoder因为我想捕捉触摸开始和触摸结束事件我发现了这个线程,但它在android上不起作用,我也会研究它,如果我找到什么我会通知你的you@FreakyCoder你知道怎么做吗?你好,为什么你不使用TouchableOpacity、TouchableHighlight甚至一个按钮?@FreakyCoder因为我想捕捉触摸开始和触摸结束事件我发现了这个线程,但它在android上不起作用,我也会研究它,如果我找到什么我会通知你的you@FreakyCoder你知道怎么做吗?