Make DebugCorePackage a TurboReactPackage
Summary: The NativeModules in DebugCorePackage are now TurboModule-compatible. Therefore, we must make this extend `TurboReactPackage`. Changelog: [Internal] - Make DebugCorePackage a TurboReactPackage Reviewed By: fkgozali Differential Revision: D18974084 fbshipit-source-id: 648b54fefe7f8952666d5a23a9d81cc6bb167b31
This commit is contained in:
Родитель
50999b1cf2
Коммит
4ba466c515
|
@ -7,16 +7,17 @@
|
|||
|
||||
package com.facebook.react;
|
||||
|
||||
import com.facebook.react.bridge.ModuleSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.devsupport.JSCHeapCapture;
|
||||
import com.facebook.react.devsupport.JSDevSupport;
|
||||
import com.facebook.react.module.annotations.ReactModule;
|
||||
import com.facebook.react.module.annotations.ReactModuleList;
|
||||
import com.facebook.react.module.model.ReactModuleInfo;
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Provider;
|
||||
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Package defining core framework modules (e.g. UIManager). It should be used for modules that
|
||||
|
@ -28,27 +29,63 @@ import javax.inject.Provider;
|
|||
JSCHeapCapture.class,
|
||||
JSDevSupport.class,
|
||||
})
|
||||
/* package */ class DebugCorePackage extends LazyReactPackage {
|
||||
|
||||
public class DebugCorePackage extends TurboReactPackage {
|
||||
DebugCorePackage() {}
|
||||
|
||||
@Override
|
||||
public List<ModuleSpec> getNativeModules(final ReactApplicationContext reactContext) {
|
||||
List<ModuleSpec> moduleSpecList = new ArrayList<>();
|
||||
moduleSpecList.add(
|
||||
ModuleSpec.nativeModuleSpec(
|
||||
JSCHeapCapture.class,
|
||||
new Provider<NativeModule>() {
|
||||
@Override
|
||||
public NativeModule get() {
|
||||
return new JSCHeapCapture(reactContext);
|
||||
}
|
||||
}));
|
||||
return moduleSpecList;
|
||||
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
|
||||
switch (name) {
|
||||
case JSCHeapCapture.TAG:
|
||||
return new JSCHeapCapture(reactContext);
|
||||
case JSDevSupport.MODULE_NAME:
|
||||
return new JSDevSupport(reactContext);
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"In CoreModulesPackage, could not find Native module for " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReactModuleInfoProvider getReactModuleInfoProvider() {
|
||||
return LazyReactPackage.getReactModuleInfoProviderViaReflection(this);
|
||||
try {
|
||||
Class<?> reactModuleInfoProviderClass =
|
||||
Class.forName("com.facebook.react.DebugCorePackage$$ReactModuleInfoProvider");
|
||||
return (ReactModuleInfoProvider) reactModuleInfoProviderClass.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
// In OSS case, the annotation processor does not run. We fall back on creating this by hand
|
||||
Class<? extends NativeModule>[] moduleList =
|
||||
new Class[] {
|
||||
JSCHeapCapture.class, JSDevSupport.class,
|
||||
};
|
||||
|
||||
final Map<String, ReactModuleInfo> reactModuleInfoMap = new HashMap<>();
|
||||
for (Class<? extends NativeModule> moduleClass : moduleList) {
|
||||
ReactModule reactModule = moduleClass.getAnnotation(ReactModule.class);
|
||||
|
||||
reactModuleInfoMap.put(
|
||||
reactModule.name(),
|
||||
new ReactModuleInfo(
|
||||
reactModule.name(),
|
||||
moduleClass.getName(),
|
||||
reactModule.canOverrideExistingModule(),
|
||||
reactModule.needsEagerInit(),
|
||||
reactModule.hasConstants(),
|
||||
reactModule.isCxxModule(),
|
||||
TurboModule.class.isAssignableFrom(moduleClass)));
|
||||
}
|
||||
|
||||
return new ReactModuleInfoProvider() {
|
||||
@Override
|
||||
public Map<String, ReactModuleInfo> getReactModuleInfos() {
|
||||
return reactModuleInfoMap;
|
||||
}
|
||||
};
|
||||
} catch (InstantiationException e) {
|
||||
throw new RuntimeException(
|
||||
"No ReactModuleInfoProvider for DebugCorePackage$$ReactModuleInfoProvider", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(
|
||||
"No ReactModuleInfoProvider for DebugCorePackage$$ReactModuleInfoProvider", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ import java.io.File;
|
|||
|
||||
// This module is being called only by Java via the static method "captureHeap" that
|
||||
// requires it to already be initialized, thus we eagerly initialize this module
|
||||
@ReactModule(name = "JSCHeapCapture", needsEagerInit = true)
|
||||
@ReactModule(name = JSCHeapCapture.TAG, needsEagerInit = true)
|
||||
public class JSCHeapCapture extends ReactContextBaseJavaModule {
|
||||
public static final String TAG = JSCHeapCapture.class.getSimpleName();
|
||||
public static final String TAG = "JSCHeapCapture";
|
||||
|
||||
public interface HeapCapture extends JavaScriptModule {
|
||||
void captureHeap(String path);
|
||||
|
|
Загрузка…
Ссылка в новой задаче