mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-17 12:19:12 +08:00
Explicitly make UIManagerModule use OnBatchComplete on Android
Summary: Currently, we scan all native modules to see if they implement the OnBatchCompleteListerner. If they do, we add those modules to a list, and when C++ calls OnBactchComplete is called, we execute the callback on each of the modules. The only native module implementing this callback today is the UIManagerModule. With Fabric, UIManager will also not be a native module anymore. This diff removes all the work done for creating the list and assumes that UIManagerModule is the only place that is interested in OnBatchComplete call - and calls it directly. Reviewed By: achen1 Differential Revision: D9186651 fbshipit-source-id: 473586b37c2465ccd041985dcdd56132026f34f1
This commit is contained in:
committed by
Facebook Github Bot
parent
69912495f9
commit
617e25d9b5
@@ -41,7 +41,6 @@ public class ModuleHolder {
|
||||
private final boolean mCanOverrideExistingModule;
|
||||
private final boolean mHasConstants;
|
||||
private final boolean mIsCxxModule;
|
||||
private final boolean mHasOnBatchCompleteListener;
|
||||
|
||||
private @Nullable Provider<? extends NativeModule> mProvider;
|
||||
// Outside of the constructur, these should only be checked or set when synchronized on this
|
||||
@@ -57,7 +56,6 @@ public class ModuleHolder {
|
||||
mCanOverrideExistingModule = moduleInfo.canOverrideExistingModule();
|
||||
mHasConstants = moduleInfo.hasConstants();
|
||||
mProvider = provider;
|
||||
mHasOnBatchCompleteListener = moduleInfo.hasOnBatchCompleteListener();
|
||||
mIsCxxModule = moduleInfo.isCxxModule();
|
||||
if (moduleInfo.needsEagerInit()) {
|
||||
mModule = create();
|
||||
@@ -69,7 +67,6 @@ public class ModuleHolder {
|
||||
mCanOverrideExistingModule = nativeModule.canOverrideExistingModule();
|
||||
mHasConstants = true;
|
||||
mIsCxxModule = CxxModuleWrapper.class.isAssignableFrom(nativeModule.getClass());
|
||||
mHasOnBatchCompleteListener = OnBatchCompleteListener.class.isAssignableFrom(nativeModule.getClass());
|
||||
mModule = nativeModule;
|
||||
PrinterHolder.getPrinter()
|
||||
.logMessage(ReactDebugOverlayTags.NATIVE_MODULE, "NativeModule init: %s", mName);
|
||||
@@ -121,8 +118,6 @@ public class ModuleHolder {
|
||||
|
||||
public boolean isCxxModule() {return mIsCxxModule; }
|
||||
|
||||
public boolean hasOnBatchCompleteListener() {return mHasOnBatchCompleteListener; }
|
||||
|
||||
@DoNotStrip
|
||||
public NativeModule getModule() {
|
||||
NativeModule module;
|
||||
|
||||
@@ -7,14 +7,12 @@
|
||||
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.systrace.Systrace;
|
||||
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;
|
||||
|
||||
/**
|
||||
* A set of Java APIs to expose to a particular JavaScript instance.
|
||||
@@ -23,15 +21,12 @@ public class NativeModuleRegistry {
|
||||
|
||||
private final ReactApplicationContext mReactApplicationContext;
|
||||
private final Map<String, ModuleHolder> mModules;
|
||||
private final ArrayList<ModuleHolder> mBatchCompleteListenerModules;
|
||||
|
||||
public NativeModuleRegistry(
|
||||
ReactApplicationContext reactApplicationContext,
|
||||
Map<String, ModuleHolder> modules,
|
||||
ArrayList<ModuleHolder> batchCompleteListenerModules) {
|
||||
Map<String, ModuleHolder> modules) {
|
||||
mReactApplicationContext = reactApplicationContext;
|
||||
mModules = modules;
|
||||
mBatchCompleteListenerModules = batchCompleteListenerModules;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,10 +40,6 @@ public class NativeModuleRegistry {
|
||||
return mReactApplicationContext;
|
||||
}
|
||||
|
||||
private ArrayList<ModuleHolder> getBatchCompleteListenerModules() {
|
||||
return mBatchCompleteListenerModules;
|
||||
}
|
||||
|
||||
/* package */ Collection<JavaModuleWrapper> getJavaModules(
|
||||
JSInstance jsInstance) {
|
||||
ArrayList<JavaModuleWrapper> javaModules = new ArrayList<>();
|
||||
@@ -81,15 +72,11 @@ public class NativeModuleRegistry {
|
||||
"Extending native modules with non-matching application contexts.");
|
||||
|
||||
Map<String, ModuleHolder> newModules = newRegister.getModuleMap();
|
||||
ArrayList<ModuleHolder> batchCompleteListeners = newRegister.getBatchCompleteListenerModules();
|
||||
|
||||
for (Map.Entry<String, ModuleHolder> entry : newModules.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (!mModules.containsKey(key)) {
|
||||
ModuleHolder value = entry.getValue();
|
||||
if (batchCompleteListeners.contains(value)) {
|
||||
mBatchCompleteListenerModules.add(value);
|
||||
}
|
||||
mModules.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -129,10 +116,13 @@ public class NativeModuleRegistry {
|
||||
}
|
||||
|
||||
public void onBatchComplete() {
|
||||
for (ModuleHolder moduleHolder : mBatchCompleteListenerModules) {
|
||||
if (moduleHolder.hasInstance()) {
|
||||
((OnBatchCompleteListener) moduleHolder.getModule()).onBatchComplete();
|
||||
}
|
||||
// The only native module that uses the onBatchComplete is the UI Manager. Hence, instead of
|
||||
// iterating over all the modules for find this one instance, and then calling it, we short-circuit
|
||||
// the search, and simply call OnBatchComplete on the UI Manager.
|
||||
// With Fabric, UIManager would no longer be a NativeModule, so this call would simply go away
|
||||
ModuleHolder moduleHolder = mModules.get("com.facebook.react.uimanager.UIManagerModule");
|
||||
if (moduleHolder != null && moduleHolder.hasInstance()) {
|
||||
((OnBatchCompleteListener) moduleHolder.getModule()).onBatchComplete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user