diff --git a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java index 5ca48fcf6..91b2c523d 100644 --- a/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java +++ b/ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactAppTestActivity.java @@ -1,16 +1,16 @@ /** * Copyright (c) 2014-present, Facebook, Inc. * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. + *
This source code is licensed under the MIT license found in the LICENSE file in the root
+ * directory of this source tree.
*/
-
package com.facebook.react.testing;
import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread;
import android.content.Intent;
import android.graphics.Bitmap;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
@@ -47,6 +47,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
+
public class ReactAppTestActivity extends FragmentActivity
implements DefaultHardwareBackBtnHandler, PermissionAwareActivity {
@@ -56,11 +57,10 @@ public class ReactAppTestActivity extends FragmentActivity
private static final int ROOT_VIEW_ID = 8675309;
// we need a bigger timeout for CI builds because they run on a slow emulator
private static final long IDLE_TIMEOUT_MS = 120000;
-
+ private final CountDownLatch mDestroyCountDownLatch = new CountDownLatch(1);
private CountDownLatch mLayoutEvent = new CountDownLatch(1);
private @Nullable ReactBridgeIdleSignaler mBridgeIdleSignaler;
private ScreenshotingFrameLayout mScreenshotingFrameLayout;
- private final CountDownLatch mDestroyCountDownLatch = new CountDownLatch(1);
private @Nullable ReactInstanceManager mReactInstanceManager;
private @Nullable ReactRootView mReactRootView;
private LifecycleState mLifecycleState = LifecycleState.BEFORE_RESUME;
@@ -138,10 +138,7 @@ public class ReactAppTestActivity extends FragmentActivity
loadApp(appKey, spec, null, DEFAULT_BUNDLE_NAME, enableDevSupport);
}
- public void loadApp(
- String appKey,
- ReactInstanceSpecForTest spec,
- String bundleName) {
+ public void loadApp(String appKey, ReactInstanceSpecForTest spec, String bundleName) {
loadApp(appKey, spec, null, bundleName, false /* = useDevSupport */);
}
@@ -160,11 +157,11 @@ public class ReactAppTestActivity extends FragmentActivity
}
public void loadApp(
- String appKey,
- ReactInstanceSpecForTest spec,
- @Nullable Bundle initialProps,
- String bundleName,
- boolean useDevSupport) {
+ String appKey,
+ ReactInstanceSpecForTest spec,
+ @Nullable Bundle initialProps,
+ String bundleName,
+ boolean useDevSupport) {
loadBundle(spec, bundleName, useDevSupport);
renderComponent(appKey, initialProps);
}
@@ -175,32 +172,34 @@ public class ReactAppTestActivity extends FragmentActivity
public void renderComponent(final String appKey, final @Nullable Bundle initialProps) {
final CountDownLatch currentLayoutEvent = mLayoutEvent = new CountDownLatch(1);
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- Assertions.assertNotNull(mReactRootView).getViewTreeObserver().addOnGlobalLayoutListener(
- new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- currentLayoutEvent.countDown();
- }
- });
- Assertions.assertNotNull(mReactRootView)
- .startReactApplication(mReactInstanceManager, appKey, initialProps);
- }
- });
- try {
- waitForBridgeAndUIIdle();
- waitForLayout(5000);
- } catch (InterruptedException e) {
- throw new RuntimeException("Layout never occurred for component " + appKey, e);
- }
+ runOnUiThread(
+ new Runnable() {
+ @Override
+ public void run() {
+ Assertions.assertNotNull(mReactRootView)
+ .getViewTreeObserver()
+ .addOnGlobalLayoutListener(
+ new ViewTreeObserver.OnGlobalLayoutListener() {
+ @Override
+ public void onGlobalLayout() {
+ currentLayoutEvent.countDown();
+ Assertions.assertNotNull(mReactRootView)
+ .getViewTreeObserver()
+ .removeGlobalOnLayoutListener(this);
+ }
+ });
+ Assertions.assertNotNull(mReactRootView)
+ .startReactApplication(mReactInstanceManager, appKey, initialProps);
+ }
+ });
+ try {
+ waitForBridgeAndUIIdle();
+ waitForLayout(5000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Layout never occurred for component " + appKey, e);}
}
- public void loadBundle(
- ReactInstanceSpecForTest spec,
- String bundleName,
- boolean useDevSupport) {
+ public void loadBundle(ReactInstanceSpecForTest spec, String bundleName, boolean useDevSupport) {
mBridgeIdleSignaler = new ReactBridgeIdleSignaler();
@@ -219,7 +218,7 @@ public class ReactAppTestActivity extends FragmentActivity
// By not setting a JS module name, we force the bundle to be always loaded from
// assets, not the devserver, even if dev mode is enabled (such as when testing redboxes).
// This makes sense because we never run the devserver in tests.
- //.setJSMainModuleName()
+ // .setJSMainModuleName()
.setUseDeveloperSupport(useDevSupport)
.setBridgeIdleDebugListener(mBridgeIdleSignaler)
.setInitialLifecycleState(mLifecycleState)
@@ -230,43 +229,54 @@ public class ReactAppTestActivity extends FragmentActivity
final ReactApplicationContext reactApplicationContext,
final JavaScriptContextHolder jsContext) {
return Arrays.