UNPKG

react-native-gesture-handler

Version:

Declarative API exposing native platform touch and gesture system to React Native

43 lines (35 loc) 1.2 kB
import { tagMessage } from '../utils'; import type IGestureHandler from '../web/handlers/IGestureHandler'; import GestureHandlerOrchestrator from '../web/tools/GestureHandlerOrchestrator'; import NodeManager from '../web/tools/NodeManager'; import type { GestureStateManagerType } from './gestureStateManager'; function ensureHandlerAttached(handler: IGestureHandler) { if (!handler.attached) { throw new Error( tagMessage( 'Manually handled gesture had not been assigned to any detector' ) ); } } export const GestureStateManager: GestureStateManagerType = { activate(handlerTag: number): void { 'worklet'; const handler = NodeManager.getHandler(handlerTag); ensureHandlerAttached(handler); GestureHandlerOrchestrator.instance.recordHandlerIfNotPresent(handler); handler.activate(true); }, fail(handlerTag: number): void { 'worklet'; const handler = NodeManager.getHandler(handlerTag); ensureHandlerAttached(handler); handler.fail(); }, deactivate(handlerTag: number): void { 'worklet'; const handler = NodeManager.getHandler(handlerTag); ensureHandlerAttached(handler); handler.end(); }, };