mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-17 18:54:11 +08:00
add press up handler
This commit is contained in:
@ -4,7 +4,8 @@ export interface PressRecognizerOptions {
|
|||||||
el: HTMLElement;
|
el: HTMLElement;
|
||||||
time: number;
|
time: number;
|
||||||
threshold: number;
|
threshold: number;
|
||||||
onPressHandler: () => void;
|
onPressHandler?: () => void;
|
||||||
|
onPressUpHandler?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createPressRecognizer = (opts: PressRecognizerOptions) => {
|
export const createPressRecognizer = (opts: PressRecognizerOptions) => {
|
||||||
@ -15,7 +16,10 @@ export const createPressRecognizer = (opts: PressRecognizerOptions) => {
|
|||||||
clearGestureTimeout();
|
clearGestureTimeout();
|
||||||
|
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
opts.onPressHandler();
|
if (opts.onPressHandler) {
|
||||||
|
opts.onPressHandler();
|
||||||
|
}
|
||||||
|
|
||||||
clearGestureTimeout();
|
clearGestureTimeout();
|
||||||
}, opts.time || 500);
|
}, opts.time || 500);
|
||||||
};
|
};
|
||||||
@ -28,6 +32,14 @@ export const createPressRecognizer = (opts: PressRecognizerOptions) => {
|
|||||||
clearGestureTimeout();
|
clearGestureTimeout();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onEnd = () => {
|
||||||
|
if (opts.onPressUpHandler) {
|
||||||
|
opts.onPressUpHandler();
|
||||||
|
}
|
||||||
|
|
||||||
|
clearGestureTimeout();
|
||||||
|
};
|
||||||
|
|
||||||
const clearGestureTimeout = () => {
|
const clearGestureTimeout = () => {
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
@ -41,6 +53,6 @@ export const createPressRecognizer = (opts: PressRecognizerOptions) => {
|
|||||||
threshold: 0,
|
threshold: 0,
|
||||||
onStart,
|
onStart,
|
||||||
onMove,
|
onMove,
|
||||||
onEnd: () => clearGestureTimeout()
|
onEnd
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user