Queue JS calls that come in before JS bundle has started loading instead of crashing

Summary: This mimics (some of) the behavior we have on iOS where if you call a JS module method before the JS bundle has started loading, we just queue up those calls and execute them after the bundle has started loading.

Reviewed By: javache

Differential Revision: D4117581

fbshipit-source-id: 58c5a6f87aeeb86083385334d92f2716a0574ba1
This commit is contained in:
Andy Street
2016-11-03 09:33:10 -07:00
committed by Facebook Github Bot
parent 52d90da75e
commit 68aeffe01f
3 changed files with 46 additions and 13 deletions

View File

@@ -40,7 +40,8 @@ public class ReactContext extends ContextWrapper {
private static final String EARLY_JS_ACCESS_EXCEPTION_MESSAGE =
"Tried to access a JS module before the React instance was fully set up. Calls to " +
"ReactContext#getJSModule should be protected by ReactContext#hasActiveCatalystInstance().";
"ReactContext#getJSModule should only happen once initialize() has been called on your " +
"native module.";
private final CopyOnWriteArraySet<LifecycleEventListener> mLifecycleEventListeners =
new CopyOnWriteArraySet<>();
@@ -143,7 +144,7 @@ public class ReactContext extends ContextWrapper {
}
public boolean hasActiveCatalystInstance() {
return mCatalystInstance != null && mCatalystInstance.isAcceptingCalls();
return mCatalystInstance != null && !mCatalystInstance.isDestroyed();
}
public LifecycleState getLifecycleState() {