diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index a8f7c70ac..98921355a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -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, diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index c2ca75781..0822f86ba 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -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; diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java new file mode 100644 index 000000000..6483d3490 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java @@ -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; + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TaggedRootView.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TaggedRootView.java new file mode 100644 index 000000000..17899a070 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TaggedRootView.java @@ -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(); +} diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index d6b7d554b..6e13dddf4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -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; /** *

Native module to allow JS to create and update native Views.

@@ -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;