private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher eventDispatcher) { // This means the gesture has already ended, via some other CANCEL or UP event. This is not // expected to happen very often as it would mean some child View has decided to intercept the // touch stream and start a native gesture only upon receiving the UP/CANCEL event. if (mTargetTag == -1) { FLog.w( ReactConstants.TAG, "Can't cancel already finished gesture. Is a child View trying to start a gesture from " + "an UP/CANCEL event?"); return; } Assertions.assertCondition( !mChildIsHandlingNativeGesture, "Expected to not have already sent a cancel for this gesture"); Assertions.assertNotNull(eventDispatcher).dispatchEvent( TouchEvent.obtain( mTargetTag, TouchEventType.CANCEL, androidEvent, mGestureStartTime, mTargetCoordinates[0], mTargetCoordinates[1], mTouchEventCoalescingKeyHelper)); }
private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher eventDispatcher) { // This means the gesture has already ended, via some other CANCEL or UP event. This is not // expected to happen very often as it would mean some child View has decided to intercept the // touch stream and start a native gesture only upon receiving the UP/CANCEL event. if (mTargetTag == -1) { FLog.w( ReactConstants.TAG, "Can't cancel already finished gesture. Is a child View trying to start a gesture from " + "an UP/CANCEL event?"); return; } Assertions.assertCondition( !mChildIsHandlingNativeGesture, "Expected to not have already sent a cancel for this gesture"); Assertions.assertNotNull(eventDispatcher).dispatchEvent( TouchEvent.obtain( mTargetTag, SystemClock.nanoTime(), TouchEventType.CANCEL, androidEvent, mTargetCoordinates[0], mTargetCoordinates[1])); }
private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher eventDispatcher) { // This means the gesture has already ended, via some other CANCEL or UP event. This is not // expected to happen very often as it would mean some child View has decided to intercept the // touch stream and start a native gesture only upon receiving the UP/CANCEL event. if (mTargetTag == -1) { FLog.w( ReactConstants.TAG, "Can't cancel already finished gesture. Is a child View trying to start a gesture from " + "an UP/CANCEL event?"); return; } Assertions.assertCondition( !mChildIsHandlingNativeGesture, "Expected to not have already sent a cancel for this gesture"); Assertions.assertNotNull(eventDispatcher).dispatchEvent( TouchEvent.obtain( mTargetTag, TouchEventType.CANCEL, androidEvent, mTargetCoordinates[0], mTargetCoordinates[1], mTouchEventCoalescingKeyHelper)); }
private void dispatchCancelEvent(MotionEvent androidEvent) { // This means the gesture has already ended, via some other CANCEL or UP event. This is not // expected to happen very often as it would mean some child View has decided to intercept the // touch stream and start a native gesture only upon receiving the UP/CANCEL event. if (mTargetTag == -1) { FLog.w( ReactConstants.TAG, "Can't cancel already finished gesture. Is a child View trying to start a gesture from " + "an UP/CANCEL event?"); return; } EventDispatcher eventDispatcher = mReactInstanceManager.getCurrentReactContext() .getNativeModule(UIManagerModule.class) .getEventDispatcher(); Assertions.assertCondition( !mChildIsHandlingNativeGesture, "Expected to not have already sent a cancel for this gesture"); Assertions.assertNotNull(eventDispatcher).dispatchEvent( TouchEvent.obtain( mTargetTag, SystemClock.nanoTime(), TouchEventType.CANCEL, androidEvent, mTargetCoordinates[0], mTargetCoordinates[1])); }
private void dispatch(MotionEvent ev, TouchEventType type) { ev.offsetLocation(getAbsoluteLeft(this), getAbsoluteTop(this)); mEventDispatcher.dispatchEvent( TouchEvent.obtain( mTargetTag, type, ev, mGestureStartTime, ev.getX(), ev.getY(), mTouchEventCoalescingKeyHelper)); }
private void handleTouchEvent(MotionEvent ev) { int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_DOWN) { mGestureStartTime = ev.getEventTime(); dispatch(ev, TouchEventType.START); } else if (mTargetTag == -1) { // All the subsequent action types are expected to be called after ACTION_DOWN thus target // is supposed to be set for them. Log.e( "error", "Unexpected state: received touch event but didn't get starting ACTION_DOWN for this " + "gesture before"); } else if (action == MotionEvent.ACTION_UP) { // End of the gesture. We reset target tag to -1 and expect no further event associated with // this gesture. dispatch(ev, TouchEventType.END); mTargetTag = -1; mGestureStartTime = TouchEvent.UNSET; } else if (action == MotionEvent.ACTION_MOVE) { // Update pointer position for current gesture dispatch(ev, TouchEventType.MOVE); } else if (action == MotionEvent.ACTION_POINTER_DOWN) { // New pointer goes down, this can only happen after ACTION_DOWN is sent for the first pointer dispatch(ev, TouchEventType.START); } else if (action == MotionEvent.ACTION_POINTER_UP) { // Exactly onw of the pointers goes up dispatch(ev, TouchEventType.END); } else if (action == MotionEvent.ACTION_CANCEL) { dispatchCancelEvent(ev); mTargetTag = -1; mGestureStartTime = TouchEvent.UNSET; } else { Log.w( "IGNORE", "Warning : touch event was ignored. Action=" + action + " Target=" + mTargetTag); } }