mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 08:05:34 +00:00
Fix check for if we are ready to make js calls
Reviewed By: mhorowitz Differential Revision: D3485010 fbshipit-source-id: 5a3ce9be6a88f02478fb711fd09c57e4b2ccfc0d
This commit is contained in:
parent
f8c486f03c
commit
d055ab548e
@ -75,6 +75,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
private final NativeModuleRegistry mJavaRegistry;
|
private final NativeModuleRegistry mJavaRegistry;
|
||||||
private final NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
private final NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
||||||
private boolean mInitialized = false;
|
private boolean mInitialized = false;
|
||||||
|
private volatile boolean mAcceptCalls = false;
|
||||||
|
|
||||||
private boolean mJSBundleHasLoaded;
|
private boolean mJSBundleHasLoaded;
|
||||||
|
|
||||||
@ -165,6 +166,10 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runJSBundle() {
|
public void runJSBundle() {
|
||||||
|
// This should really be done when we post the task that runs the JS bundle
|
||||||
|
// (don't even need to wait for it to finish). Since that is currently done
|
||||||
|
// synchronously, marking it here is fine.
|
||||||
|
mAcceptCalls = true;
|
||||||
Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
|
Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
|
||||||
mJSBundleHasLoaded = true;
|
mJSBundleHasLoaded = true;
|
||||||
// incrementPendingJSCalls();
|
// incrementPendingJSCalls();
|
||||||
@ -191,8 +196,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
FLog.w(ReactConstants.TAG, "Calling JS function after bridge has been destroyed.");
|
FLog.w(ReactConstants.TAG, "Calling JS function after bridge has been destroyed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!mInitialized) {
|
if (!mAcceptCalls) {
|
||||||
throw new RuntimeException("Attempt to call JS function before instance initialization.");
|
throw new RuntimeException("Attempt to call JS function before JS bundle is loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
callJSFunction(executorToken, module, method, arguments, tracingName);
|
callJSFunction(executorToken, module, method, arguments, tracingName);
|
||||||
@ -253,6 +258,12 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
Assertions.assertCondition(
|
Assertions.assertCondition(
|
||||||
!mInitialized,
|
!mInitialized,
|
||||||
"This catalyst instance has already been initialized");
|
"This catalyst instance has already been initialized");
|
||||||
|
// We assume that the instance manager blocks on running the JS bundle. If
|
||||||
|
// that changes, then we need to set mAcceptCalls just after posting the
|
||||||
|
// task that will run the js bundle.
|
||||||
|
Assertions.assertCondition(
|
||||||
|
mAcceptCalls,
|
||||||
|
"RunJSBundle hasn't completed.");
|
||||||
mInitialized = true;
|
mInitialized = true;
|
||||||
mJavaRegistry.notifyCatalystInstanceInitialized();
|
mJavaRegistry.notifyCatalystInstanceInitialized();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user