-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
90e7f51
commit e89bd4a
Showing
19 changed files
with
245 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNativeEntryPoint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
ReactAndroid/src/main/jni/react/newarchdefaults/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 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. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
|
||
add_compile_options(-fexceptions -frtti -std=c++17 -Wall -DLOG_TAG=\"ReactNative\") | ||
|
||
file(GLOB react_newarchdefaults_SRC CONFIGURE_DEPENDS *.cpp) | ||
|
||
add_library(react_newarchdefaults SHARED ${react_newarchdefaults_SRC}) | ||
|
||
target_include_directories(react_newarchdefaults PUBLIC .) | ||
|
||
target_link_libraries(react_newarchdefaults | ||
fbjni | ||
fabricjni | ||
react_nativemodule_core | ||
react_codegen_rncore | ||
jsi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
ReactAndroid/src/main/jni/react/newarchdefaults/DefaultTurboModuleManagerDelegate.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "DefaultTurboModuleManagerDelegate.h" | ||
|
||
#include <rncore.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
std::function<std::shared_ptr<TurboModule>( | ||
const std::string &, | ||
const JavaTurboModule::InitParams &)> | ||
DefaultTurboModuleManagerDelegate::moduleProvidersFromEntryPoint{nullptr}; | ||
|
||
jni::local_ref<DefaultTurboModuleManagerDelegate::jhybriddata> | ||
DefaultTurboModuleManagerDelegate::initHybrid(jni::alias_ref<jhybridobject>) { | ||
return makeCxxInstance(); | ||
} | ||
|
||
void DefaultTurboModuleManagerDelegate::registerNatives() { | ||
registerHybrid({ | ||
makeNativeMethod( | ||
"initHybrid", DefaultTurboModuleManagerDelegate::initHybrid), | ||
}); | ||
} | ||
|
||
std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule( | ||
const std::string &name, | ||
const std::shared_ptr<CallInvoker> &jsInvoker) { | ||
// Not implemented yet: provide pure-C++ NativeModules here. | ||
return nullptr; | ||
} | ||
|
||
std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule( | ||
const std::string &name, | ||
const JavaTurboModule::InitParams ¶ms) { | ||
auto resolvedModule = (DefaultTurboModuleManagerDelegate:: | ||
moduleProvidersFromEntryPoint)(name, params); | ||
if (resolvedModule != nullptr) { | ||
return resolvedModule; | ||
} | ||
return rncore_ModuleProvider(name, params); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
ReactAndroid/src/main/jni/react/newarchdefaults/OnLoad.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include <fbjni/fbjni.h> | ||
|
||
#include "DefaultComponentsRegistry.h" | ||
#include "DefaultTurboModuleManagerDelegate.h" | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
facebook::react::DefaultTurboModuleManagerDelegate::registerNatives(); | ||
facebook::react::DefaultComponentsRegistry::registerNatives(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.