加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 同时有多个手势响应者

发布时间:2020-12-15 20:54:30 所属栏目:百科 来源:网络整理
导读:我需要一些可以同时按下的按钮,但是目前如果你按下一个按钮,它“声称”响应性而其他按钮不能再被按下了.我该怎么做呢? 得到它了.您必须使用ReactNativeEventEmitter直接监听触摸事件并完全绕过手势响应程序.下面是一个装饰器类,只要收到这些触摸事件,它就会
我需要一些可以同时按下的按钮,但是目前如果你按下一个按钮,它“声称”响应性而其他按钮不能再被按下了.我该怎么做呢?
得到它了.您必须使用ReactNativeEventEmitter直接监听触摸事件并完全绕过手势响应程序.下面是一个装饰器类,只要收到这些触摸事件,它就会在包装类中调用onTouchStart,onTouchEnd和onTouchMove.
'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);
                    }}
                />
            );
        }
    };
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读