Add onChildEndedNativeGesture to JSTouchDispatcher and ReactRootView to handle child gesture finishes event

Summary:
Changelog:
[Android][Added] Adding new API `onChildEndedNativeGesture` to the RootView interface to let its implementations notify the JS side that a child gesture is ended.

Reviewed By: javache

Differential Revision: D32228745

fbshipit-source-id: ad1f26546dd60f9c5a569b0bc3ad5020a01b90cc
This commit is contained in:
Xin Chen
2021-11-09 12:51:21 -08:00
committed by Facebook GitHub Bot
parent e973b3afc2
commit 9b33c31ee0
5 changed files with 58 additions and 8 deletions
@@ -185,14 +185,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
@Override
public void onChildStartedNativeGesture(MotionEvent ev) {
if (mReactInstanceManager == null
|| !mIsAttachedToInstance
|| mReactInstanceManager.getCurrentReactContext() == null) {
FLog.w(TAG, "Unable to dispatch touch to JS as the catalyst instance has not been attached");
return;
}
if (mJSTouchDispatcher == null) {
FLog.w(TAG, "Unable to dispatch touch to JS before the dispatcher is available");
if (!isDispatcherReady()) {
return;
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
@@ -209,6 +202,35 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
onChildStartedNativeGesture(ev);
}
@Override
public void onChildEndedNativeGesture(View childView, MotionEvent ev) {
if (!isDispatcherReady()) {
return;
}
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
UIManager uiManager = UIManagerHelper.getUIManager(reactContext, getUIManagerType());
if (uiManager != null) {
EventDispatcher eventDispatcher = uiManager.getEventDispatcher();
mJSTouchDispatcher.onChildEndedNativeGesture(ev, eventDispatcher);
}
}
private boolean isDispatcherReady() {
if (mReactInstanceManager == null
|| !mIsAttachedToInstance
|| mReactInstanceManager.getCurrentReactContext() == null) {
FLog.w(TAG, "Unable to dispatch touch to JS as the catalyst instance has not been attached");
return false;
}
if (mJSTouchDispatcher == null) {
FLog.w(TAG, "Unable to dispatch touch to JS before the dispatcher is available");
return false;
}
return true;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
dispatchJSTouchEvent(ev);