mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-13 22:29:45 +08:00
Expose way for native modules to modify JSC context
Reviewed By: svcscm Differential Revision: D2933197 fb-gh-sync-id: 32eb943ab341804343bbcadd29f0377fccf75de6 shipit-source-id: 32eb943ab341804343bbcadd29f0377fccf75de6
This commit is contained in:
committed by
facebook-github-bot-1
parent
46a8f1d8e0
commit
e5ba46c30d
@@ -332,6 +332,11 @@ public abstract class BaseJavaModule implements NativeModule {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReactBridgeInitialized(ReactBridge bridge) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCatalystInstanceDestroy() {
|
||||
// do nothing
|
||||
|
||||
@@ -127,6 +127,7 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
mJavaRegistry.notifyReactBridgeInitialized(bridge);
|
||||
return bridge;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,15 @@ public interface NativeModule {
|
||||
*/
|
||||
boolean canOverrideExistingModule();
|
||||
|
||||
/**
|
||||
* Called on the JS thread after a ReactBridge has been created. This is useful for native modules
|
||||
* that need to do any setup before the JS bundle has been loaded. An example of this would be
|
||||
* installing custom functionality into the JavaScriptCore context.
|
||||
*
|
||||
* @param bridge the ReactBridge instance that has just been created
|
||||
*/
|
||||
void onReactBridgeInitialized(ReactBridge bridge);
|
||||
|
||||
/**
|
||||
* Called before {CatalystInstance#onHostDestroy}
|
||||
*/
|
||||
|
||||
@@ -114,6 +114,19 @@ public class NativeModuleRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void notifyReactBridgeInitialized(ReactBridge bridge) {
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"NativeModuleRegistry_notifyReactBridgeInitialized");
|
||||
try {
|
||||
for (NativeModule nativeModule : mModuleInstances.values()) {
|
||||
nativeModule.onReactBridgeInitialized(bridge);
|
||||
}
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
|
||||
public void onBatchComplete() {
|
||||
for (int i = 0; i < mBatchCompleteListenerModules.size(); i++) {
|
||||
mBatchCompleteListenerModules.get(i).onBatchComplete();
|
||||
|
||||
@@ -87,4 +87,13 @@ public class ReactBridge extends Countable {
|
||||
public native void stopProfiler(String title, String filename);
|
||||
private native void handleMemoryPressureModerate();
|
||||
private native void handleMemoryPressureCritical();
|
||||
|
||||
/**
|
||||
* This method will return a long representing the underlying JSGlobalContextRef pointer or
|
||||
* 0 (representing NULL) when in Chrome debug mode, and is only useful if passed back through
|
||||
* the JNI to native code that will use it with the JavaScriptCore C API.
|
||||
* **WARNING:** This method is *experimental* and should only be used when no other option is
|
||||
* available. It will likely change in a future release!
|
||||
*/
|
||||
public native long getJavaScriptContextNativePtrExperimental();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user