Reduce the amount of C++ code in user space for RN-Tester

Summary:
This diff reduces the amount of C++ code in user space by:
- Moving all the C++ implementation of the .defaults package inside a `react_newarchdefaults` shared library
- Exposing only the entrypoint logic inside the RN-Tester's `OnLoad.cpp` file.

Changelog:
[Android] [Changed] - Reduce the amount of C++ code in user space for New Architecture

Reviewed By: cipolleschi

Differential Revision: D39381820

fbshipit-source-id: 9c4b5596b67b5a7ee58824319c80e325348ed06c
This commit is contained in:
Nicola Corti
2022-09-12 12:48:43 -07:00
committed by Facebook GitHub Bot
parent 90e7f510dc
commit e89bd4a375
19 changed files with 245 additions and 132 deletions
@@ -15,9 +15,8 @@ import com.facebook.react.fabric.ComponentFactory
* A utility class that provides users a ComponentRegistry they can customize with a C++
* implementation of its native methods.
*
* Please note that you need to provide a native implementation for the method initHybrid for this
* class, making sure the Java Descriptor is:
* Lcom/facebook/react/defaults/DefaultComponentsRegistry;
* This class works together with the [DefaultNativeEntryPoint] and it's C++ implementation is
* hosted inside the React Native framwork
*/
@DoNotStrip
class DefaultComponentsRegistry
@@ -0,0 +1,39 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.defaults
import com.facebook.jni.HybridData
import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.soloader.SoLoader
/**
* A utility class that serves as an entry point for users to register all the custom Fabric
* Components and Turbo Native Modules.
*
* This class needs to be invoked as `DefaultNativeEntryPoint.load("...")` by passing the name of
* the dynamic library to load.
*
* This class works together with the [DefaultNativeEntryPoint] and it's C++ implementation is
* hosted inside the React Native framework
*/
@DoNotStrip
class DefaultNativeEntryPoint @DoNotStrip private constructor() {
@DoNotStrip private val hybridData: HybridData = initHybrid()
@DoNotStrip private external fun initHybrid(): HybridData
companion object {
@JvmStatic
fun load(dynamicLibraryName: String) {
SoLoader.loadLibrary("react_newarchdefaults")
SoLoader.loadLibrary(dynamicLibraryName)
DefaultNativeEntryPoint()
}
}
}
@@ -17,9 +17,8 @@ import com.facebook.react.bridge.ReactApplicationContext
* A utility class that allows you to simplify the setup of a
* [ReactPackageTurboModuleManagerDelegate] for new apps in Open Source.
*
* Please note that you need to provide a native implementation for the method initHybrid for this
* class, making sure the Java Descriptor is:
* Lcom/facebook/react/defaults/DefaultTurboModuleManagerDelegate;
* This class works together with the [DefaultNativeEntryPoint] and it's C++ implementation is
* hosted inside the React Native framwork
*/
class DefaultTurboModuleManagerDelegate
private constructor(context: ReactApplicationContext, packages: List<ReactPackage>) :