You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
35 KiB

{"ast":null,"code":"import _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nfunction _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n return obj;\n}\nimport { State } from \"../../State\";\nimport { PointerType } from \"../interfaces\";\nimport PointerTracker from \"./PointerTracker\";\nimport { isPointerInBounds } from \"../utils\";\nvar GestureHandlerOrchestrator = function () {\n function GestureHandlerOrchestrator() {\n _classCallCheck(this, GestureHandlerOrchestrator);\n _defineProperty(this, \"gestureHandlers\", []);\n _defineProperty(this, \"awaitingHandlers\", []);\n _defineProperty(this, \"handlersToCancel\", []);\n _defineProperty(this, \"handlingChangeSemaphore\", 0);\n _defineProperty(this, \"activationIndex\", 0);\n }\n _createClass(GestureHandlerOrchestrator, [{\n key: \"scheduleFinishedHandlersCleanup\",\n value: function scheduleFinishedHandlersCleanup() {\n if (this.handlingChangeSemaphore === 0) {\n this.cleanupFinishedHandlers();\n }\n }\n }, {\n key: \"cleanHandler\",\n value: function cleanHandler(handler) {\n handler.reset();\n handler.setActive(false);\n handler.setAwaiting(false);\n handler.setActivationIndex(Number.MAX_VALUE);\n }\n }, {\n key: \"removeHandlerFromOrchestrator\",\n value: function removeHandlerFromOrchestrator(handler) {\n this.gestureHandlers.splice(this.gestureHandlers.indexOf(handler), 1);\n this.awaitingHandlers.splice(this.awaitingHandlers.indexOf(handler), 1);\n this.handlersToCancel.splice(this.handlersToCancel.indexOf(handler), 1);\n }\n }, {\n key: \"cleanupFinishedHandlers\",\n value: function cleanupFinishedHandlers() {\n for (var i = this.gestureHandlers.length - 1; i >= 0; --i) {\n var handler = this.gestureHandlers[i];\n if (!handler) {\n continue;\n }\n if (this.isFinished(handler.getState()) && !handler.isAwaiting()) {\n this.gestureHandlers.splice(i, 1);\n this.cleanHandler(handler);\n }\n }\n }\n }, {\n key: \"hasOtherHandlerToWaitFor\",\n value: function hasOtherHandlerToWaitFor(handler) {\n var _this = this;\n var hasToWait = false;\n this.gestureHandlers.forEach(function (otherHandler) {\n if (otherHandler && !_this.isFinished(otherHandler.getState()) && _this.shouldHandlerWaitForOther(handler, otherHandler)) {\n hasToWait = true;\n return;\n }\n });\n return hasToWait;\n }\n }, {\n key: \"tryActivate\",\n value: function tryActivate(handler) {\n if (this.hasOtherHandlerToWaitFor(handler)) {\n this.addAwaitingHandler(handler);\n } else if (handler.getState() !== State.CANCELLED && handler.getState() !== State.FAILED) {\n if (this.shouldActivate(handler)) {\n this.makeActive(handler);\n } else {\n switch (handler.getState()) {\n case State.ACTIVE:\n handler.fail();\n break;\n case State.BEGAN:\n handler.cancel();\n }\n }\n }\n }\n }, {\n key: \"shouldActivate\",\n value: function shouldActivate(handler) {\n for (var otherHandler of this.gestureHandlers) {\n if (this.shouldHandlerBeCancelledBy(handler, otherHandler)) {\n return false;\n }\n }\n return true;\n }\n }, {\n key: \"cleanupAwaitingHandlers\",\n value: function cleanupAwaitingHandlers(handler) {\n for (var i = 0; i < this.awaitingHandlers.length; ++i) {\n if (!this.awaitingHandlers[i].isAwaiting() && this.shouldHandlerWaitForOther(this.awaitingHandlers[i], handler)) {\n this.cleanHandler(this.awaitingHandlers[i]);\n this.awaitingHandlers.splice(i, 1);\n }\n }\n }\n }, {\n key: \"onHandlerStateChange\",\n value: function onHandlerStateChange(handler, newState, oldState, sendIfDisabled) {\n var _this2 = this;\n if (!handler.isEnabled() && !sendIfDisabled) {\n return;\n }\n this.handlingChangeSemaphore += 1;\n if (this.isFinished(newState)) {\n this.awaitingHandlers.forEach(function (otherHandler) {\n if (_this2.shouldHandlerWaitForOther(otherHandler, handler)) {\n if (newState === State.END) {\n otherHandler === null || otherHandler === void 0 ? void 0 : otherHandler.cancel();\n if (otherHandler.getState() === State.END) {\n otherHandler.sendEvent(State.CANCELLED, State.BEGAN);\n }\n otherHandler === null || otherHandler === void 0 ? void 0 : otherHandler.setAwaiting(false);\n } else {\n _this2.tryActivate(otherHandler);\n }\n }\n });\n }\n if (newState === State.ACTIVE) {\n this.tryActivate(handler);\n } else if (oldState === State.ACTIVE || oldState === State.END) {\n if (handler.isActive()) {\n handler.sendEvent(newState, oldState);\n } else if (oldState === State.ACTIVE && (newState === State.CANCELLED || newState === State.FAILED)) {\n handler.sendEvent(newState, State.BEGAN);\n }\n } else if (oldState !== State.UNDETERMINED || newState !== State.CANCELLED) {\n handler.sendEvent(newState, oldState);\n }\n this.handlingChangeSemaphore -= 1;\n this.scheduleFinishedHandlersCleanup();\n if (this.awaitingHandlers.indexOf(handler) < 0) {\n this.cleanupAwaitingHandlers(handler);\n }\n }\n }, {\n key: \"makeActive\",\n value: function makeActive(handler) {\n var _this3 = this;\n var currentState = handler.getState();\n handler.setActive(true);\n handler.setShouldResetProgress(true);\n handler.setActivationIndex(this.activationIndex++);\n this.gestureHandlers.forEach(function (otherHandler) {\n if (_this3.shouldHandlerBeCancelledBy(otherHandler, handler)) {\n _this3.handlersToCancel.push(otherHandler);\n }\n });\n for (var i = this.handlersToCancel.length - 1; i >= 0; --i) {\n var _this$handlersToCance;\n (_this$handlersToCance = this.handlersToCancel[i]) === null || _this$handlersToCance === void 0 ? void 0 : _this$handlersToCance.cancel();\n }\n this.awaitingHandlers.forEach(function (otherHandler) {\n if (_this3.shouldHandlerBeCancelledBy(otherHandler, handler)) {\n otherHandler === null || otherHandler === void 0 ? void 0 : otherHandler.cancel();\n otherHandler === null || otherHandler === void 0 ? void 0 : otherHandler.setAwaiting(true);\n }\n });\n handler.sendEvent(State.ACTIVE, State.BEGAN);\n if (currentState !== State.ACTIVE) {\n handler.sendEvent(State.END, State.ACTIVE);\n if (currentState !== State.END) {\n handler.sendEvent(State.UNDETERMINED, State.END);\n }\n }\n if (handler.isAwaiting()) {\n handler.setAwaiting(false);\n for (var _i = 0; _i < this.awaitingHandlers.length; ++_i) {\n if (this.awaitingHandlers[_i] === handler) {\n this.awaitingHandlers.splice(_i, 1);\n }\n }\n }\n this.handlersToCancel = [];\n }\n }, {\n key: \"addAwaitingHandler\",\n value: function addAwaitingHandler(handler) {\n var alreadyExists = false;\n this.awaitingHandlers.forEach(function (otherHandler) {\n if (otherHandler === handler) {\n alreadyExists = true;\n return;\n }\n });\n if (alreadyExists) {\n return;\n }\n this.awaitingHandlers.push(handler);\n handler.setAwaiting(true);\n handler.setActivationIndex(this.activationIndex++);\n }\n }, {\n key: \"recordHandlerIfNotPresent\",\n value: function recordHandlerIfNotPresent(handler) {\n var alreadyExists = false;\n this.gestureHandlers.forEach(function (otherHandler) {\n if (otherHandler === handler) {\n alreadyExists = true;\n return;\n }\n });\n if (alreadyExists) {\n return;\n }\n this.gestureHandlers.push(handler);\n handler.setActive(false);\n handler.setAwaiting(false);\n handler.setActivationIndex(Number.MAX_SAFE_INTEGER);\n }\n }, {\n key: \"shouldHandlerWaitForOther\",\n value: function shouldHandlerWaitForOther(handler, otherHandler) {\n return handler !== otherHandler && (handler.shouldWaitForHandlerFailure(otherHandler) || otherHandler.shouldRequireToWaitForFailure(handler));\n }\n }, {\n key: \"canRunSimultaneously\",\n value: function canRunSimultaneously(gh1, gh2) {\n return gh1 === gh2 || gh1.shouldRecognizeSimultaneously(gh2) || gh2.shouldRecognizeSimultaneously(gh1);\n }\n }, {\n key: \"shouldHandlerBeCancelledBy\",\n value: function shouldHandlerBeCancelledBy(handler, otherHandler) {\n if (this.canRunSimultaneously(handler, otherHandler)) {\n return false;\n }\n if (handler !== otherHandler && (handler.isAwaiting() || handler.getState() === State.ACTIVE)) {\n return handler.shouldBeCancelledByOther(otherHandler);\n }\n var handlerPointers = handler.getTrackedPointersID();\n var otherPointers = otherHandler.getTrackedPointersID();\n if (!PointerTracker.shareCommonPointers(handlerPointers, otherPointers) && handler.getView() !== otherHandler.getView()) {\n return this.checkOverlap(handler, otherHandler);\n }\n return true;\n }\n }, {\n key: \"checkOverlap\",\n value: function checkOverlap(handler, otherHandler) {\n var handlerPointers = handler.getTrackedPointersID();\n var otherPointers = otherHandler.getTrackedPointersID();\n var overlap = false;\n handlerPointers.forEach(function (pointer) {\n var handlerX = handler.getTracker().getLastX(pointer);\n var handlerY = handler.getTracker().getLastY(pointer);\n if (isPointerInBounds(handler.getView(), {\n x: handlerX,\n y: handlerY\n }) && isPointerInBounds(otherHandler.getView(), {\n x: handlerX,\n y: handlerY\n })) {\n overlap = true;\n }\n });\n otherPointers.forEach(function (pointer) {\n var otherX = otherHandler.getTracker().getLastX(pointer);\n var otherY = otherHandler.getTracker().getLastY(pointer);\n if (isPointerInBounds(handler.getView(), {\n x: otherX,\n y: otherY\n }) && isPointerInBounds(otherHandler.getView(), {\n x: otherX,\n y: otherY\n })) {\n overlap = true;\n }\n });\n return overlap;\n }\n }, {\n key: \"isFinished\",\n value: function isFinished(state) {\n return state === State.END || state === State.FAILED || state === State.CANCELLED;\n }\n }, {\n key: \"cancelMouseAndPenGestures\",\n value: function cancelMouseAndPenGestures(currentHandler) {\n this.gestureHandlers.forEach(function (handler) {\n if (handler.getPointerType() !== PointerType.MOUSE && handler.getPointerType() !== PointerType.PEN) {\n return;\n }\n if (handler !== currentHandler) {\n handler.cancel();\n } else {\n handler.getTracker().resetTracker();\n }\n });\n }\n }], [{\n key: \"getInstance\",\n value: function getInstance() {\n if (!GestureHandlerOrchestrator.instance) {\n GestureHandlerOrchestrator.instance = new GestureHandlerOrchestrator();\n }\n return GestureHandlerOrchestrator.instance;\n }\n }]);\n return GestureHandlerOrchestrator;\n}();\nexport { GestureHandlerOrchestrator as default };\n_defineProperty(GestureHandlerOrchestrator, \"instance\", void 0);","map":{"version":3,"mappings":";;;;;;;;;;;;;;;AAAA,SAASA,KAAT;AACA,SAASC,WAAT;AAGA,OAAOC,cAAP;AACA,SAASC,iBAAT;AAAA,IAEqBC,0BAAN;EAYLC,sCAAc;IAAA;IAAAC,yCATsB,EAStB;IAA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AAL,CAAqBY,OAArB,CAA8BpB,iBAAD,EAA6B;QACxD,IACEA,OAAO,CAAC8E,cAAR,OAA6BxF,WAAW,CAACyF,KAAzC,IACA/E,OAAO,CAAC8E,cAAR,OAA6BxF,WAAW,CAAC0F,GAF3C,EAGE;UACA;QACD;QAED,IAAIhF,OAAO,KAAK6E,cAAhB,EAAgC;UAC9B7E,OAAO,CAACgC,MAAR;QACD,CAFD,MAEO;UAQLhC,OAAO,CAACmE,UAAR,GAAqBc,YAArB;QACD;MACF,CApBD;IAqBD;EAAA;IAAA;IAAA,OAEwB,uBAA+B;MACtD,IAAI,CAACxF,0BAA0B,CAACyF,QAAhC,EAA0C;QACxCzF,0BAA0B,CAACyF,QAA3B,GAAsC,IAAIzF,0BAAJ,EAAtC;MACD;MAED,OAAOA,0BAA0B,CAACyF,QAAlC;IACD;EAAA;EAAA;AAAA;AAAA,SApYkBzF,0BAAN;gBAAMA,0B","names":["State","PointerType","PointerTracker","isPointerInBounds","GestureHandlerOrchestrator","constructor","_defineProperty","scheduleFinishedHandlersCleanup","handlingChangeSemaphore","cleanupFinishedHandlers","cleanHandler","handler","reset","setActive","setAwaiting","setActivationIndex","Number","MAX_VALUE","removeHandlerFromOrchestrator","gestureHandlers","splice","indexOf","awaitingHandlers","handlersToCancel","i","length","isFinished","getState","isAwaiting","hasOtherHandlerToWaitFor","hasToWait","forEach","otherHandler","shouldHandlerWaitForOther","tryActivate","addAwaitingHandler","CANCELLED","FAILED","shouldActivate","makeActive","ACTIVE","fail","BEGAN","cancel","shouldHandlerBeCancelledBy","cleanupAwaitingHandlers","onHandlerStateChange","newState","oldState","sendIfDisabled","isEnabled","END","sendEvent","isActive","UNDETERMINED","currentState","setShouldResetProgress","activationIndex","push","alreadyExists","recordHandlerIfNotPresent","MAX_SAFE_INTEGER","shouldWaitForHandlerFailure","shouldRequireToWaitForFailure","canRunSimultaneously","gh1","gh2","shouldRecognizeSimultaneously","shouldBeCancelledByOther","handlerPointers","getTrackedPointersID","otherPointers","shareCommonPointers","getView","checkOverlap","overlap","pointer","handlerX","getTracker","getLastX","handlerY","getLastY","x","y","otherX","otherY","state","cancelMouseAndPenGestures","currentHandler","getPointerType","MOUSE","PEN","resetTracker","instance"],"sources":["/Users/mathildejean/Documents/BUT/LaSuperMeteo/LaSuperMeteo/iut-expo-starter/node_modules/react-native-gesture-handler/lib/module/web/tools/GestureHandlerOrchestrator.ts"],"sourcesContent":["import { State } from '../../State';\nimport { PointerType } from '../interfaces';\n\nimport GestureHandler from '../handlers/GestureHandler';\nimport PointerTracker from './PointerTracker';\nimport { isPointerInBounds } from '../utils';\n\nexport default class GestureHandlerOrchestrator {\n private static instance: GestureHandlerOrchestrator;\n\n private gestureHandlers: GestureHandler[] = [];\n private awaitingHandlers: GestureHandler[] = [];\n private handlersToCancel: GestureHandler[] = [];\n\n private handlingChangeSemaphore = 0;\n private activationIndex = 0;\n\n // Private beacuse of Singleton\n // eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function\n private constructor() {}\n\n private scheduleFinishedHandlersCleanup(): void {\n if (this.handlingChangeSemaphore === 0) {\n this.cleanupFinishedHandlers();\n }\n }\n\n private cleanHandler(handler: GestureHandler): void {\n handler.reset();\n handler.setActive(false);\n handler.setAwaiting(false);\n handler.setActivationIndex(Number.MAX_VALUE);\n }\n\n public removeHandlerFromOrchestrator(handler: GestureHandler): void {\n this.gestureHandlers.splice(this.gestureHandlers.indexOf(handler), 1);\n this.awaitingHandlers.splice(this.awaitingHandlers.indexOf(handler), 1);\n this.handlersToCancel.splice(this.handlersToCancel.indexOf(handler), 1);\n }\n\n private cleanupFinishedHandlers(): void {\n for (let i = this.gestureHandlers.length - 1; i >= 0; --i) {\n const handler = this.gestureHandlers[i];\n\n if (!handler) {\n continue;\n }\n if (this.isFinished(handler.getState()) && !handler.isAwaiting()) {\n this.gestureHandlers.splice(i, 1);\n\n this.cleanHandler(handler);\n }\n }\n }\n\n private hasOtherHandlerToWaitFor(handler: GestureHandler): boolean {\n let hasToWait = false;\n this.gestureHandlers.forEach((otherHandler) => {\n if (\n otherHandler &&\n !this.isFinished(otherHandler.getState()) &&\n this.shouldHandlerWaitForOther(handler, otherHandler)\n ) {\n hasToWait = true;\n return;\n }\n });\n\n return hasToWait;\n }\n\n private tryActivate(handler: GestureHandler): void {\n if (this.hasOtherHandlerToWaitFor(handler)) {\n this.addAwaitingHandler(handler);\n } else if (\n handler.getState() !== State.CANCELLED &&\n handler.getState() !== State.FAILED\n ) {\n if (this.shouldActivate(handler)) {\n this.makeActive(handler);\n } else {\n switch (handler.getState()) {\n case State.ACTIVE:\n handler.fail();\n break;\n case State.BEGAN:\n handler.cancel();\n }\n }\n }\n }\n\n private shouldActivate(handler: GestureHandler): boolean {\n for (const otherHandler of this.gestureHandlers) {\n if (this.shouldHandlerBeCancelledBy(handler, otherHandler)) {\n return false;\n }\n }\n\n return true;\n }\n\n private cleanupAwaitingHandlers(handler: GestureHandler): void {\n for (let i = 0; i < this.awaitingHandlers.length; ++i) {\n if (\n !this.awaitingHandlers[i].isAwaiting() &&\n this.shouldHandlerWaitForOther(this.awaitingHandlers[i], handler)\n ) {\n this.cleanHandler(this.awaitingHandlers[i]);\n this.awaitingHandlers.splice(i, 1);\n }\n }\n }\n\n public onHandlerStateChange(\n handler: GestureHandler,\n newState: State,\n oldState: State,\n sendIfDisabled?: boolean\n ): void {\n if (!handler.isEnabled() && !sendIfDisabled) {\n return;\n }\n\n this.handlingChangeSemaphore += 1;\n\n if (this.isFinished(newState)) {\n this.awaitingHandlers.forEach((otherHandler) => {\n if (this.shouldHandlerWaitForOther(otherHandler, handler)) {\n if (newState === State.END) {\n otherHandler?.cancel();\n if (otherHandler.getState() === State.END) {\n // Handle edge case, where discrete gestures end immediately after activation thus\n // their state is set to END and when the gesture they are waiting for activates they\n // should be cancelled, however `cancel` was never sent as gestures were already in the END state.\n // Send synthetic BEGAN -> CANCELLED to properly handle JS logic\n otherHandler.sendEvent(State.CANCELLED, State.BEGAN);\n }\n otherHandler?.setAwaiting(false);\n } else {\n this.tryActivate(otherHandler);\n }\n }\n });\n }\n\n if (newState === State.ACTIVE) {\n this.tryActivate(handler);\n } else if (oldState === State.ACTIVE || oldState === State.END) {\n if (handler.isActive()) {\n handler.sendEvent(newState, oldState);\n } else if (\n oldState === State.ACTIVE &&\n (newState === State.CANCELLED || newState === State.FAILED)\n ) {\n handler.sendEvent(newState, State.BEGAN);\n }\n } else if (\n oldState !== State.UNDETERMINED ||\n newState !== State.CANCELLED\n ) {\n handler.sendEvent(newState, oldState);\n }\n\n this.handlingChangeSemaphore -= 1;\n\n this.scheduleFinishedHandlersCleanup();\n\n if (this.awaitingHandlers.indexOf(handler) < 0) {\n this.cleanupAwaitingHandlers(handler);\n }\n }\n\n private makeActive(handler: GestureHandler): void {\n const currentState = handler.getState();\n\n handler.setActive(true);\n handler.setShouldResetProgress(true);\n handler.setActivationIndex(this.activationIndex++);\n\n this.gestureHandlers.forEach((otherHandler) => {\n // Order of arguments is correct - we check whether current handler should cancel existing handlers\n\n if (this.shouldHandlerBeCancelledBy(otherHandler, handler)) {\n this.handlersToCancel.push(otherHandler);\n }\n });\n\n for (let i = this.handlersToCancel.length - 1; i >= 0; --i) {\n this.handlersToCancel[i]?.cancel();\n }\n this.awaitingHandlers.forEach((otherHandler) => {\n if (this.shouldHandlerBeCancelledBy(otherHandler, handler)) {\n otherHandler?.cancel();\n otherHandler?.setAwaiting(true);\n }\n });\n\n handler.sendEvent(State.ACTIVE, State.BEGAN);\n\n if (currentState !== State.ACTIVE) {\n handler.sendEvent(State.END, State.ACTIVE);\n if (currentState !== State.END) {\n handler.sendEvent(State.UNDETERMINED, State.END);\n }\n }\n\n if (handler.isAwaiting()) {\n handler.setAwaiting(false);\n for (let i = 0; i < this.awaitingHandlers.length; ++i) {\n if (this.awaitingHandlers[i] === handler) {\n this.awaitingHandlers.splice(i, 1);\n }\n }\n }\n\n this.handlersToCancel = [];\n }\n\n private addAwaitingHandler(handler: GestureHandler): void {\n let alreadyExists = false;\n\n this.awaitingHandlers.forEach((otherHandler) => {\n if (otherHandler === handler) {\n alreadyExists = true;\n return;\n }\n });\n\n if (alreadyExists) {\n return;\n }\n\n this.awaitingHandlers.push(handler);\n\n handler.setAwaiting(true);\n handler.setActivationIndex(this.activationIndex++);\n }\n\n public recordHandlerIfNotPresent(handler: GestureHandler): void {\n let alreadyExists = false;\n\n this.gestureHandlers.forEach((otherHandler) => {\n if (otherHandler === handler) {\n alreadyExists = true;\n return;\n }\n });\n\n if (alreadyExists) {\n return;\n }\n\n this.gestureHandlers.push(handler);\n\n handler.setActive(false);\n handler.setAwaiting(false);\n handler.setActivationIndex(Number.MAX_SAFE_INTEGER);\n }\n\n private shouldHandlerWaitForOther(\n handler: GestureHandler,\n otherHandler: GestureHandler\n ): boolean {\n return (\n handler !== otherHandler &&\n (handler.shouldWaitForHandlerFailure(otherHandler) ||\n otherHandler.shouldRequireToWaitForFailure(handler))\n );\n }\n\n private canRunSimultaneously(\n gh1: GestureHandler,\n gh2: GestureHandler\n ): boolean {\n return (\n gh1 === gh2 ||\n gh1.shouldRecognizeSimultaneously(gh2) ||\n gh2.shouldRecognizeSimultaneously(gh1)\n );\n }\n\n private shouldHandlerBeCancelledBy(\n handler: GestureHandler,\n otherHandler: GestureHandler\n ): boolean {\n if (this.canRunSimultaneously(handler, otherHandler)) {\n return false;\n }\n\n if (\n handler !== otherHandler &&\n (handler.isAwaiting() || handler.getState() === State.ACTIVE)\n ) {\n // For now it always returns false\n return handler.shouldBeCancelledByOther(otherHandler);\n }\n\n const handlerPointers: number[] = handler.getTrackedPointersID();\n const otherPointers: number[] = otherHandler.getTrackedPointersID();\n\n if (\n !PointerTracker.shareCommonPointers(handlerPointers, otherPointers) &&\n handler.getView() !== otherHandler.getView()\n ) {\n return this.checkOverlap(handler, otherHandler);\n }\n\n return true;\n }\n\n private checkOverlap(\n handler: GestureHandler,\n otherHandler: GestureHandler\n ): boolean {\n // If handlers don't have common pointers, default return value is false.\n // However, if at least on pointer overlaps with both handlers, we return true\n // This solves issue in overlapping parents example\n\n // TODO: Find better way to handle that issue, for example by activation order and handler cancelling\n\n const handlerPointers: number[] = handler.getTrackedPointersID();\n const otherPointers: number[] = otherHandler.getTrackedPointersID();\n\n let overlap = false;\n\n handlerPointers.forEach((pointer: number) => {\n const handlerX: number = handler.getTracker().getLastX(pointer);\n const handlerY: number = handler.getTracker().getLastY(pointer);\n\n if (\n isPointerInBounds(handler.getView(), { x: handlerX, y: handlerY }) &&\n isPointerInBounds(otherHandler.getView(), { x: handlerX, y: handlerY })\n ) {\n overlap = true;\n }\n });\n\n otherPointers.forEach((pointer: number) => {\n const otherX: number = otherHandler.getTracker().getLastX(pointer);\n const otherY: number = otherHandler.getTracker().getLastY(pointer);\n\n if (\n isPointerInBounds(handler.getView(), { x: otherX, y: otherY }) &&\n isPointerInBounds(otherHandler.getView(), { x: otherX, y: otherY })\n ) {\n overlap = true;\n }\n });\n\n return overlap;\n }\n\n private isFinished(state: State): boolean {\n return (\n state === State.END || state === State.FAILED || state === State.CANCELLED\n );\n }\n\n // This function is called when handler receives touchdown event\n // If handler is using mouse or pen as a pointer and any handler receives touch event,\n // mouse/pen event dissappears - it doesn't send onPointerCancel nor onPointerUp (and others)\n // This became a problem because handler was left at active state without any signal to end or fail\n // To handle this, when new touch event is received, we loop through active handlers and check which type of\n // pointer they're using. If there are any handler with mouse/pen as a pointer, we cancel them\n public cancelMouseAndPenGestures(currentHandler: GestureHandler): void {\n this.gestureHandlers.forEach((handler: GestureHandler) => {\n if (\n handler.getPointerType() !== PointerType.MOUSE &&\n handler.getPointerType() !== PointerType.PEN\n ) {\n return;\n }\n\n if (handler !== currentHandler) {\n handler.cancel();\n } else {\n // Handler that received touch event should have its pointer tracker reset\n // This allows handler to smoothly change from mouse/pen to touch\n // The drawback is, that when we try to use mouse/pen one more time, it doesn't send onPointerDown at the first time\n // so it is required to click two times to get handler to work\n //\n // However, handler will receive manually created onPointerEnter that is triggered in EventManager in onPointerMove method.\n // There may be possibility to use that fact to make handler respond properly to first mouse click\n handler.getTracker().resetTracker();\n }\n });\n }\n\n public static getInstance(): GestureHandlerOrchestrator {\n if (!GestureHandlerOrchestrator.instance) {\n GestureHandlerOrchestrator.instance = new GestureHandlerOrchestrator();\n }\n\n return GestureHandlerOrchestrator.instance;\n }\n}\n"]},"metadata":{},"sourceType":"module","externalDependencies":[]}