diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK index 7d96b9b3bb530e..4c0afb7f229dd5 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/BUCK @@ -35,6 +35,7 @@ rn_android_library( react_native_target("java/com/facebook/react/modules/debug:interfaces"), react_native_target("java/com/facebook/react/shell:shell"), react_native_target("java/com/facebook/react/uimanager:uimanager"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("res:uimanager"), ], ) diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java index 307caf3c0170e8..004b00b7fcce2e 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java @@ -38,6 +38,7 @@ import com.facebook.react.uimanager.UIImplementationProvider; import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManagerRegistry; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -74,7 +75,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(rootView); mScreenshotingFrameLayout = new ScreenshotingFrameLayout(this); - mScreenshotingFrameLayout.setId(ROOT_VIEW_ID); + ReactFindViewUtil.setReactTag(mScreenshotingFrameLayout, ROOT_VIEW_ID); rootView.addView(mScreenshotingFrameLayout); mReactRootView = new ReactRootView(this); diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java index 4d58d579139d61..539f99ff0c31d7 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/CatalystUIManagerTestCase.java @@ -98,7 +98,7 @@ public void run() { public void testFlexUIRendered() { FrameLayout rootView = createRootView(); - jsModule.renderFlexTestApplication(rootView.getId()); + jsModule.renderFlexTestApplication(rootReactFindViewUtil.getReactTag(view)); waitForBridgeAndUIIdle(); assertEquals(1, rootView.getChildCount()); @@ -122,7 +122,7 @@ public void testFlexUIRendered() { // Find what could be different and make the test independent of env // public void testFlexWithTextViews() { // FrameLayout rootView = createRootView(); - // jsModule.renderFlexWithTextApplication(rootView.getId()); + // jsModule.renderFlexWithTextApplication(rootReactFindViewUtil.getReactTag(view)); // waitForBridgeAndUIIdle(); // // assertEquals(1, rootView.getChildCount()); @@ -160,7 +160,7 @@ public void testFlexUIRendered() { public void testAbsolutePositionUIRendered() { FrameLayout rootView = createRootView(); - jsModule.renderAbsolutePositionTestApplication(rootView.getId()); + jsModule.renderAbsolutePositionTestApplication(rootReactFindViewUtil.getReactTag(view)); waitForBridgeAndUIIdle(); assertEquals(1, rootView.getChildCount()); @@ -174,7 +174,7 @@ public void testAbsolutePositionUIRendered() { public void testUpdatePositionInList() { FrameLayout rootView = createRootView(); - jsModule.renderUpdatePositionInListTestApplication(rootView.getId()); + jsModule.renderUpdatePositionInListTestApplication(rootReactFindViewUtil.getReactTag(view)); waitForBridgeAndUIIdle(); ViewGroup containerView = getViewByTestId(rootView, "container"); @@ -203,7 +203,7 @@ public void testUpdatePositionInList() { public void testAbsolutePositionBottomRightUIRendered() { FrameLayout rootView = createRootView(); - jsModule.renderAbsolutePositionBottomRightTestApplication(rootView.getId()); + jsModule.renderAbsolutePositionBottomRightTestApplication(rootReactFindViewUtil.getReactTag(view)); waitForBridgeAndUIIdle(); assertEquals(1, rootView.getChildCount()); diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TextInputTestCase.java b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TextInputTestCase.java index cd0e8362d8f415..09b145bcab521c 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TextInputTestCase.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/tests/TextInputTestCase.java @@ -154,7 +154,7 @@ public void testMetionsInputColors() throws Throwable { eventDispatcher.dispatchEvent( new ReactTextChangedEvent( - reactEditText.getId(), + ReactFindViewUtil.getReactTag(reactEditText), newText.toString(), (int) PixelUtil.toDIPFromPixel(contentWidth), (int) PixelUtil.toDIPFromPixel(contentHeight), @@ -162,7 +162,7 @@ public void testMetionsInputColors() throws Throwable { eventDispatcher.dispatchEvent( new ReactTextInputEvent( - reactEditText.getId(), + ReactFindViewUtil.getReactTag(reactEditText), newText.toString(), "", start, @@ -186,7 +186,7 @@ public void testMetionsInputColors() throws Throwable { eventDispatcher.dispatchEvent( new ReactTextChangedEvent( - reactEditText.getId(), + ReactFindViewUtil.getReactTag(reactEditText), newText.toString(), (int) PixelUtil.toDIPFromPixel(contentWidth), (int) PixelUtil.toDIPFromPixel(contentHeight), @@ -194,7 +194,7 @@ public void testMetionsInputColors() throws Throwable { eventDispatcher.dispatchEvent( new ReactTextInputEvent( - reactEditText.getId(), + ReactFindViewUtil.getReactTag(reactEditText), moreText, "", start, @@ -218,7 +218,7 @@ public void testMetionsInputColors() throws Throwable { eventDispatcher.dispatchEvent( new ReactTextChangedEvent( - reactEditText.getId(), + ReactFindViewUtil.getReactTag(reactEditText), newText.toString(), (int) PixelUtil.toDIPFromPixel(contentWidth), (int) PixelUtil.toDIPFromPixel(contentHeight), @@ -226,7 +226,7 @@ public void testMetionsInputColors() throws Throwable { eventDispatcher.dispatchEvent( new ReactTextInputEvent( - reactEditText.getId(), + ReactFindViewUtil.getReactTag(reactEditText), moreText, "", start, diff --git a/ReactAndroid/src/main/java/com/facebook/react/BUCK b/ReactAndroid/src/main/java/com/facebook/react/BUCK index 9a33c9af419216..ed51a25f8d75da 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/BUCK @@ -33,6 +33,7 @@ rn_android_library( react_native_target("java/com/facebook/react/modules/systeminfo:systeminfo"), react_native_target("java/com/facebook/react/modules/toast:toast"), react_native_target("java/com/facebook/react/uimanager:uimanager"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/imagehelper:imagehelper"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index 45d6782321249f..010958912e5f56 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -82,6 +82,7 @@ import com.facebook.react.uimanager.UIImplementationProvider; import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper; import com.facebook.soloader.SoLoader; import com.facebook.systrace.Systrace; @@ -713,7 +714,7 @@ public void attachRootView(ReactRootView rootView) { // Reset view content as it's going to be populated by the application content from JS. rootView.removeAllViews(); - rootView.setId(View.NO_ID); + ReactFindViewUtil.setReactTag(rootView, View.NO_ID); // If react context is being created in the background, JS application will be started // automatically when creation completes, as root view is part of the attached root view list. @@ -1058,7 +1059,7 @@ private void tearDownReactContext(ReactContext reactContext) { synchronized (mAttachedRootViews) { for (ReactRootView rootView : mAttachedRootViews) { rootView.removeAllViews(); - rootView.setId(View.NO_ID); + ReactFindViewUtil.setReactTag(rootView, View.NO_ID); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK b/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK index 76c0990a222704..c9f59b1afccca5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/BUCK @@ -15,6 +15,7 @@ rn_android_library( react_native_dep("third-party/java/okio:okio"), react_native_target("java/com/facebook/debug/holder:holder"), react_native_target("java/com/facebook/react/uimanager:uimanager"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/debug/tags:tags"), react_native_target("java/com/facebook/react/bridge:bridge"), react_native_target("java/com/facebook/react/common:common"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java index b951ef2ff22213..649f0e6537ae6b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerImpl.java @@ -52,6 +52,7 @@ import com.facebook.react.modules.debug.interfaces.DeveloperSettings; import com.facebook.react.packagerconnection.RequestHandler; import com.facebook.react.packagerconnection.Responder; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK b/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK index ec7cf4c57ca816..c699d365655ac2 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/BUCK @@ -26,6 +26,7 @@ rn_android_library( react_native_target("java/com/facebook/react/touch:touch"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/art:art"), react_native_target("java/com/facebook/react/views/image:image"), react_native_target("java/com/facebook/react/views/imagehelper:withmultisource"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java b/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java index 390f8f9225e8b2..86969862e6187e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/ClippingDrawCommandManager.java @@ -23,6 +23,7 @@ import com.facebook.infer.annotation.Assertions; import com.facebook.react.uimanager.ReactClippingViewGroup; import com.facebook.react.uimanager.ReactClippingViewGroupHelper; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * Abstract class for a {@link DrawCommandManager} with directional clipping. Allows support for @@ -310,7 +311,7 @@ private boolean isNotClipped(int id) { @Override void onClippedViewDropped(View view) { - unclip(view.getId()); + unclip(ReactFindViewUtil.getReactTag(view)); mFlatViewGroup.removeDetachedView(view); } @@ -440,7 +441,7 @@ public boolean updateClippingRect() { private void updateClippingRecursively() { for (int i = 0, children = mClippingViewGroups.size(); i < children; i++) { ReactClippingViewGroup view = mClippingViewGroups.get(i); - if (isNotClipped(((View) view).getId())) { + if (isNotClipped(ReactFindViewUtil.getReactTag((View) view))) { view.updateClippingRect(); } } @@ -465,12 +466,12 @@ private void updateClippingRecursively() { private void updateClippingToCurrentRect() { for (int i = 0, size = mFlatViewGroup.getChildCount(); i < size; i++) { View view = mFlatViewGroup.getChildAt(i); - int index = mDrawViewIndexMap.get(view.getId()); + int index = mDrawViewIndexMap.get(ReactFindViewUtil.getReactTag(view)); if (withinBounds(index) || animating(view)) { mViewsToKeep.add(view); } else { mViewsToRemove.append(i, view); - clip(view.getId(), view); + clip(ReactFindViewUtil.getReactTag(view), view); } } @@ -497,7 +498,7 @@ private void updateClippingToCurrentRect() { for (int i = 0, size = mViewsToKeep.size(); i < size; i++) { View view = mViewsToKeep.get(i); - int commandIndex = mDrawViewIndexMap.get(view.getId()); + int commandIndex = mDrawViewIndexMap.get(ReactFindViewUtil.getReactTag(view)); if (current <= commandIndex) { while (current != commandIndex) { if (mDrawCommands[current] instanceof DrawView) { @@ -595,7 +596,8 @@ public void draw(Canvas canvas) { // This is the command index of the next view that we need to draw. Since a view might be // animating, this view is either before all the commands onscreen, onscreen, or after the // onscreen commands. - int viewIndex = mDrawViewIndexMap.get(mFlatViewGroup.getChildAt(i).getId()); + int reactTag = ReactFindViewUtil.getReactTag(mFlatViewGroup.getChildAt(i)); + int viewIndex = mDrawViewIndexMap.get(reactTag); if (mStop < viewIndex) { // The current view is outside of the viewport bounds. We want to draw all the commands // up to the stop, then draw all the views outside the viewport bounds. diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java index ac1e0aadde92a5..1c08b04eaa24a5 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatNativeViewHierarchyManager.java @@ -23,6 +23,7 @@ import com.facebook.react.uimanager.ThemedReactContext; import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.ViewManagerRegistry; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * FlatNativeViewHierarchyManager is the only class that performs View manipulations. All of this @@ -51,7 +52,7 @@ public void addRootView( // When unmounting, ReactInstanceManager.detachViewFromInstance() will check id of the // top-level View (SizeMonitoringFrameLayout) and pass it back to JS. We want that View's id to // be set, otherwise NativeViewHierarchyManager will not be able to cleanup properly. - view.setId(tag); + ReactFindViewUtil.setReactTag(view, tag); addRootViewGroup(tag, root, themedContext); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java index ae94b744b9fdfa..b06db646c6d572 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java @@ -37,6 +37,7 @@ import com.facebook.react.uimanager.ReactCompoundViewGroup; import com.facebook.react.uimanager.ReactPointerEventsView; import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.image.ImageLoadEvent; import com.facebook.react.uimanager.ReactClippingViewGroup; @@ -205,7 +206,7 @@ public int reactTagForTouch(float touchX, float touchY) { * b) PointerEvents.NONE - this method will NOT be executed, because the View will be filtered * out by TouchTargetHelper. * c) PointerEvents.BOX_NONE - TouchTargetHelper will make sure that {@link #reactTagForTouch()} - * doesn't return getId(). + * doesn't return ReactFindViewUtil.getReactTag(this). */ SoftAssertions.assertCondition( mPointerEvents != PointerEvents.NONE, @@ -219,7 +220,7 @@ public int reactTagForTouch(float touchX, float touchY) { } // no children found - return getId(); + return ReactFindViewUtil.getReactTag(this); } @Override diff --git a/ReactAndroid/src/main/java/com/facebook/react/touch/BUCK b/ReactAndroid/src/main/java/com/facebook/react/touch/BUCK index 5b7dbdc25544e3..13c144e097fdf0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/touch/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/touch/BUCK @@ -1,4 +1,4 @@ -load("//ReactNative:DEFS.bzl", "rn_android_library", "react_native_dep") +load("//ReactNative:DEFS.bzl", "rn_android_library", "react_native_dep", "react_native_target") rn_android_library( name = "touch", @@ -9,5 +9,6 @@ rn_android_library( deps = [ react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/touch/JSResponderHandler.java b/ReactAndroid/src/main/java/com/facebook/react/touch/JSResponderHandler.java index c206bc725752b3..1b973da37998a0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/touch/JSResponderHandler.java +++ b/ReactAndroid/src/main/java/com/facebook/react/touch/JSResponderHandler.java @@ -13,6 +13,8 @@ import android.view.ViewGroup; import android.view.ViewParent; +import com.facebook.react.uimanager.util.ReactFindViewUtil; + /** * This class coordinates JSResponder commands for {@link UIManagerModule}. It should be set as * OnInterceptTouchEventListener for all newly created native views that implements @@ -68,7 +70,7 @@ public boolean onInterceptTouchEvent(ViewGroup v, MotionEvent event) { // Therefore since "UP" event is the last event in a gesture, we should just let it reach the // original target that is a child view of {@param v}. // http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent(android.view.MotionEvent) - return v.getId() == currentJSResponder; + return ReactFindViewUtil.getReactTag(v) == currentJSResponder; } return false; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index f1d1413d079246..5313f44465ae6e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -2,8 +2,10 @@ package com.facebook.react.uimanager; +import android.content.res.Resources; import android.graphics.Color; import android.os.Build; +import android.support.annotation.IdRes; import android.view.View; import android.view.ViewParent; import com.facebook.react.R; @@ -43,6 +45,7 @@ public abstract class BaseViewManager= 0; i--) { View child = viewGroupManager.getChildAt(viewGroup, i); - if (mTagsToViews.get(child.getId()) != null) { + if (mTagsToViews.get(ReactFindViewUtil.getReactTag(child)) != null) { dropView(child); } } viewGroupManager.removeAllViews(viewGroup); } - mTagsToViews.remove(view.getId()); - mTagsToViewManagers.remove(view.getId()); + mTagsToViews.remove(ReactFindViewUtil.getReactTag(view)); + mTagsToViewManagers.remove(ReactFindViewUtil.getReactTag(view)); } public synchronized void removeRootView(int rootViewTag) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java index fc8c4cb1476d3e..e636166ac0478f 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java @@ -19,6 +19,7 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.touch.ReactHitSlopView; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * Class responsible for identifying which react view should handle a given {@link MotionEvent}. @@ -85,7 +86,7 @@ public static int findTargetTagAndCoordinatesForTouch( float[] viewCoords, @Nullable int[] nativeViewTag) { UiThreadUtil.assertOnUiThread(); - int targetTag = viewGroup.getId(); + int targetTag = ReactFindViewUtil.getReactTag(viewGroup); // Store eventCoords in array so that they are modified to be relative to the targetView found. viewCoords[0] = eventX; viewCoords[1] = eventY; @@ -94,7 +95,7 @@ public static int findTargetTagAndCoordinatesForTouch( View reactTargetView = findClosestReactAncestor(nativeTargetView); if (reactTargetView != null) { if (nativeViewTag != null) { - nativeViewTag[0] = reactTargetView.getId(); + nativeViewTag[0] = ReactFindViewUtil.getReactTag(reactTargetView); } targetTag = getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]); } @@ -103,7 +104,7 @@ public static int findTargetTagAndCoordinatesForTouch( } private static View findClosestReactAncestor(View view) { - while (view != null && view.getId() <= 0) { + while (view != null && ReactFindViewUtil.getReactTag(view) <= 0) { view = (View) view.getParent(); } return view; @@ -239,7 +240,7 @@ private static boolean isTransformedTouchPointInView( // ViewGroup). if (view instanceof ReactCompoundView) { int reactTag = ((ReactCompoundView)view).reactTagForTouch(eventCoords[0], eventCoords[1]); - if (reactTag != view.getId()) { + if (reactTag != ReactFindViewUtil.getReactTag(view)) { // make sure we exclude the View itself because of the PointerEvents.BOX_NONE return view; } @@ -271,7 +272,7 @@ private static int getTouchTargetForView(View targetView, float eventX, float ev // {@link #findTouchTargetView()}. return ((ReactCompoundView) targetView).reactTagForTouch(eventX, eventY); } - return targetView.getId(); + return ReactFindViewUtil.getReactTag(targetView); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java index cd3104ae37264f..2db2fec3a93557 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java @@ -141,4 +141,13 @@ public static void notifyViewRendered(View view) { Object tag = view.getTag(R.id.view_tag_native_id); return tag instanceof String ? (String) tag : null; } + + public static Integer getReactTag(View view) { + Object tag = view.getTag(R.id.react_tag_id); + return tag instanceof Integer ? (Integer) tag : View.NO_ID; + } + + public static void setReactTag(View view, int reactTag) { + view.setTag(R.id.react_tag_id, reactTag); + } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK index 31c186d716907b..3133184300d0f4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/BUCK @@ -15,5 +15,6 @@ rn_android_library( react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java index e71c601f4e7b74..c9ee368dd59c94 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/checkbox/ReactCheckBoxManager.java @@ -13,6 +13,7 @@ import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** View manager for {@link ReactCheckBox} components. */ public class ReactCheckBoxManager extends SimpleViewManager { @@ -27,7 +28,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { reactContext .getNativeModule(UIManagerModule.class) .getEventDispatcher() - .dispatchEvent(new ReactCheckBoxEvent(buttonView.getId(), isChecked)); + .dispatchEvent(new ReactCheckBoxEvent(ReactFindViewUtil.getReactTag(buttonView), isChecked)); } }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/drawer/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/drawer/BUCK index 70a65ded008680..9438c38f1e0a97 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/drawer/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/drawer/BUCK @@ -18,6 +18,7 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/scroll:scroll"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java index 1620d637a9d977..072eb57212f433 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/drawer/ReactDrawerLayoutManager.java @@ -29,6 +29,7 @@ import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.drawer.events.DrawerClosedEvent; import com.facebook.react.views.drawer.events.DrawerOpenedEvent; import com.facebook.react.views.drawer.events.DrawerSlideEvent; @@ -185,25 +186,25 @@ public DrawerEventEmitter(DrawerLayout drawerLayout, EventDispatcher eventDispat @Override public void onDrawerSlide(View view, float v) { mEventDispatcher.dispatchEvent( - new DrawerSlideEvent(mDrawerLayout.getId(), v)); + new DrawerSlideEvent(ReactFindViewUtil.getReactTag(mDrawerLayout), v)); } @Override public void onDrawerOpened(View view) { mEventDispatcher.dispatchEvent( - new DrawerOpenedEvent(mDrawerLayout.getId())); + new DrawerOpenedEvent(ReactFindViewUtil.getReactTag(mDrawerLayout))); } @Override public void onDrawerClosed(View view) { mEventDispatcher.dispatchEvent( - new DrawerClosedEvent(mDrawerLayout.getId())); + new DrawerClosedEvent(ReactFindViewUtil.getReactTag(mDrawerLayout))); } @Override public void onDrawerStateChanged(int i) { mEventDispatcher.dispatchEvent( - new DrawerStateChangedEvent(mDrawerLayout.getId(), i)); + new DrawerStateChangedEvent(ReactFindViewUtil.getReactTag(mDrawerLayout), i)); } } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/image/BUCK index 9646bbddfff08e..1dab1a1a97e876 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/BUCK @@ -48,6 +48,7 @@ rn_android_library( react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/modules/fresco:fresco"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), react_native_target("java/com/facebook/react/views/imagehelper:withmultisource"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java index cb294cbb93d7eb..b1899924eb144b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageView.java @@ -53,6 +53,7 @@ import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.image.ImageResizeMode; import com.facebook.react.views.imagehelper.ImageSource; import com.facebook.react.views.imagehelper.MultiSourceHelper; @@ -240,8 +241,9 @@ public void setShouldNotifyLoadEvents(boolean shouldNotify) { mControllerListener = new BaseControllerListener() { @Override public void onSubmit(String id, Object callerContext) { + Integer reactTag = ReactFindViewUtil.getReactTag(ReactImageView.this); mEventDispatcher.dispatchEvent( - new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_START)); + new ImageLoadEvent(reactTag, ImageLoadEvent.ON_LOAD_START)); } @Override @@ -250,20 +252,22 @@ public void onFinalImageSet( @Nullable final ImageInfo imageInfo, @Nullable Animatable animatable) { if (imageInfo != null) { + Integer reactTag = ReactFindViewUtil.getReactTag(ReactImageView.this); mEventDispatcher.dispatchEvent( - new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD, + new ImageLoadEvent(reactTag, ImageLoadEvent.ON_LOAD, mImageSource.getSource(), imageInfo.getWidth(), imageInfo.getHeight())); mEventDispatcher.dispatchEvent( - new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END)); + new ImageLoadEvent(reactTag, ImageLoadEvent.ON_LOAD_END)); } } @Override public void onFailure(String id, Throwable throwable) { + Integer reactTag = ReactFindViewUtil.getReactTag(ReactImageView.this); mEventDispatcher.dispatchEvent( - new ImageLoadEvent(getId(), ImageLoadEvent.ON_ERROR)); + new ImageLoadEvent(reactTag, ImageLoadEvent.ON_ERROR)); mEventDispatcher.dispatchEvent( - new ImageLoadEvent(getId(), ImageLoadEvent.ON_LOAD_END)); + new ImageLoadEvent(reactTag, ImageLoadEvent.ON_LOAD_END)); } }; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/modal/BUCK index 50de0adde787f8..050a17f214996a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/BUCK @@ -17,6 +17,7 @@ rn_android_library( react_native_target("java/com/facebook/react/touch:touch"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/view:view"), react_native_target("res:modal"), ], diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java index 0f67e9c9e0bb13..560e4f1beb6a56 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java @@ -19,6 +19,7 @@ import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * View manager for {@link ReactModalHostView} components. @@ -79,14 +80,14 @@ protected void addEventEmitters( new ReactModalHostView.OnRequestCloseListener() { @Override public void onRequestClose(DialogInterface dialog) { - dispatcher.dispatchEvent(new RequestCloseEvent(view.getId())); + dispatcher.dispatchEvent(new RequestCloseEvent(ReactFindViewUtil.getReactTag(view))); } }); view.setOnShowListener( new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { - dispatcher.dispatchEvent(new ShowEvent(view.getId())); + dispatcher.dispatchEvent(new ShowEvent(ReactFindViewUtil.getReactTag(view))); } }); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java index ab0491fe4619fd..deebcdac84a168 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java @@ -28,6 +28,7 @@ import com.facebook.react.uimanager.RootView; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.view.ReactViewGroup; import java.util.ArrayList; import javax.annotation.Nullable; @@ -320,7 +321,7 @@ public DialogRootViewGroup(Context context) { protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); if (getChildCount() > 0) { - final int viewTag = getChildAt(0).getId(); + final int viewTag = ReactFindViewUtil.getReactTag(getChildAt(0)); ReactContext reactContext = getReactContext(); reactContext.runOnNativeModulesQueueThread( new GuardedRunnable(reactContext) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/picker/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/picker/BUCK index aca48169427385..77154e1b495300 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/picker/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/picker/BUCK @@ -14,5 +14,6 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerManager.java index 59f5461ab60795..cf0fa642603c89 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/picker/ReactPickerManager.java @@ -26,6 +26,7 @@ import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.picker.events.PickerItemSelectEvent; /** @@ -154,7 +155,7 @@ public PickerEventEmitter(ReactPicker reactPicker, EventDispatcher eventDispatch @Override public void onItemSelected(int position) { mEventDispatcher.dispatchEvent( new PickerItemSelectEvent( - mReactPicker.getId(), position)); + ReactFindViewUtil.getReactTag(mReactPicker), position)); } } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK index e2c20c51f02844..dd732b82107cb4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/BUCK @@ -20,6 +20,7 @@ rn_android_library( react_native_target("java/com/facebook/react/touch:touch"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/view:view"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java index a034694b4bd9d7..5311cef48a0d17 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.java @@ -13,6 +13,7 @@ import com.facebook.react.bridge.JSApplicationIllegalArgumentException; import com.facebook.react.bridge.ReactContext; import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * Helper class that deals with emitting Scroll Events. @@ -71,7 +72,7 @@ private static void emitScrollEvent( ReactContext reactContext = (ReactContext) scrollView.getContext(); reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( ScrollEvent.obtain( - scrollView.getId(), + ReactFindViewUtil.getReactTag(scrollView), scrollEventType, scrollView.getScrollX(), scrollView.getScrollY(), diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK index 04d91b9bf4b5fb..26bdefebaa9f09 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/slider/BUCK @@ -16,5 +16,6 @@ rn_android_library( react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java index 1cd9c261103e3a..022dc91c55c011 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/slider/ReactSliderManager.java @@ -23,6 +23,7 @@ import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.yoga.YogaMeasureFunction; import com.facebook.yoga.YogaMeasureMode; import com.facebook.yoga.YogaMeasureOutput; @@ -111,7 +112,7 @@ public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { ReactContext reactContext = (ReactContext) seekbar.getContext(); reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( new ReactSliderEvent( - seekbar.getId(), + ReactFindViewUtil.getReactTag(seekbar), ((ReactSlider) seekbar).toRealProgress(progress), fromUser)); } @@ -125,7 +126,7 @@ public void onStopTrackingTouch(SeekBar seekbar) { ReactContext reactContext = (ReactContext) seekbar.getContext(); reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( new ReactSlidingCompleteEvent( - seekbar.getId(), + ReactFindViewUtil.getReactTag(seekbar), ((ReactSlider) seekbar).toRealProgress(seekbar.getProgress()))); } }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/BUCK index b60b696d794935..ba032987d25c82 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/BUCK @@ -16,6 +16,7 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/scroll:scroll"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java index 4988129234edd5..66e005993e40e1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/swiperefresh/SwipeRefreshLayoutManager.java @@ -23,6 +23,7 @@ import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import static com.facebook.react.views.swiperefresh.SwipeRefreshLayoutManager.REACT_CLASS; @@ -92,7 +93,7 @@ protected void addEventEmitters( @Override public void onRefresh() { reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher() - .dispatchEvent(new RefreshEvent(view.getId())); + .dispatchEvent(new RefreshEvent(ReactFindViewUtil.getReactTag(view))); } }); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/BUCK index 90811afcf8e172..bf2fc223e12ac3 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/BUCK @@ -16,5 +16,6 @@ rn_android_library( react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java index 70c5a5123e949a..05318cdafb66c1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/switchview/ReactSwitchManager.java @@ -25,6 +25,7 @@ import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.ViewProps; import com.facebook.react.uimanager.annotations.ReactProp; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * View manager for {@link ReactSwitch} components. @@ -107,7 +108,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ReactContext reactContext = (ReactContext) buttonView.getContext(); reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent( new ReactSwitchEvent( - buttonView.getId(), + ReactFindViewUtil.getReactTag(buttonView), isChecked)); } }; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/text/BUCK index 4ed92a824f9352..3724dbddb3519c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/BUCK @@ -16,6 +16,7 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/view:view"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java index 226a5d4e0f4686..e2854bde1b10df 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextView.java @@ -18,6 +18,7 @@ import android.widget.TextView; import com.facebook.react.uimanager.ReactCompoundView; import com.facebook.react.uimanager.ViewDefaults; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.view.ReactViewBackgroundManager; import javax.annotation.Nullable; @@ -75,7 +76,7 @@ public void setText(ReactTextUpdate update) { @Override public int reactTagForTouch(float touchX, float touchY) { CharSequence text = getText(); - int target = getId(); + int target = ReactFindViewUtil.getReactTag(this); int x = (int) touchX; int y = (int) touchY; diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK index 60e261c2a202cc..a602103f7a88f0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/BUCK @@ -20,6 +20,7 @@ rn_android_library( react_native_target("java/com/facebook/react/modules/core:core"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/imagehelper:imagehelper"), react_native_target("java/com/facebook/react/views/scroll:scroll"), react_native_target("java/com/facebook/react/views/text:text"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 7a9f34e2a6a0dd..b63c4f7a197656 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -35,6 +35,7 @@ import com.facebook.react.bridge.ReactContext; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.UIManagerModule; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.text.CustomStyleSpan; import com.facebook.react.views.text.ReactTagSpan; import com.facebook.react.views.text.ReactTextUpdate; @@ -473,7 +474,8 @@ private void setIntrinsicContentSize() { ReactContext reactContext = (ReactContext) getContext(); UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class); final ReactTextInputLocalData localData = new ReactTextInputLocalData(this); - uiManager.setViewLocalData(getId(), localData); + Integer reactTag = ReactFindViewUtil.getReactTag(this); + uiManager.setViewLocalData(reactTag, localData); } /* package */ void setGravityHorizontal(int gravityHorizontal) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java index cc2976efdf8679..612e8f530171e0 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.java @@ -16,6 +16,7 @@ import com.facebook.react.bridge.ReactContext; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; /** * A class to implement the TextInput 'onKeyPress' API on android for soft keyboards. @@ -156,7 +157,7 @@ private void dispatchKeyEvent(String key) { } mEventDispatcher.dispatchEvent( new ReactTextInputKeyPressEvent( - mEditText.getId(), + ReactFindViewUtil.getReactTag(mEditText), key)); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index 2c5013a7e712a8..3d9f0eccd894b9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -40,6 +40,7 @@ import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.annotations.ReactPropGroup; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper; import com.facebook.react.views.scroll.ScrollEvent; import com.facebook.react.views.scroll.ScrollEventType; @@ -720,13 +721,13 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO: t7936714 merge these events mEventDispatcher.dispatchEvent( new ReactTextChangedEvent( - mEditText.getId(), + ReactFindViewUtil.getReactTag(mEditText), s.toString(), mEditText.incrementAndGetEventCounter())); mEventDispatcher.dispatchEvent( new ReactTextInputEvent( - mEditText.getId(), + ReactFindViewUtil.getReactTag(mEditText), newText, oldText, start, @@ -751,15 +752,15 @@ public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { eventDispatcher.dispatchEvent( new ReactTextInputFocusEvent( - editText.getId())); + ReactFindViewUtil.getReactTag(editText))); } else { eventDispatcher.dispatchEvent( new ReactTextInputBlurEvent( - editText.getId())); + ReactFindViewUtil.getReactTag(editText))); eventDispatcher.dispatchEvent( new ReactTextInputEndEditingEvent( - editText.getId(), + ReactFindViewUtil.getReactTag(editText), editText.getText().toString())); } } @@ -788,7 +789,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) { eventDispatcher.dispatchEvent( new ReactTextInputSubmitEditingEvent( - editText.getId(), + ReactFindViewUtil.getReactTag(editText), editText.getText().toString())); if (blurOnSubmit) { @@ -835,7 +836,7 @@ public void onLayout() { mEventDispatcher.dispatchEvent( new ReactContentSizeChangedEvent( - mEditText.getId(), + ReactFindViewUtil.getReactTag(mEditText), PixelUtil.toDIPFromPixel(contentWidth), PixelUtil.toDIPFromPixel(contentHeight))); } @@ -863,7 +864,7 @@ public void onSelectionChanged(int start, int end) { if (mPreviousSelectionStart != start || mPreviousSelectionEnd != end) { mEventDispatcher.dispatchEvent( new ReactTextInputSelectionEvent( - mReactEditText.getId(), + ReactFindViewUtil.getReactTag(mReactEditText), start, end )); @@ -891,7 +892,7 @@ public ReactScrollWatcher(ReactEditText editText) { public void onScrollChanged(int horiz, int vert, int oldHoriz, int oldVert) { if (mPreviousHoriz != horiz || mPreviousVert != vert) { ScrollEvent event = ScrollEvent.obtain( - mReactEditText.getId(), + ReactFindViewUtil.getReactTag(mReactEditText), ScrollEventType.SCROLL, horiz, vert, diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK index a3c96aab6dc4d2..9688895fae153c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/BUCK @@ -21,5 +21,6 @@ rn_android_library( react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java index 0de356f1b95ed1..1fe2fdd91e6764 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/toolbar/ReactToolbarManager.java @@ -23,6 +23,7 @@ import com.facebook.react.uimanager.ViewGroupManager; import com.facebook.react.uimanager.annotations.ReactProp; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.toolbar.events.ToolbarClickEvent; import java.util.Map; import javax.annotation.Nullable; @@ -125,7 +126,7 @@ protected void addEventEmitters(final ThemedReactContext reactContext, final Rea @Override public void onClick(View v) { mEventDispatcher.dispatchEvent( - new ToolbarClickEvent(view.getId(), -1)); + new ToolbarClickEvent(ReactFindViewUtil.getReactTag(view), -1)); } }); @@ -135,7 +136,7 @@ public void onClick(View v) { public boolean onMenuItemClick(MenuItem menuItem) { mEventDispatcher.dispatchEvent( new ToolbarClickEvent( - view.getId(), + ReactFindViewUtil.getReactTag(view), menuItem.getOrder())); return true; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/BUCK index 45ed3f183395e9..f69e19d5ce9777 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/BUCK @@ -18,6 +18,7 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/scroll:scroll"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java index 48b5f1a6194956..e7fef879e1bc89 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/viewpager/ReactViewPager.java @@ -18,6 +18,7 @@ import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.NativeGestureUtil; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import java.util.ArrayList; import java.util.List; @@ -120,15 +121,17 @@ private class PageChangeListener implements ViewPager.OnPageChangeListener { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + Integer reactTag = ReactFindViewUtil.getReactTag(ReactViewPager.this); mEventDispatcher.dispatchEvent( - new PageScrollEvent(getId(), position, positionOffset)); + new PageScrollEvent(reactTag, position, positionOffset)); } @Override public void onPageSelected(int position) { if (!mIsCurrentItemFromJs) { + Integer reactTag = ReactFindViewUtil.getReactTag(ReactViewPager.this); mEventDispatcher.dispatchEvent( - new PageSelectedEvent(getId(), position)); + new PageSelectedEvent(reactTag, position)); } } @@ -148,8 +151,9 @@ public void onPageScrollStateChanged(int state) { default: throw new IllegalStateException("Unsupported pageScrollState"); } + Integer reactTag = ReactFindViewUtil.getReactTag(ReactViewPager.this); mEventDispatcher.dispatchEvent( - new PageScrollStateChangedEvent(getId(), pageScrollState)); + new PageScrollStateChangedEvent(reactTag, pageScrollState)); } } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/webview/BUCK b/ReactAndroid/src/main/java/com/facebook/react/views/webview/BUCK index b55bad969c290e..abcbacd9c00ab8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/webview/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/views/webview/BUCK @@ -14,5 +14,6 @@ rn_android_library( react_native_target("java/com/facebook/react/module/annotations:annotations"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), ], ) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java index 7f07b2742677ab..51f0ba338dfcba 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/webview/ReactWebViewManager.java @@ -57,6 +57,7 @@ import com.facebook.react.uimanager.events.ContentSizeChangeEvent; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.webview.events.TopLoadingErrorEvent; import com.facebook.react.views.webview.events.TopLoadingFinishEvent; import com.facebook.react.views.webview.events.TopLoadingStartEvent; @@ -137,7 +138,7 @@ public void onPageStarted(WebView webView, String url, Bitmap favicon) { dispatchEvent( webView, new TopLoadingStartEvent( - webView.getId(), + ReactFindViewUtil.getReactTag(webView), createWebViewEvent(webView, url))); } @@ -208,20 +209,20 @@ public void onReceivedError( dispatchEvent( webView, - new TopLoadingErrorEvent(webView.getId(), eventData)); + new TopLoadingErrorEvent(ReactFindViewUtil.getReactTag(webView), eventData)); } protected void emitFinishEvent(WebView webView, String url) { dispatchEvent( webView, new TopLoadingFinishEvent( - webView.getId(), + ReactFindViewUtil.getReactTag(webView), createWebViewEvent(webView, url))); } protected WritableMap createWebViewEvent(WebView webView, String url) { WritableMap event = Arguments.createMap(); - event.putDouble("target", webView.getId()); + event.putDouble("target", ReactFindViewUtil.getReactTag(webView)); // Don't use webView.getUrl() here, the URL isn't updated to the new value yet in callbacks // like onPageFinished event.putString("url", url); @@ -354,7 +355,7 @@ public void onReceiveValue(String value) { } public void onMessage(String message) { - dispatchEvent(this, new TopMessageEvent(this.getId(), message)); + dispatchEvent(this, new TopMessageEvent(ReactFindViewUtil.getReactTag(this), message)); } protected void cleanupCallbacksAndDestroy() { @@ -671,7 +672,7 @@ public void onNewPicture(WebView webView, Picture picture) { dispatchEvent( webView, new ContentSizeChangeEvent( - webView.getId(), + ReactFindViewUtil.getReactTag(webView), webView.getWidth(), webView.getContentHeight())); } diff --git a/ReactAndroid/src/main/res/views/uimanager/values/ids.xml b/ReactAndroid/src/main/res/views/uimanager/values/ids.xml index 75ac81d1710607..4611b170bed9b8 100644 --- a/ReactAndroid/src/main/res/views/uimanager/values/ids.xml +++ b/ReactAndroid/src/main/res/views/uimanager/values/ids.xml @@ -1,5 +1,8 @@ + + + diff --git a/ReactAndroid/src/test/java/com/facebook/react/BUCK b/ReactAndroid/src/test/java/com/facebook/react/BUCK index 250a4c23a205d6..2ba07a64e9ebf4 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/BUCK @@ -22,6 +22,7 @@ rn_robolectric_test( react_native_target("java/com/facebook/react/common:common"), react_native_target("java/com/facebook/react/touch:touch"), react_native_target("java/com/facebook/react/uimanager:uimanager"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/text:text"), react_native_target("java/com/facebook/react/views/view:view"), react_native_tests_target("java/com/facebook/react/bridge:testhelpers"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java b/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java index c293858b4b6ade..5a0cc94dce7238 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java @@ -26,6 +26,7 @@ import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.RCTEventEmitter; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import org.junit.Before; import org.junit.Test; @@ -110,7 +111,7 @@ public void testTouchEmitter() { int rootViewId = 7; ReactRootView rootView = new ReactRootView(mReactContext); - rootView.setId(rootViewId); + ReactFindViewUtil.setReactTag(rootView, rootViewId); rootView.startReactApplication(instanceManager, ""); rootView.simulateAttachForTesting(); diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK b/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK index 385a2d6609b134..e63277f6cc6d26 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/BUCK @@ -30,6 +30,7 @@ rn_robolectric_test( react_native_target("java/com/facebook/react/touch:touch"), react_native_target("java/com/facebook/react/uimanager:uimanager"), react_native_target("java/com/facebook/react/uimanager/annotations:annotations"), + react_native_target("java/com/facebook/react/uimanager/util:util"), react_native_target("java/com/facebook/react/views/text:text"), react_native_target("java/com/facebook/react/views/view:view"), react_native_tests_target("java/com/facebook/react/bridge:testhelpers"), diff --git a/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java b/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java index 6a90e84b628cd1..343ccd0a4b013d 100644 --- a/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java +++ b/ReactAndroid/src/test/java/com/facebook/react/uimanager/UIManagerModuleTest.java @@ -32,6 +32,7 @@ import com.facebook.react.bridge.ReactTestHelper; import com.facebook.react.modules.core.ChoreographerCompat; import com.facebook.react.modules.core.ReactChoreographer; +import com.facebook.react.uimanager.util.ReactFindViewUtil; import com.facebook.react.views.text.ReactRawTextManager; import com.facebook.react.views.text.ReactRawTextShadowNode; import com.facebook.react.views.text.ReactTextViewManager; @@ -479,22 +480,22 @@ public void testTagsAssignment() { TestMoveDeleteHierarchy hierarchy = createMoveDeleteHierarchy(uiManager); View view0 = hierarchy.nativeRootView.getChildAt(0); - assertThat(view0.getId()).isEqualTo(hierarchy.view0); + assertThat(ReactFindViewUtil.getReactTag(view0)).isEqualTo(hierarchy.view0); View viewWithChildren1 = hierarchy.nativeRootView.getChildAt(1); - assertThat(viewWithChildren1.getId()).isEqualTo(hierarchy.viewWithChildren1); + assertThat(ReactFindViewUtil.getReactTag(viewWithChildren1)).isEqualTo(hierarchy.viewWithChildren1); View childView0 = ((ViewGroup) viewWithChildren1).getChildAt(0); - assertThat(childView0.getId()).isEqualTo(hierarchy.childView0); + assertThat(ReactFindViewUtil.getReactTag(childView0)).isEqualTo(hierarchy.childView0); View childView1 = ((ViewGroup) viewWithChildren1).getChildAt(1); - assertThat(childView1.getId()).isEqualTo(hierarchy.childView1); + assertThat(ReactFindViewUtil.getReactTag(childView1)).isEqualTo(hierarchy.childView1); View view2 = hierarchy.nativeRootView.getChildAt(2); - assertThat(view2.getId()).isEqualTo(hierarchy.view2); + assertThat(ReactFindViewUtil.getReactTag(view2)).isEqualTo(hierarchy.view2); View view3 = hierarchy.nativeRootView.getChildAt(3); - assertThat(view3.getId()).isEqualTo(hierarchy.view3); + assertThat(ReactFindViewUtil.getReactTag(view3)).isEqualTo(hierarchy.view3); } @Test