Add support for async callbacks in ReactFindViewUtil

Reviewed By: AaaChiuuu

Differential Revision: D4841500

fbshipit-source-id: 16620d72bd636ad13085c15c38862e16da6c42d2
This commit is contained in:
Andrew Y. Chen
2017-04-11 10:23:22 -07:00
committed by Facebook Github Bot
parent 8fc3b48c65
commit 21819f1a99
4 changed files with 135 additions and 11 deletions

View File

@@ -37,9 +37,28 @@ public class NativeIdTestCase extends ReactAppInstrumentationTestCase {
"TextInput",
"View");
private boolean mViewFound;
@Override
protected void setUp() throws Exception {
mViewFound = false;
ReactFindViewUtil.addViewListener(new ReactFindViewUtil.OnViewFoundListener() {
@Override
public String getNativeId() {
return viewTags.get(0);
}
@Override
public void onViewFound(View view) {
mViewFound = true;
}
});
super.setUp();
}
public void testPropertyIsSetForViews() {
for (String nativeId : viewTags) {
View viewWithTag = ReactFindViewUtil.findViewByNativeId(
View viewWithTag = ReactFindViewUtil.findView(
getActivity().getRootView(),
nativeId);
assertNotNull(
@@ -47,4 +66,28 @@ public class NativeIdTestCase extends ReactAppInstrumentationTestCase {
viewWithTag);
}
}
public void testViewListener() {
assertTrue("OnViewFound callback was never invoked", mViewFound);
}
public void testFindView() {
mViewFound = false;
ReactFindViewUtil.findView(
getActivity().getRootView(),
new ReactFindViewUtil.OnViewFoundListener() {
@Override
public String getNativeId() {
return viewTags.get(0);
}
@Override
public void onViewFound(View view) {
mViewFound = true;
}
});
assertTrue(
"OnViewFound callback should have successfully been invoked synchronously",
mViewFound);
}
}