簡體   English   中英

多個手勢響應者同時

[英]Multiple gesture responders at the same time

我需要一些可以同時按下的按鈕,但是目前如果按下一個按鈕,它“聲稱”響應性,其他按鈕不能再被按下了。 我該怎么做呢?

得到它了。 您必須使用ReactNativeEventEmitter直接監聽觸摸事件並完全繞過手勢響應程序。 下面是一個裝飾器類,只要收到這些觸摸事件, onTouchEnd onTouchMove在包裝類中調用onTouchStartonTouchEndonTouchMove

'use strict';

import React, {Component} from 'react-native';
import ReactNativeEventEmitter from 'ReactNativeEventEmitter';
import NodeHandle from 'NodeHandle';

export const multitouchable = BaseComponent => {
    return class extends Component {

        constructor(props, context) {
            super(props, context);

            this.comp = null;
            this.compId = null;
        }

        componentDidMount() {
            if(this.comp && this.compId){
                this.comp.onTouchStart && ReactNativeEventEmitter.putListener(this.compId, 'onTouchStart', e => this.comp.onTouchStart(e));
                this.comp.onTouchEnd && ReactNativeEventEmitter.putListener(this.compId, 'onTouchEnd', e => this.comp.onTouchEnd(e));
                this.comp.onTouchMove && ReactNativeEventEmitter.putListener(this.compId, 'onTouchMove', e => this.comp.onTouchMove(e));
            }
        }

        componentWillUnmount() { 
            if(this.comp && this.compId){
                this.comp.onTouchStart && ReactNativeEventEmitter.deleteListener(this.compId, 'onTouchStart');
                this.comp.onTouchEnd && ReactNativeEventEmitter.deleteListener(this.compId, 'onTouchEnd');
                this.comp.onTouchMove && ReactNativeEventEmitter.deleteListener(this.compId, 'onTouchMove');
            }
        }

        render() {
            return (
                <BaseComponent {...this.props} {...this.state}
                    ref={c => {
                        this.comp = c;
                        const handle = React.findNodeHandle(c);
                        if(handle)
                            this.compId = NodeHandle.getRootNodeID(handle);
                    }}
                />
            );
        }
    };
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM