Skip to content

Commit

Permalink
Adding support for resource-id.
Browse files Browse the repository at this point in the history
* This closes #9777.
  • Loading branch information
jsdevel committed Sep 19, 2016
1 parent 7b2080e commit e406eb9
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -35,6 +36,8 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
private static final String PROP_TRANSLATE_X = "translateX";
private static final String PROP_TRANSLATE_Y = "translateY";

private static final ConcurrentHashMap<String, Integer> TEST_IDS = new ConcurrentHashMap<>();

/**
* Used to locate views in end-to-end (UI) tests.
*/
Expand Down Expand Up @@ -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.setId(mappedTestId);
}
view.setTag(testId);
}

Expand Down

0 comments on commit e406eb9

Please sign in to comment.