mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
TurboModule Android: allow RNTester to activate TurboModule system
Summary:
If built with `USE_CODEGEN=1` flag set, RNTester now activates the TurboModule system, also using various codegen output from the previous commits.
Note that this is very early integration, and not thoroughly tested yet.
To verify:
```
console.warn('TM enabled?', global.__turboModuleProxy != null);
```
{F337454276}
Changelog: [Internal]
Reviewed By: yungsters
Differential Revision: D23946944
fbshipit-source-id: 5838aeb9ded07b1cc0fcb069535d1c6fb3725973
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9dbab5fb7b
commit
8d4b5efac7
@@ -154,6 +154,7 @@ android {
|
||||
testBuildType System.getProperty('testBuildType', 'debug') // This will later be used to control the test apk build type
|
||||
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
|
||||
buildConfigField("boolean", "ENABLE_FABRIC", "$enableFabric")
|
||||
buildConfigField("boolean", "ENABLE_TURBOMODULE", "$enableCodegen") // If using codegen, assume using TurboModule
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
|
||||
+1
-3
@@ -7,8 +7,6 @@
|
||||
|
||||
package com.facebook.react.uiapp;
|
||||
|
||||
import static com.facebook.react.uiapp.RNTesterApplication.IS_FABRIC_ENABLED;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -31,7 +29,7 @@ public class RNTesterActivity extends ReactActivity {
|
||||
@Override
|
||||
protected ReactRootView createRootView() {
|
||||
ReactRootView reactRootView = new ReactRootView(getContext());
|
||||
reactRootView.setIsFabric(IS_FABRIC_ENABLED);
|
||||
reactRootView.setIsFabric(BuildConfig.ENABLE_FABRIC);
|
||||
return reactRootView;
|
||||
}
|
||||
|
||||
|
||||
+77
-40
@@ -7,16 +7,14 @@
|
||||
|
||||
package com.facebook.react.uiapp;
|
||||
|
||||
import static com.facebook.react.uiapp.BuildConfig.ENABLE_FABRIC;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.BuildConfig;
|
||||
import com.facebook.react.ReactApplication;
|
||||
import com.facebook.react.ReactInstanceManager;
|
||||
import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.bridge.JSIModule;
|
||||
import com.facebook.react.bridge.JSIModulePackage;
|
||||
import com.facebook.react.bridge.JSIModuleProvider;
|
||||
import com.facebook.react.bridge.JSIModuleSpec;
|
||||
@@ -24,11 +22,13 @@ import com.facebook.react.bridge.JSIModuleType;
|
||||
import com.facebook.react.bridge.JavaScriptContextHolder;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
import com.facebook.react.bridge.UIManager;
|
||||
import com.facebook.react.config.ReactFeatureFlags;
|
||||
import com.facebook.react.fabric.ComponentFactory;
|
||||
import com.facebook.react.fabric.CoreComponentsRegistry;
|
||||
import com.facebook.react.fabric.FabricJSIModuleProvider;
|
||||
import com.facebook.react.fabric.ReactNativeConfig;
|
||||
import com.facebook.react.shell.MainReactPackage;
|
||||
import com.facebook.react.turbomodule.core.TurboModuleManager;
|
||||
import com.facebook.react.views.text.ReactFontManager;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -38,8 +38,6 @@ import java.util.List;
|
||||
|
||||
public class RNTesterApplication extends Application implements ReactApplication {
|
||||
|
||||
static final boolean IS_FABRIC_ENABLED = ENABLE_FABRIC;
|
||||
|
||||
private final ReactNativeHost mReactNativeHost =
|
||||
new ReactNativeHost(this) {
|
||||
@Override
|
||||
@@ -65,7 +63,7 @@ public class RNTesterApplication extends Application implements ReactApplication
|
||||
@Nullable
|
||||
@Override
|
||||
protected JSIModulePackage getJSIModulePackage() {
|
||||
if (!IS_FABRIC_ENABLED) {
|
||||
if (!BuildConfig.ENABLE_FABRIC && !ReactFeatureFlags.useTurboModules) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -75,44 +73,81 @@ public class RNTesterApplication extends Application implements ReactApplication
|
||||
final ReactApplicationContext reactApplicationContext,
|
||||
final JavaScriptContextHolder jsContext) {
|
||||
List<JSIModuleSpec> specs = new ArrayList<>();
|
||||
specs.add(
|
||||
new JSIModuleSpec() {
|
||||
@Override
|
||||
public JSIModuleType getJSIModuleType() {
|
||||
return JSIModuleType.UIManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSIModuleProvider<UIManager> getJSIModuleProvider() {
|
||||
ComponentFactory ComponentFactory = new ComponentFactory();
|
||||
CoreComponentsRegistry.register(ComponentFactory);
|
||||
return new FabricJSIModuleProvider(
|
||||
reactApplicationContext,
|
||||
ComponentFactory,
|
||||
// TODO: T71362667 add ReactNativeConfig's support in RNTester
|
||||
new ReactNativeConfig() {
|
||||
@Override
|
||||
public boolean getBool(String s) {
|
||||
return true;
|
||||
}
|
||||
// Install the new native module system.
|
||||
if (ReactFeatureFlags.useTurboModules) {
|
||||
specs.add(
|
||||
new JSIModuleSpec() {
|
||||
@Override
|
||||
public JSIModuleType getJSIModuleType() {
|
||||
return JSIModuleType.TurboModuleManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt64(String s) {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public JSIModuleProvider getJSIModuleProvider() {
|
||||
return new JSIModuleProvider() {
|
||||
@Override
|
||||
public JSIModule get() {
|
||||
ReactInstanceManager reactInstanceManager = getReactInstanceManager();
|
||||
List<ReactPackage> packages = reactInstanceManager.getPackages();
|
||||
|
||||
@Override
|
||||
public String getString(String s) {
|
||||
return "";
|
||||
}
|
||||
return new TurboModuleManager(
|
||||
jsContext,
|
||||
new RNTesterTurboModuleManagerDelegate(
|
||||
reactApplicationContext, packages),
|
||||
reactApplicationContext
|
||||
.getCatalystInstance()
|
||||
.getJSCallInvokerHolder(),
|
||||
reactApplicationContext
|
||||
.getCatalystInstance()
|
||||
.getNativeCallInvokerHolder());
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(String s) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// Install the new renderer.
|
||||
if (BuildConfig.ENABLE_FABRIC) {
|
||||
specs.add(
|
||||
new JSIModuleSpec() {
|
||||
@Override
|
||||
public JSIModuleType getJSIModuleType() {
|
||||
return JSIModuleType.UIManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSIModuleProvider<UIManager> getJSIModuleProvider() {
|
||||
ComponentFactory ComponentFactory = new ComponentFactory();
|
||||
CoreComponentsRegistry.register(ComponentFactory);
|
||||
return new FabricJSIModuleProvider(
|
||||
reactApplicationContext,
|
||||
ComponentFactory,
|
||||
// TODO: T71362667 add ReactNativeConfig's support in RNTester
|
||||
new ReactNativeConfig() {
|
||||
@Override
|
||||
public boolean getBool(String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt64(String s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(String s) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDouble(String s) {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return specs;
|
||||
}
|
||||
@@ -122,6 +157,8 @@ public class RNTesterApplication extends Application implements ReactApplication
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// Set `USE_CODEGEN` env var when building RNTester to enable TurboModule.
|
||||
ReactFeatureFlags.useTurboModules = BuildConfig.ENABLE_TURBOMODULE;
|
||||
ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik);
|
||||
super.onCreate();
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
|
||||
@@ -18,6 +18,54 @@ std::shared_ptr<TurboModule> RNTesterAppModuleProvider(const std::string moduleN
|
||||
if (module != nullptr) {
|
||||
return module;
|
||||
}
|
||||
|
||||
// TODO: fix up the ReactAndroidSpec_ModuleProvider() to avoid the Android prefix.
|
||||
if (moduleName == "DatePicker") {
|
||||
return std::make_shared<NativeDatePickerAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "DialogManager") {
|
||||
return std::make_shared<NativeDialogManagerAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "ImageLoader") {
|
||||
return std::make_shared<NativeImageLoaderAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "Networking") {
|
||||
return std::make_shared<NativeNetworkingAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "Permissions") {
|
||||
return std::make_shared<NativePermissionsAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "PlatformConstants") {
|
||||
return std::make_shared<NativePlatformConstantsAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "StatusBarManager") {
|
||||
return std::make_shared<NativeStatusBarManagerAndroidSpecJSI>(params);
|
||||
}
|
||||
if (moduleName == "Toast") {
|
||||
return std::make_shared<NativeToastAndroidSpecJSI>(params);
|
||||
}
|
||||
|
||||
// TODO: handle some special case naming.
|
||||
if (moduleName == "IntentAndroid") {
|
||||
return std::make_shared<NativeLinkingSpecJSI>(params);
|
||||
}
|
||||
|
||||
// TODO: Animated module has special cases.
|
||||
if ("NativeAnimatedModule" == moduleName) {
|
||||
return std::make_shared<NativeAnimatedModuleSpecJSI>(params);
|
||||
}
|
||||
if ("NativeAnimatedTurboModule" == moduleName) {
|
||||
return std::make_shared<NativeAnimatedTurboModuleSpecJSI>(params);
|
||||
}
|
||||
|
||||
// TODO: handle multiple names for one spec.
|
||||
if ("AsyncLocalStorage" == moduleName) {
|
||||
return std::make_shared<NativeAsyncStorageSpecJSI>(params);
|
||||
}
|
||||
if ("AsyncSQLiteDBStorage" == moduleName) {
|
||||
return std::make_shared<NativeAsyncStorageSpecJSI>(params);
|
||||
}
|
||||
|
||||
return ReactAndroidSpec_ModuleProvider(moduleName, params);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user