mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 17:54:48 +00:00
Fix LazyReactPackage in OSS
Summary: In OSS, during gradle build, the ReactModuleSpecProcess annotation-processor does not run. As a result, the `ReactModuleInfo` that we need for CoreReactPackage is not generated, resulting in a runtime error. The fix is to make LazyReactPackage revert to what it was doing earlier. In `NativeModuleRegistryBuilder`, if we dont find `ReactModuleInfo` for any `ModuleSpec`, we eagerly instantiate the module and get all the `ReactModuleInfo` from it. By returning an emoy collection if the class is not available, we force the modules in `CoreReactPackage` to use this codepath instead. The alternate fix would be to ensure that the annotation processor runs in gradle/OSS. However, the annotation processor will be removed eventually in the future, and we will also be move to generating them for JS, so that work will soon be irrelevant. Reviewed By: fkgozali, achen1 Differential Revision: D9130517 fbshipit-source-id: 469cf0e32a2f3650f098547667b3cd09a63eb1a0
This commit is contained in:
parent
3f89dd2db6
commit
42146a7a4a
@ -7,20 +7,21 @@
|
||||
|
||||
package com.facebook.react;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
|
||||
import com.facebook.react.bridge.ModuleSpec;
|
||||
import com.facebook.react.bridge.NativeModule;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.ReactMarker;
|
||||
import com.facebook.react.bridge.ReactMarkerConstants;
|
||||
import com.facebook.react.module.model.ReactModuleInfo;
|
||||
import com.facebook.react.module.model.ReactModuleInfoProvider;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.systrace.SystraceMessage;
|
||||
|
||||
import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_JAVA_BRIDGE;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* React package supporting lazy creation of native modules.
|
||||
@ -36,7 +37,16 @@ public abstract class LazyReactPackage implements ReactPackage {
|
||||
reactModuleInfoProviderClass = Class.forName(
|
||||
lazyReactPackage.getClass().getCanonicalName() + "$$ReactModuleInfoProvider");
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
// In OSS case, when the annotation processor does not run, we fall back to non-lazy mode
|
||||
// For this, we simply return an empty moduleMap.
|
||||
// NativeModuleRegistryBuilder will eagerly get all the modules, and get the info from the
|
||||
// modules directly
|
||||
return new ReactModuleInfoProvider() {
|
||||
@Override
|
||||
public Map<String, ReactModuleInfo> getReactModuleInfos() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (reactModuleInfoProviderClass == null) {
|
||||
|
@ -60,7 +60,7 @@ public class NativeModuleRegistryBuilder {
|
||||
NativeModule module;
|
||||
ReactMarker.logMarker(
|
||||
ReactMarkerConstants.CREATE_MODULE_START,
|
||||
moduleSpec.getType().getName());
|
||||
moduleSpec.getClassName());
|
||||
try {
|
||||
module = moduleSpec.getProvider().get();
|
||||
} finally {
|
||||
|
Loading…
x
Reference in New Issue
Block a user