Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for resource-id #18527

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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");
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ public void testMetionsInputColors() throws Throwable {

eventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
reactEditText.getId(),
ReactFindViewUtil.getReactTag(reactEditText),
newText.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
reactEditText.incrementAndGetEventCounter()));

eventDispatcher.dispatchEvent(
new ReactTextInputEvent(
reactEditText.getId(),
ReactFindViewUtil.getReactTag(reactEditText),
newText.toString(),
"",
start,
Expand All @@ -186,15 +186,15 @@ public void testMetionsInputColors() throws Throwable {

eventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
reactEditText.getId(),
ReactFindViewUtil.getReactTag(reactEditText),
newText.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
reactEditText.incrementAndGetEventCounter()));

eventDispatcher.dispatchEvent(
new ReactTextInputEvent(
reactEditText.getId(),
ReactFindViewUtil.getReactTag(reactEditText),
moreText,
"",
start,
Expand All @@ -218,15 +218,15 @@ public void testMetionsInputColors() throws Throwable {

eventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
reactEditText.getId(),
ReactFindViewUtil.getReactTag(reactEditText),
newText.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
reactEditText.incrementAndGetEventCounter()));

eventDispatcher.dispatchEvent(
new ReactTextInputEvent(
reactEditText.getId(),
ReactFindViewUtil.getReactTag(reactEditText),
moreText,
"",
start,
Expand Down
1 change: 1 addition & 0 deletions ReactAndroid/src/main/java/com/facebook/react/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions ReactAndroid/src/main/java/com/facebook/react/flat/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -310,7 +311,7 @@ private boolean isNotClipped(int id) {

@Override
void onClippedViewDropped(View view) {
unclip(view.getId());
unclip(ReactFindViewUtil.getReactTag(view));
mFlatViewGroup.removeDetachedView(view);
}

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -219,7 +220,7 @@ public int reactTagForTouch(float touchX, float touchY) {
}

// no children found
return getId();
return ReactFindViewUtil.getReactTag(this);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion ReactAndroid/src/main/java/com/facebook/react/touch/BUCK
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,6 +45,7 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
*/
public static final String PROP_TEST_ID = "testID";
public static final String PROP_NATIVE_ID = "nativeID";
public static final String RESOURCE_ID = "id";

private static MatrixMathHelper.MatrixDecompositionContext sMatrixDecompositionContext =
new MatrixMathHelper.MatrixDecompositionContext();
Expand Down Expand Up @@ -92,6 +95,9 @@ public void setRenderToHardwareTexture(T view, boolean useHWTexture) {

@ReactProp(name = PROP_TEST_ID)
public void setTestId(T view, String testId) {
String packageName = view.getContext().getPackageName();
@IdRes int viewId = view.getResources().getIdentifier(testId, RESOURCE_ID, packageName);
view.setId(viewId);
view.setTag(R.id.react_test_id, testId);

// temporarily set the tag and keyed tags to avoid end to end test regressions
Expand Down
Loading