mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-03 22:48:25 +08:00
Summary: The logic in NativeModuleRegistryBuilder.processPackage was getting pretty complex with lot of branches. Moved the logic to get actual packages into each of the packages, instead of having it in NativeModuleRegistryBuilder. Reviewed By: achen1 Differential Revision: D9618140 fbshipit-source-id: 4be82ec65b0bd92f11f8b77044004e10c9d3b1a1
63 lines
2.0 KiB
Java
63 lines
2.0 KiB
Java
package com.facebook.react;
|
|
|
|
import android.support.annotation.NonNull;
|
|
import com.facebook.common.logging.FLog;
|
|
import com.facebook.react.bridge.ModuleHolder;
|
|
import com.facebook.react.bridge.NativeModule;
|
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
import com.facebook.react.common.ReactConstants;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
public class ReactPackageHelper {
|
|
/**
|
|
* A helper method to iterate over a list of Native Modules and convert them to an iterable.
|
|
*
|
|
* @param reactPackage
|
|
* @param reactApplicationContext
|
|
* @param reactInstanceManager
|
|
* @return
|
|
*/
|
|
public static Iterable<ModuleHolder> getNativeModuleIterator(
|
|
ReactPackage reactPackage,
|
|
ReactApplicationContext reactApplicationContext,
|
|
ReactInstanceManager reactInstanceManager) {
|
|
FLog.d(
|
|
ReactConstants.TAG,
|
|
reactPackage.getClass().getSimpleName()
|
|
+ " is not a LazyReactPackage, falling back to old version.");
|
|
final List<NativeModule> nativeModules;
|
|
if (reactPackage instanceof ReactInstancePackage) {
|
|
ReactInstancePackage reactInstancePackage = (ReactInstancePackage) reactPackage;
|
|
nativeModules =
|
|
reactInstancePackage.createNativeModules(reactApplicationContext, reactInstanceManager);
|
|
} else {
|
|
nativeModules = reactPackage.createNativeModules(reactApplicationContext);
|
|
}
|
|
return new Iterable<ModuleHolder>() {
|
|
@NonNull
|
|
@Override
|
|
public Iterator<ModuleHolder> iterator() {
|
|
return new Iterator<ModuleHolder>() {
|
|
int position = 0;
|
|
|
|
@Override
|
|
public ModuleHolder next() {
|
|
return new ModuleHolder(nativeModules.get(position++));
|
|
}
|
|
|
|
@Override
|
|
public boolean hasNext() {
|
|
return position < nativeModules.size();
|
|
}
|
|
|
|
@Override
|
|
public void remove() {
|
|
throw new UnsupportedOperationException("Cannot remove methods ");
|
|
}
|
|
};
|
|
}
|
|
};
|
|
}
|
|
}
|