Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ReactRootView mount/unmount race condition
- Loading branch information
Showing
3 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
ReactAndroid/src/androidTest/java/com/facebook/react/tests/core/BUCK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# BUILD FILE SYNTAX: SKYLARK | ||
load( | ||
"//tools/build_defs/oss:rn_defs.bzl", | ||
"IS_OSS_BUILD", | ||
"react_native_dep", | ||
"react_native_integration_tests_target", | ||
"react_native_target", | ||
"rn_android_library", | ||
) | ||
|
||
rn_android_library( | ||
name = "core", | ||
srcs = glob(["*.java"]), | ||
deps = ([ | ||
react_native_dep("third-party/java/espresso:espresso"), | ||
react_native_dep("third-party/java/fest:fest"), | ||
react_native_dep("third-party/java/junit:junit"), | ||
react_native_dep("third-party/java/testing-support-lib:testing-support-lib"), | ||
react_native_integration_tests_target("java/com/facebook/react/testing:testing"), | ||
react_native_integration_tests_target("java/com/facebook/react/testing/rule:rule"), | ||
react_native_target("java/com/facebook/react:react"), | ||
react_native_target("java/com/facebook/react/bridge:bridge"), | ||
react_native_target("java/com/facebook/react/common:common"), | ||
react_native_target("java/com/facebook/react/shell:shell"), | ||
react_native_target("java/com/facebook/react/uimanager:uimanager"), | ||
]) + ([ | ||
react_native_dep("java/com/facebook/fbreact/testing:testing"), | ||
]) if not IS_OSS_BUILD else [], | ||
) |
46 changes: 46 additions & 0 deletions
46
...tAndroid/src/androidTest/java/com/facebook/react/tests/core/ReactInstanceManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.facebook.react.tests.core; | ||
|
||
import android.app.Activity; | ||
import android.support.test.annotation.UiThreadTest; | ||
import android.support.test.rule.ActivityTestRule; | ||
import android.support.test.runner.AndroidJUnit4; | ||
import com.facebook.react.ReactInstanceManager; | ||
import com.facebook.react.ReactRootView; | ||
import com.facebook.react.common.LifecycleState; | ||
import com.facebook.react.shell.MainReactPackage; | ||
import com.facebook.react.testing.ReactTestHelper; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ReactInstanceManagerTest { | ||
|
||
private ReactInstanceManager mReactInstanceManager; | ||
private ReactRootView mReactRootView; | ||
|
||
@Rule public ActivityTestRule<Activity> mActivityRule = new ActivityTestRule<>(Activity.class); | ||
|
||
@Before | ||
public void setup() { | ||
Activity activity = mActivityRule.getActivity(); | ||
mReactRootView = new ReactRootView(activity); | ||
mReactInstanceManager = | ||
ReactTestHelper.getReactTestFactory() | ||
.getReactInstanceManagerBuilder() | ||
.setApplication(activity.getApplication()) | ||
.setBundleAssetName("AndroidTestBundle.js") | ||
.setInitialLifecycleState(LifecycleState.BEFORE_CREATE) | ||
.addPackage(new MainReactPackage()) | ||
.build(); | ||
} | ||
|
||
@Test | ||
@UiThreadTest | ||
public void testMountUnmount() { | ||
mReactInstanceManager.onHostResume(mActivityRule.getActivity()); | ||
mReactRootView.startReactApplication(mReactInstanceManager, "ViewLayoutTestApp"); | ||
mReactRootView.unmountReactApplication(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters