From ad747b05f1834b1d0fa017e6bc91b2e681efb191 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Thu, 7 Nov 2019 15:20:49 -0500 Subject: [PATCH] add press up handler --- core/src/utils/gesture/recognizers/press.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/utils/gesture/recognizers/press.ts b/core/src/utils/gesture/recognizers/press.ts index e9f5b3933b..4276373009 100644 --- a/core/src/utils/gesture/recognizers/press.ts +++ b/core/src/utils/gesture/recognizers/press.ts @@ -4,7 +4,8 @@ export interface PressRecognizerOptions { el: HTMLElement; time: number; threshold: number; - onPressHandler: () => void; + onPressHandler?: () => void; + onPressUpHandler?: () => void; } export const createPressRecognizer = (opts: PressRecognizerOptions) => { @@ -15,7 +16,10 @@ export const createPressRecognizer = (opts: PressRecognizerOptions) => { clearGestureTimeout(); timeout = setTimeout(() => { - opts.onPressHandler(); + if (opts.onPressHandler) { + opts.onPressHandler(); + } + clearGestureTimeout(); }, opts.time || 500); }; @@ -28,6 +32,14 @@ export const createPressRecognizer = (opts: PressRecognizerOptions) => { clearGestureTimeout(); }; + const onEnd = () => { + if (opts.onPressUpHandler) { + opts.onPressUpHandler(); + } + + clearGestureTimeout(); + }; + const clearGestureTimeout = () => { if (timeout) { clearTimeout(timeout); @@ -41,6 +53,6 @@ export const createPressRecognizer = (opts: PressRecognizerOptions) => { threshold: 0, onStart, onMove, - onEnd: () => clearGestureTimeout() + onEnd }); };