import GestureHandler from './GestureHandler' ; import { TEST_MAX_IF_NOT_NAN } from './utils' ; abstract class DiscreteGestureHandler extends GestureHandler { get isDiscrete ( ) { return true ; } get shouldEnableGestureOnSetup ( ) { return true ; } shouldFailUnderCustomCriteria ( { x , y , deltaX , deltaY } , { maxDeltaX , maxDeltaY , maxDistSq , shouldCancelWhenOutside } ) { if ( shouldCancelWhenOutside ) { if ( ! this . isPointInView ( { x , y } ) ) { return true ; } } return ( TEST_MAX_IF_NOT_NAN ( Math . abs ( deltaX ) , maxDeltaX ) || TEST_MAX_IF_NOT_NAN ( Math . abs ( deltaY ) , maxDeltaY ) || TEST_MAX_IF_NOT_NAN ( Math . abs ( deltaY * deltaY + deltaX * deltaX ) , maxDistSq ) ) ; } transformNativeEvent ( { center : { x , y } } ) { const rect = this . view ! . getBoundingClientRect ( ) ; return { absoluteX : x , absoluteY : y , x : x - rect . left , y : y - rect . top , } ; } isGestureEnabledForEvent ( { minPointers , maxPointers , maxDeltaX , maxDeltaY , maxDistSq , shouldCancelWhenOutside , } , _recognizer , { maxPointers : pointerLength , center , deltaX , deltaY } ) { const validPointerCount = pointerLength >= minPointers && pointerLength <= maxPointers ; if ( this . shouldFailUnderCustomCriteria ( { ... center , deltaX , deltaY } , { maxDeltaX , maxDeltaY , maxDistSq , shouldCancelWhenOutside , } ) || ( ! validPointerCount && this . isGestureRunning ) ) { return { failed : true } ; } return { success : validPointerCount } ; } } export default DiscreteGestureHandler ;