-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (44 loc) · 1.44 KB
/
index.ts
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
import { DraggerBase, NDraggerBase } from '../DraggerBase';
import { NDraggerDirection } from './types';
export type { NDraggerDirection };
/**
* `Dragger` that detects swipe direction
*/
export class DraggerDirection<
StaticProps extends
NDraggerDirection.IStaticProps = NDraggerDirection.IStaticProps,
ChangeableProps extends
NDraggerDirection.IChangeableProps = NDraggerDirection.IChangeableProps,
CallbacksTypes extends
NDraggerDirection.ICallbacksTypes = NDraggerDirection.ICallbacksTypes,
> extends DraggerBase<StaticProps, ChangeableProps, CallbacksTypes> {
protected _getDefaultProps() {
return {
...super._getDefaultProps(),
minLength: 75,
};
}
/** Event on drag end */
protected _handleEnd(event: NDraggerBase.TEvent) {
const { x, y } = this._getEventCoords(event);
const { startCoords } = this;
const min = Math.abs(this.props.minLength);
// up
if (startCoords.y > y && Math.abs(y - startCoords.y) >= min) {
this.callbacks.tbt('up', undefined);
}
// down
if (startCoords.y < y && Math.abs(y - startCoords.y) >= min) {
this.callbacks.tbt('down', undefined);
}
// left
if (startCoords.x > x && Math.abs(x - startCoords.x) >= min) {
this.callbacks.tbt('left', undefined);
}
// right
if (startCoords.x < x && Math.abs(x - startCoords.x) >= min) {
this.callbacks.tbt('right', undefined);
}
super._handleEnd(event);
}
}