工具類:
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;
使用方法:
<MyButton
onPress={() => {
NoDoublePress.onPress(() => {
this.onPressLogin();
});
}}
>
<Text> 登 錄 </Text>
</MyButton>