refactor out RootView tag number logic

Reviewed By: achen1

Differential Revision: D5609280

fbshipit-source-id: bc0c9f50b2938f05d5e43f50491ff6f0de154fb6
This commit is contained in:
Aaron Chiu
2017-08-15 10:41:15 -07:00
committed by Facebook Github Bot
parent ab9c788c2c
commit 353cb61400
5 changed files with 50 additions and 33 deletions

View File

@@ -41,8 +41,10 @@ import com.facebook.react.modules.deviceinfo.DeviceInfoModule;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.JSTouchDispatcher;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.ReactRootViewTagGenerator;
import com.facebook.react.uimanager.RootView;
import com.facebook.react.uimanager.SizeMonitoringFrameLayout;
import com.facebook.react.uimanager.TaggedRootView;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.systrace.Systrace;
@@ -50,19 +52,17 @@ import javax.annotation.Nullable;
/**
* Default root view for catalyst apps. Provides the ability to listen for size changes so that a UI
* manager can re-layout its elements.
* It delegates handling touch events for itself and child views and sending those events to JS by
* using JSTouchDispatcher.
* This view is overriding {@link ViewGroup#onInterceptTouchEvent} method in order to be notified
* about the events for all of its children and it's also overriding
* {@link ViewGroup#requestDisallowInterceptTouchEvent} to make sure that
* {@link ViewGroup#onInterceptTouchEvent} will get events even when some child view start
* intercepting it. In case when no child view is interested in handling some particular
* touch event this view's {@link View#onTouchEvent} will still return true in order to be notified
* about all subsequent touch events related to that gesture (in case when JS code want to handle
* that gesture).
* manager can re-layout its elements. It delegates handling touch events for itself and child views
* and sending those events to JS by using JSTouchDispatcher. This view is overriding {@link
* ViewGroup#onInterceptTouchEvent} method in order to be notified about the events for all of its
* children and it's also overriding {@link ViewGroup#requestDisallowInterceptTouchEvent} to make
* sure that {@link ViewGroup#onInterceptTouchEvent} will get events even when some child view start
* intercepting it. In case when no child view is interested in handling some particular touch event
* this view's {@link View#onTouchEvent} will still return true in order to be notified about all
* subsequent touch events related to that gesture (in case when JS code want to handle that
* gesture).
*/
public class ReactRootView extends SizeMonitoringFrameLayout implements RootView {
public class ReactRootView extends SizeMonitoringFrameLayout implements RootView, TaggedRootView {
/**
* Listener interface for react root view events
@@ -79,7 +79,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
private @Nullable Bundle mAppProperties;
private @Nullable CustomGlobalLayoutListener mCustomGlobalLayoutListener;
private @Nullable ReactRootViewEventListener mRootViewEventListener;
private int mRootViewTag;
private int mRootViewTag = ReactRootViewTagGenerator.getNextRootViewTag();
private boolean mIsAttachedToInstance;
private boolean mContentAppeared;
private final JSTouchDispatcher mJSTouchDispatcher = new JSTouchDispatcher(this);
@@ -261,6 +261,7 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
if (mReactInstanceManager != null && mIsAttachedToInstance) {
mReactInstanceManager.detachRootView(this);
mIsAttachedToInstance = false;
mRootViewTag = ReactRootViewTagGenerator.getNextRootViewTag();
}
}
@@ -363,14 +364,11 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
"the onDestroyView() of your hosting Fragment.");
}
@Override
public int getRootViewTag() {
return mRootViewTag;
}
public void setRootViewTag(int rootViewTag) {
mRootViewTag = rootViewTag;
}
private class CustomGlobalLayoutListener implements ViewTreeObserver.OnGlobalLayoutListener {
private final Rect mVisibleViewArea;
private final int mMinKeyboardHeightDetected;