mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 09:29:07 +08:00
Add support for async callbacks in ReactFindViewUtil
Reviewed By: AaaChiuuu Differential Revision: D4841500 fbshipit-source-id: 16620d72bd636ad13085c15c38862e16da6c42d2
This commit is contained in:
committed by
Facebook Github Bot
parent
8fc3b48c65
commit
21819f1a99
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user