mirror of
https://github.com/status-im/react-native.git
synced 2025-01-25 00:39:03 +00:00
Allow lazy Cxx modules to not initialize
Reviewed By: mhorowitz Differential Revision: D4851596 fbshipit-source-id: cf5f5c51b9aaa0da96f7ab6fba1277b72c988400
This commit is contained in:
parent
e67b8fe761
commit
f3dfd616f4
@ -46,12 +46,6 @@ std::vector<std::unique_ptr<NativeModule>> createNativeModules(NSArray<RCTModule
|
||||
std::vector<std::unique_ptr<NativeModule>> nativeModules;
|
||||
for (RCTModuleData *moduleData in modules) {
|
||||
if ([moduleData.moduleClass isSubclassOfClass:[RCTCxxModule class]]) {
|
||||
// If a module does not support automatic instantiation, and
|
||||
// wasn't provided as an extra module, it may not have an
|
||||
// instance. If so, skip it.
|
||||
if (![moduleData hasInstance]) {
|
||||
continue;
|
||||
}
|
||||
nativeModules.emplace_back(std::make_unique<CxxNativeModule>(
|
||||
instance,
|
||||
[moduleData.name UTF8String],
|
||||
|
@ -64,6 +64,10 @@ std::vector<MethodDescriptor> CxxNativeModule::getMethods() {
|
||||
folly::dynamic CxxNativeModule::getConstants() {
|
||||
lazyInit();
|
||||
|
||||
if (!module_) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
folly::dynamic constants = folly::dynamic::object();
|
||||
for (auto& pair : module_->getConstants()) {
|
||||
constants.insert(std::move(pair.first), std::move(pair.second));
|
||||
@ -161,13 +165,17 @@ MethodCallResult CxxNativeModule::callSerializableNativeHook(
|
||||
}
|
||||
|
||||
void CxxNativeModule::lazyInit() {
|
||||
if (module_) {
|
||||
if (module_ || !provider_) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO 17216751: providers should never return null modules
|
||||
module_ = provider_();
|
||||
methods_ = module_->getMethods();
|
||||
module_->setInstance(instance_);
|
||||
provider_ = nullptr;
|
||||
if (module_) {
|
||||
methods_ = module_->getMethods();
|
||||
module_->setInstance(instance_);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ folly::Optional<ModuleConfig> ModuleRegistry::getConfig(const std::string& name)
|
||||
}
|
||||
}
|
||||
|
||||
if (config.size() == 1) {
|
||||
if (config.size() == 2 && config[1].empty()) {
|
||||
// no constants or methods
|
||||
return nullptr;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user