@Override public boolean onInterceptTouchEvent(MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch(action) { case (MotionEvent.ACTION_DOWN): initialX = event.getRawX(); return false; case (MotionEvent.ACTION_MOVE) : float deltaX = event.getRawX() - initialX; boolean nowSwiping = Math.abs(deltaX) > MIN_DISABLE_SCROLL; if (!swiping && nowSwiping && listener != null) { listener.onSwipeStart(); } swiping = swiping || nowSwiping; if(swiping) { RootViewUtil.getRootView(this).onChildStartedNativeGesture(event); } return swiping; case (MotionEvent.ACTION_UP) : case (MotionEvent.ACTION_CANCEL) : case (MotionEvent.ACTION_OUTSIDE) : default: return false; } }
/** * Helper method that should be called when a native view starts a native gesture (e.g. a native * ScrollView takes control of a gesture stream and starts scrolling). This will handle * dispatching the appropriate events to JS to make sure the gesture in JS is canceled. * * @param view the View starting the native gesture * @param event the MotionEvent that caused the gesture to be started */ public static void notifyNativeGestureStarted(View view, MotionEvent event) { RootViewUtil.getRootView(view).onChildStartedNativeGesture(event); }