forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLongPressGestureHandler.js
More file actions
50 lines (42 loc) · 1.19 KB
/
LongPressGestureHandler.js
File metadata and controls
50 lines (42 loc) · 1.19 KB
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
import Hammer from 'hammerjs';
import State from '../State';
import PressGestureHandler from './PressGestureHandler';
import { isnan } from './utils';
class LongPressGestureHandler extends PressGestureHandler {
get minDurationMs() {
return isnan(this.config.minDurationMs) ? 251 : this.config.minDurationMs;
}
get maxDist() {
return isnan(this.config.maxDist) ? 9 : this.config.maxDist;
}
updateHasCustomActivationCriteria({ maxDistSq }) {
return !isnan(maxDistSq);
}
getConfig() {
if (!this._hasCustomActivationCriteria) {
// Default config
// If no params have been defined then this config should emulate the native gesture as closely as possible.
return {
shouldCancelWhenOutside: true,
maxDistSq: 10,
};
}
return this.config;
}
getHammerConfig() {
return {
...super.getHammerConfig(),
// threshold: this.maxDist,
time: this.minDurationMs,
};
}
getState(type) {
return {
[Hammer.INPUT_START]: State.ACTIVE,
[Hammer.INPUT_MOVE]: State.ACTIVE,
[Hammer.INPUT_END]: State.END,
[Hammer.INPUT_CANCEL]: State.FAILED,
}[type];
}
}
export default LongPressGestureHandler;