refactor out RootView tag number logic
Reviewed By: achen1 Differential Revision: D5609280 fbshipit-source-id: bc0c9f50b2938f05d5e43f50491ff6f0de154fb6
This commit is contained in:
parent
ab9c788c2c
commit
353cb61400
|
@ -930,7 +930,6 @@ public class ReactInstanceManager {
|
|||
Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "attachRootViewToInstance");
|
||||
UIManagerModule uiManagerModule = catalystInstance.getNativeModule(UIManagerModule.class);
|
||||
final int rootTag = uiManagerModule.addRootView(rootView);
|
||||
rootView.setRootViewTag(rootTag);
|
||||
rootView.runApplication();
|
||||
Systrace.beginAsyncSection(
|
||||
TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
/** Incremental counter for React Root View tag. */
|
||||
public class ReactRootViewTagGenerator {
|
||||
|
||||
// Keep in sync with ReactIOSTagHandles JS module - see that file for an explanation on why the
|
||||
// increment here is 10.
|
||||
private static final int ROOT_VIEW_TAG_INCREMENT = 10;
|
||||
|
||||
private static int sNextRootViewTag = 1;
|
||||
|
||||
public static synchronized int getNextRootViewTag() {
|
||||
final int tag = sNextRootViewTag;
|
||||
sNextRootViewTag += ROOT_VIEW_TAG_INCREMENT;
|
||||
return tag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
// Copyright 2004-present Facebook. All Rights Reserved.
|
||||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
/** Interface for the a ReactRootView with a tag. */
|
||||
public interface TaggedRootView {
|
||||
|
||||
int getRootViewTag();
|
||||
}
|
|
@ -9,15 +9,11 @@
|
|||
|
||||
package com.facebook.react.uimanager;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_START;
|
||||
|
||||
import android.content.ComponentCallbacks2;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.react.animation.Animation;
|
||||
import com.facebook.react.bridge.Callback;
|
||||
|
@ -37,9 +33,10 @@ import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugL
|
|||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.facebook.systrace.Systrace;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.CREATE_UI_MANAGER_MODULE_CONSTANTS_START;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* <p>Native module to allow JS to create and update native Views.</p>
|
||||
|
@ -76,9 +73,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
|
||||
protected static final String NAME = "UIManager";
|
||||
|
||||
// Keep in sync with ReactIOSTagHandles JS module - see that file for an explanation on why the
|
||||
// increment here is 10
|
||||
private static final int ROOT_VIEW_TAG_INCREMENT = 10;
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private final EventDispatcher mEventDispatcher;
|
||||
|
@ -86,7 +80,6 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
private final UIImplementation mUIImplementation;
|
||||
private final MemoryTrimCallback mMemoryTrimCallback = new MemoryTrimCallback();
|
||||
|
||||
private int mNextRootViewTag = 1;
|
||||
private int mBatchId = 0;
|
||||
|
||||
public UIManagerModule(
|
||||
|
@ -188,8 +181,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"UIManagerModule.addRootView");
|
||||
final int tag = mNextRootViewTag;
|
||||
mNextRootViewTag += ROOT_VIEW_TAG_INCREMENT;
|
||||
final int tag = ((TaggedRootView) rootView).getRootViewTag();
|
||||
|
||||
final int width;
|
||||
final int height;
|
||||
|
|
Loading…
Reference in New Issue