mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Setting bridge up for sharing: allowing native modules to register after init
Reviewed By: javache Differential Revision: D4945784 fbshipit-source-id: 80e7236e9ccd5d5c9a7fba7c96b98fc38b43a2fc
This commit is contained in:
committed by
Facebook Github Bot
parent
1ae54b5108
commit
5c5410459e
@@ -13,6 +13,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.systrace.Systrace;
|
||||
@@ -35,6 +36,21 @@ public class NativeModuleRegistry {
|
||||
mBatchCompleteListenerModules = batchCompleteListenerModules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private getters for combining NativeModuleRegistrys
|
||||
*/
|
||||
private Map<Class<? extends NativeModule>, ModuleHolder> getModuleMap() {
|
||||
return mModules;
|
||||
}
|
||||
|
||||
private ReactApplicationContext getReactApplicationContext() {
|
||||
return mReactApplicationContext;
|
||||
}
|
||||
|
||||
private ArrayList<ModuleHolder> getBatchCompleteListenerModules() {
|
||||
return mBatchCompleteListenerModules;
|
||||
}
|
||||
|
||||
/* package */ Collection<JavaModuleWrapper> getJavaModules(
|
||||
JSInstance jsInstance) {
|
||||
ArrayList<JavaModuleWrapper> javaModules = new ArrayList<>();
|
||||
@@ -58,6 +74,29 @@ public class NativeModuleRegistry {
|
||||
return cxxModules;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds any new modules to the current module regsitry
|
||||
*/
|
||||
/* package */ void registerModules(NativeModuleRegistry newRegister) {
|
||||
|
||||
Assertions.assertCondition(mReactApplicationContext.equals(newRegister.getReactApplicationContext()),
|
||||
"Extending native modules with non-matching application contexts.");
|
||||
|
||||
Map<Class<? extends NativeModule>, ModuleHolder> newModules = newRegister.getModuleMap();
|
||||
ArrayList<ModuleHolder> batchCompleteListeners = newRegister.getBatchCompleteListenerModules();
|
||||
|
||||
for (Map.Entry<Class<? extends NativeModule>, ModuleHolder> entry : newModules.entrySet()) {
|
||||
Class<? extends NativeModule> key = entry.getKey();
|
||||
if (!mModules.containsKey(key)) {
|
||||
ModuleHolder value = entry.getValue();
|
||||
if (batchCompleteListeners.contains(value)) {
|
||||
mBatchCompleteListenerModules.add(value);
|
||||
}
|
||||
mModules.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* package */ void notifyJSInstanceDestroy() {
|
||||
mReactApplicationContext.assertOnNativeModulesQueueThread();
|
||||
Systrace.beginSection(
|
||||
|
||||
Reference in New Issue
Block a user