-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (46 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Created by zhouwenjie on 2018/4/12.
*/
import React from 'react';
import {
TouchableWithoutFeedback,
} from 'react-native';
// import debounce from 'lodash.debounce';
class MultiTapComponent extends TouchableWithoutFeedback {
debouncedOnPress = (e,tapCount) => {
this.props.onPress && this.props.onPress(e,tapCount);
}
onPress = debounce(this.debouncedOnPress, 300);
render(){
return (<TouchableWithoutFeedback {...this.props}
onPress={(e)=>this.onPress(e)}>
{this.props.children}
</TouchableWithoutFeedback>);
}
}
function debounce(func, wait, immediate) {
let timeout;
let fireCount=0;
function debounced(event) {
fireCount+=1;
var context = this;
event.persist();
var later = function() {
timeout = null;
if (!immediate) {
let args = Array.from(arguments);
// fireCount = 0;
func.apply(context, args);
}
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait, event, fireCount);
if (callNow) {
// fireCount = 0;
func.apply(context, event, fireCount);
}
}
return debounced;
}
export default MultiTapComponent;