mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-19 13:08:11 +08:00
Allow reactinstancemanager to set an initialization function
Reviewed By: javache Differential Revision: D5227811 fbshipit-source-id: e7868481de2a8799af5d6a6bcad26369d054b35e
This commit is contained in:
committed by
Facebook Github Bot
parent
6783694158
commit
84e80eb781
@@ -43,20 +43,27 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
|
||||
private static final AtomicInteger sNextInstanceIdForTrace = new AtomicInteger(1);
|
||||
|
||||
private static class PendingJSCall {
|
||||
public static class PendingJSCall {
|
||||
|
||||
public String mModule;
|
||||
public String mMethod;
|
||||
public NativeArray mArguments;
|
||||
public @Nullable NativeArray mArguments;
|
||||
|
||||
public PendingJSCall(
|
||||
String module,
|
||||
String method,
|
||||
NativeArray arguments) {
|
||||
public PendingJSCall(String module, String method, @Nullable NativeArray arguments) {
|
||||
mModule = module;
|
||||
mMethod = method;
|
||||
mArguments = arguments;
|
||||
}
|
||||
|
||||
void call(CatalystInstanceImpl catalystInstance) {
|
||||
NativeArray arguments = mArguments != null ? mArguments : new WritableNativeArray();
|
||||
catalystInstance.jniCallJSFunction(mModule, mMethod, arguments);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return mModule + "." + mMethod + "("
|
||||
+ (mArguments == null ? "" : mArguments.toString()) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
// Access from any thread
|
||||
@@ -216,7 +223,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
public void runJSBundle() {
|
||||
Log.d(ReactConstants.TAG, "CatalystInstanceImpl.runJSBundle()");
|
||||
Assertions.assertCondition(!mJSBundleHasLoaded, "JS bundle was already loaded!");
|
||||
|
||||
// incrementPendingJSCalls();
|
||||
mJSBundleLoader.loadScript(CatalystInstanceImpl.this);
|
||||
|
||||
@@ -227,8 +233,8 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
// gates will be queued on the JS thread behind the load.
|
||||
mAcceptCalls = true;
|
||||
|
||||
for (PendingJSCall call : mJSCallsPendingInit) {
|
||||
jniCallJSFunction(call.mModule, call.mMethod, call.mArguments);
|
||||
for (PendingJSCall function : mJSCallsPendingInit) {
|
||||
function.call(this);
|
||||
}
|
||||
mJSCallsPendingInit.clear();
|
||||
mJSBundleHasLoaded = true;
|
||||
@@ -260,8 +266,12 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
final String module,
|
||||
final String method,
|
||||
final NativeArray arguments) {
|
||||
callFunction(new PendingJSCall(module, method, arguments));
|
||||
}
|
||||
|
||||
public void callFunction(PendingJSCall function) {
|
||||
if (mDestroyed) {
|
||||
final String call = module + "." + method + "(" + arguments.toString() + ")";
|
||||
final String call = function.toString();
|
||||
FLog.w(ReactConstants.TAG, "Calling JS function after bridge has been destroyed: " + call);
|
||||
return;
|
||||
}
|
||||
@@ -269,13 +279,12 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
// Most of the time the instance is initialized and we don't need to acquire the lock
|
||||
synchronized (mJSCallsPendingInitLock) {
|
||||
if (!mAcceptCalls) {
|
||||
mJSCallsPendingInit.add(new PendingJSCall(module, method, arguments));
|
||||
mJSCallsPendingInit.add(function);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jniCallJSFunction(module, method, arguments);
|
||||
function.call(this);
|
||||
}
|
||||
|
||||
private native void jniCallJSCallback(int callbackID, NativeArray arguments);
|
||||
|
||||
Reference in New Issue
Block a user