react-native 防止重复点击

工具类:

NoDoublePress.js

var NoDoublePress = {
    lastPressTime: 1,
    onPress(callback){
        let curTime = new Date().getTime();
        if (curTime - this.lastPressTime > 1000) {
            this.lastPressTime = curTime;
            callback();
        }
    },
};
module.exports = NoDoublePress;

使用方法:

                         {
                                NoDoublePress.onPress(() => {
                                    this.onPressLogin();
                                });
                            }}
                        >
                             登 录 
                        

你可能感兴趣的:(react-native 防止重复点击)