-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for TurboModule (#843)
Note that this change requires some adjustments to your `build.gradle`: ```diff diff --git a/example/android/build.gradle b/example/android/build.gradle index 0c6c69d..2ed70f1 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,6 +1,7 @@ buildscript { def androidTestAppDir = "../node_modules/react-native-test-app/android" apply(from: "${androidTestAppDir}/dependencies.gradle") + apply(from: "${androidTestAppDir}/test-app-util.gradle") repositories { mavenCentral() @@ -8,8 +9,12 @@ buildscript { } dependencies { - classpath "com.android.tools.build:gradle:$androidPluginVersion" - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" + classpath("com.android.tools.build:gradle:${androidPluginVersion}") + + if (isNewArchitectureEnabled(project)) { + classpath("com.facebook.react:react-native-gradle-plugin") + classpath("de.undercouch:gradle-download-task:5.1.0") + } } } ``` If you're seeing build issues with `newArchEnabled=true`, please see https://github.com/microsoft/react-native-test-app/wiki/Troubleshooting.
- Loading branch information
Showing
38 changed files
with
874 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,4 +53,4 @@ DEPENDENCIES | |
xcodeproj! | ||
|
||
BUNDLED WITH | ||
2.2.22 | ||
2.3.11 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
THIS_DIR := $(call my-dir) | ||
|
||
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk | ||
|
||
# If you wish to add a custom TurboModule or Fabric component in your app you | ||
# will have to include the following autogenerated makefile. | ||
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk | ||
|
||
# Makefile for autolinked libraries | ||
include $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/Android-rncli.mk | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_PATH := $(THIS_DIR) | ||
|
||
# You can customize the name of your application .so file here. | ||
LOCAL_MODULE := reacttestapp_appmodules | ||
|
||
LOCAL_C_INCLUDES := $(LOCAL_PATH) | ||
LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | ||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) | ||
|
||
# If you wish to add a custom TurboModule or Fabric component in your app you | ||
# will have to uncomment those lines to include the generated source | ||
# files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) | ||
# | ||
# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni | ||
# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) | ||
# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni | ||
|
||
# Autolinked TurboModules and Fabric components | ||
LOCAL_C_INCLUDES += $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni | ||
LOCAL_SRC_FILES += $(wildcard $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni/*.cpp) | ||
LOCAL_EXPORT_C_INCLUDES += $(PROJECT_BUILD_DIR)/generated/rncli/src/main/jni | ||
|
||
# Here you should add any native library you wish to depend on. | ||
LOCAL_SHARED_LIBRARIES := \ | ||
libfabricjni \ | ||
libfbjni \ | ||
libfolly_runtime \ | ||
libglog \ | ||
libjsi \ | ||
libreact_codegen_rncore \ | ||
libreact_debug \ | ||
libreact_nativemodule_core \ | ||
libreact_render_componentregistry \ | ||
libreact_render_core \ | ||
libreact_render_debug \ | ||
libreact_render_graphics \ | ||
librrc_view \ | ||
libruntimeexecutor \ | ||
libturbomodulejsijni \ | ||
libyoga \ | ||
$(call import-codegen-modules) | ||
|
||
LOCAL_CFLAGS := -std=c++17 -Wall -frtti -fexceptions -DLOG_TAG=\"ReactNative\" | ||
|
||
include $(BUILD_SHARED_LIBRARY) |
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,55 @@ | ||
#include "ComponentsRegistry.h" | ||
|
||
#include <CoreComponentsRegistry.h> | ||
#include <rncli.h> | ||
|
||
#include <fbjni/fbjni.h> | ||
|
||
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h> | ||
#include <react/renderer/componentregistry/ComponentDescriptorRegistry.h> | ||
#include <react/renderer/components/rncore/ComponentDescriptors.h> | ||
|
||
using facebook::react::ComponentDescriptorParameters; | ||
using facebook::react::ComponentDescriptorProviderRegistry; | ||
using facebook::react::ComponentDescriptorRegistry; | ||
using facebook::react::ComponentFactory; | ||
using facebook::react::ContextContainer; | ||
using facebook::react::CoreComponentsRegistry; | ||
using facebook::react::EventDispatcher; | ||
using facebook::react::UnimplementedNativeViewComponentDescriptor; | ||
using ReactTestApp::ComponentsRegistry; | ||
|
||
void ComponentsRegistry::registerNatives() | ||
{ | ||
registerHybrid({makeNativeMethod("initHybrid", ComponentsRegistry::initHybrid)}); | ||
} | ||
|
||
ComponentsRegistry::ComponentsRegistry(ComponentFactory *) | ||
{ | ||
} | ||
|
||
facebook::jni::local_ref<ComponentsRegistry::jhybriddata> | ||
ComponentsRegistry::initHybrid(facebook::jni::alias_ref<jclass>, ComponentFactory *delegate) | ||
{ | ||
delegate->buildRegistryFunction = [](EventDispatcher::Weak const &eventDispatcher, | ||
ContextContainer::Shared const &contextContainer) | ||
-> ComponentDescriptorRegistry::Shared { | ||
auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); | ||
|
||
// Register providers generated by `@react-native-community/cli` | ||
rncli_registerProviders(providerRegistry); | ||
|
||
auto registry = providerRegistry->createComponentDescriptorRegistry( | ||
{eventDispatcher, contextContainer}); | ||
|
||
auto mutableRegistry = std::const_pointer_cast<ComponentDescriptorRegistry>(registry); | ||
|
||
mutableRegistry->setFallbackComponentDescriptor( | ||
std::make_shared<UnimplementedNativeViewComponentDescriptor>( | ||
ComponentDescriptorParameters{eventDispatcher, contextContainer, nullptr})); | ||
|
||
return registry; | ||
}; | ||
|
||
return makeCxxInstance(delegate); | ||
} |
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,26 @@ | ||
#ifndef REACTTESTAPP_JNI_COMPONENTSREGISTRY_H_ | ||
#define REACTTESTAPP_JNI_COMPONENTSREGISTRY_H_ | ||
|
||
#include <ComponentFactory.h> | ||
|
||
#include <fbjni/fbjni.h> | ||
|
||
namespace ReactTestApp | ||
{ | ||
class ComponentsRegistry : public facebook::jni::HybridClass<ComponentsRegistry> | ||
{ | ||
public: | ||
constexpr static auto kJavaDescriptor = | ||
"Lcom/microsoft/reacttestapp/fabric/ComponentsRegistry;"; | ||
|
||
static void registerNatives(); | ||
|
||
ComponentsRegistry(facebook::react::ComponentFactory *delegate); | ||
|
||
private: | ||
static facebook::jni::local_ref<ComponentsRegistry::jhybriddata> | ||
initHybrid(facebook::jni::alias_ref<jclass>, facebook::react::ComponentFactory *delegate); | ||
}; | ||
} // namespace ReactTestApp | ||
|
||
#endif // REACTTESTAPP_JNI_COMPONENTSREGISTRY_H_ |
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,15 @@ | ||
#include <fbjni/fbjni.h> | ||
|
||
#include "ComponentsRegistry.h" | ||
#include "TurboModuleManagerDelegate.h" | ||
|
||
using ReactTestApp::ComponentsRegistry; | ||
using ReactTestApp::TurboModuleManagerDelegate; | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) | ||
{ | ||
return facebook::jni::initialize(vm, [] { | ||
TurboModuleManagerDelegate::registerNatives(); | ||
ComponentsRegistry::registerNatives(); | ||
}); | ||
} |
Oops, something went wrong.