From 62f66db47bf68ac8203fceee92d82556368697e3 Mon Sep 17 00:00:00 2001 From: jsdevel Date: Fri, 16 Sep 2016 03:42:03 -0700 Subject: [PATCH] Adding support for resource-id. * This closes #9777. --- .../com/facebook/react/uimanager/BaseViewManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 815bad0faddcc5..fc8545c8a0c184 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -9,6 +9,7 @@ import com.facebook.react.bridge.ReadableArray; import com.facebook.react.uimanager.annotations.ReactProp; +import java.util.concurrent.ConcurrentHashMap; /** * Base class that should be suitable for the majority of subclasses of {@link ViewManager}. @@ -35,6 +36,8 @@ public abstract class BaseViewManager TEST_IDS = new ConcurrentHashMap<>(); + /** * Used to locate views in end-to-end (UI) tests. */ @@ -84,6 +87,13 @@ public void setRenderToHardwareTexture(T view, boolean useHWTexture) { @ReactProp(name = PROP_TEST_ID) public void setTestId(T view, String testId) { + if (!TEST_IDS.containsKey(testId)) { + TEST_IDS.put(testId, view.getResources().getIdentifier(testId, "id", view.getContext().getPackageName())); + } + int mappedTestId = TEST_IDS.get(testId); + if (mappedTestId != 0 && view.getId() == View.NO_ID) { + view.setId(mappedTestId); + } view.setTag(testId); }