Add a way to selectively enable TurboModules

Summary:
Added a flag that checks if TurboModules are enabled, don't expose them to JS via the old module system.
All TurboModules needs to implement TurboModule interface.

Reviewed By: mdvacca

Differential Revision: D13648332

fbshipit-source-id: f22506fe029ac82d56075f5b6962ff2df2e7eaa4
This commit is contained in:
Ram N
2019-01-16 19:19:53 -08:00
committed by Facebook Github Bot
parent c93edb5ffd
commit aa19fa02e9
8 changed files with 58 additions and 4 deletions
@@ -8,6 +8,7 @@ package com.facebook.react;
import com.facebook.react.bridge.ModuleHolder;
import com.facebook.react.bridge.NativeModuleRegistry;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.config.ReactFeatureFlags;
import java.util.HashMap;
import java.util.Map;
@@ -55,6 +56,17 @@ public class NativeModuleRegistryBuilder {
}
mModules.remove(existingNativeModule);
}
if (ReactFeatureFlags.useTurboModules && moduleHolder.isTurboModule()) {
// If this module is a TurboModule, and if TurboModules are enabled, don't add this module
// This condition is after checking for overrides, since if there is already a module,
// and we want to override it with a turbo module, we would need to remove the modules thats
// already in the list, and then NOT add the new module, since that will be directly exposed
// Note that is someone uses {@link NativeModuleRegistry#registerModules}, we will NOT check
// for TurboModules - assuming that people wanted to explicitly register native modules there
continue;
}
mModules.put(name, moduleHolder);
}
}