Skip to content

Commit 5a61912

Browse files
committed
Adding support for resource-id.
* This closes #9777.
1 parent 7b2080e commit 5a61912

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import com.facebook.react.bridge.ReadableArray;
1111
import com.facebook.react.uimanager.annotations.ReactProp;
12+
import java.util.concurrent.ConcurrentHashMap;
1213

1314
/**
1415
* Base class that should be suitable for the majority of subclasses of {@link ViewManager}.
@@ -35,6 +36,8 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
3536
private static final String PROP_TRANSLATE_X = "translateX";
3637
private static final String PROP_TRANSLATE_Y = "translateY";
3738

39+
private static final ConcurrentHashMap<String, Integer> TEST_IDS = new ConcurrentHashMap<>();
40+
3841
/**
3942
* Used to locate views in end-to-end (UI) tests.
4043
*/
@@ -84,6 +87,13 @@ public void setRenderToHardwareTexture(T view, boolean useHWTexture) {
8487

8588
@ReactProp(name = PROP_TEST_ID)
8689
public void setTestId(T view, String testId) {
90+
if (!TEST_IDS.containsKey(testId)) {
91+
TEST_IDS.put(testId, view.getResources().getIdentifier(testId, "id", view.getContext().getPackageName()));
92+
}
93+
int mappedTestId = TEST_IDS.get(testId);
94+
if (mappedTestId != 0 && view.getId() == 0) {
95+
view.setId(mappedTestId);
96+
}
8797
view.setTag(testId);
8898
}
8999

0 commit comments

Comments
 (0)