mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add C++ header for default TurboModules and cross-platform reuse (#44361)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44361 In order to keep all platforms in sync (Android, iOS, Windows, etc.), it makes sense to consolidate all C++ TurboModules that we want available by default on all platforms to a shared C++ header / implementation. This moves the duplicated code from Android and iOS to such a shared module provider and updates relevant build specs. ## Changelog [Internal] Reviewed By: christophpurrer Differential Revision: D56835783 fbshipit-source-id: 7322ed054ded5749973885c63257e5caf23b3fc3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0383669a4b
commit
67bc65df85
@@ -30,9 +30,7 @@
|
||||
#else
|
||||
#import <ReactCommon/RCTJscInstance.h>
|
||||
#endif
|
||||
#import <react/nativemodule/dom/NativeDOM.h>
|
||||
#import <react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h>
|
||||
#import <react/nativemodule/microtasks/NativeMicrotasks.h>
|
||||
#import <react/nativemodule/defaults/DefaultTurboModules.h>
|
||||
|
||||
@interface RCTAppDelegate () <RCTComponentViewFactoryComponentProvider>
|
||||
@end
|
||||
@@ -212,19 +210,7 @@
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
||||
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
if (name == facebook::react::NativeReactNativeFeatureFlags::kModuleName) {
|
||||
return std::make_shared<facebook::react::NativeReactNativeFeatureFlags>(jsInvoker);
|
||||
}
|
||||
|
||||
if (name == facebook::react::NativeMicrotasks::kModuleName) {
|
||||
return std::make_shared<facebook::react::NativeMicrotasks>(jsInvoker);
|
||||
}
|
||||
|
||||
if (name == facebook::react::NativeDOM::kModuleName) {
|
||||
return std::make_shared<facebook::react::NativeDOM>(jsInvoker);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return facebook::react::DefaultTurboModules::getTurboModule(name, jsInvoker);
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
||||
|
||||
@@ -75,9 +75,7 @@ Pod::Spec.new do |s|
|
||||
s.dependency "React-CoreModules"
|
||||
s.dependency "React-nativeconfig"
|
||||
s.dependency "ReactCodegen"
|
||||
s.dependency "React-domnativemodule"
|
||||
s.dependency "React-featureflagsnativemodule"
|
||||
s.dependency "React-microtasksnativemodule"
|
||||
s.dependency "React-defaultsnativemodule"
|
||||
|
||||
add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"])
|
||||
add_dependency(s, "React-NativeModulesApple")
|
||||
|
||||
@@ -106,6 +106,7 @@ add_react_common_subdir(react/utils)
|
||||
add_react_common_subdir(react/bridging)
|
||||
add_react_common_subdir(react/renderer/mapbuffer)
|
||||
add_react_common_subdir(react/nativemodule/core)
|
||||
add_react_common_subdir(react/nativemodule/defaults)
|
||||
add_react_common_subdir(react/nativemodule/dom)
|
||||
add_react_common_subdir(react/nativemodule/featureflags)
|
||||
add_react_common_subdir(react/nativemodule/microtasks)
|
||||
|
||||
@@ -21,6 +21,7 @@ target_link_libraries(react_newarchdefaults
|
||||
react_nativemodule_core
|
||||
react_codegen_rncore
|
||||
react_cxxreactpackage
|
||||
react_nativemodule_defaults
|
||||
react_nativemodule_dom
|
||||
react_nativemodule_featureflags
|
||||
react_nativemodule_microtasks
|
||||
|
||||
+2
-16
@@ -9,9 +9,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <react/nativemodule/dom/NativeDOM.h>
|
||||
#include <react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h>
|
||||
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
|
||||
#include <react/nativemodule/defaults/DefaultTurboModules.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
@@ -75,19 +73,7 @@ std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule(
|
||||
}
|
||||
}
|
||||
|
||||
if (name == NativeReactNativeFeatureFlags::kModuleName) {
|
||||
return std::make_shared<NativeReactNativeFeatureFlags>(jsInvoker);
|
||||
}
|
||||
|
||||
if (name == NativeMicrotasks::kModuleName) {
|
||||
return std::make_shared<NativeMicrotasks>(jsInvoker);
|
||||
}
|
||||
|
||||
if (name == NativeDOM::kModuleName) {
|
||||
return std::make_shared<NativeDOM>(jsInvoker);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return DefaultTurboModules::getTurboModule(name, jsInvoker);
|
||||
}
|
||||
|
||||
std::shared_ptr<TurboModule> DefaultTurboModuleManagerDelegate::getTurboModule(
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# 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++20
|
||||
-Wall
|
||||
-Wpedantic
|
||||
-DLOG_TAG=\"ReactNative\")
|
||||
|
||||
file(GLOB react_nativemodule_defaults_SRC CONFIGURE_DEPENDS *.cpp)
|
||||
add_library(react_nativemodule_defaults SHARED ${react_nativemodule_defaults_SRC})
|
||||
|
||||
target_include_directories(react_nativemodule_defaults PUBLIC ${REACT_COMMON_DIR})
|
||||
|
||||
target_link_libraries(react_nativemodule_defaults
|
||||
react_nativemodule_dom
|
||||
react_nativemodule_featureflags
|
||||
react_nativemodule_microtasks
|
||||
)
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 "DefaultTurboModules.h"
|
||||
#include <react/nativemodule/dom/NativeDOM.h>
|
||||
#include <react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h>
|
||||
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
/* static */ std::shared_ptr<TurboModule> DefaultTurboModules::getTurboModule(
|
||||
const std::string& name,
|
||||
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
||||
if (name == NativeReactNativeFeatureFlags::kModuleName) {
|
||||
return std::make_shared<NativeReactNativeFeatureFlags>(jsInvoker);
|
||||
}
|
||||
|
||||
if (name == NativeMicrotasks::kModuleName) {
|
||||
return std::make_shared<NativeMicrotasks>(jsInvoker);
|
||||
}
|
||||
|
||||
if (name == NativeDOM::kModuleName) {
|
||||
return std::make_shared<NativeDOM>(jsInvoker);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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 <react/nativemodule/dom/NativeDOM.h>
|
||||
#include <react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h>
|
||||
#include <react/nativemodule/microtasks/NativeMicrotasks.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
struct DefaultTurboModules {
|
||||
static std::shared_ptr<TurboModule> getTurboModule(
|
||||
const std::string& name,
|
||||
const std::shared_ptr<CallInvoker>& jsInvoker);
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
# 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.
|
||||
|
||||
require "json"
|
||||
|
||||
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "..", "..", "package.json")))
|
||||
version = package['version']
|
||||
|
||||
source = { :git => 'https://github.com/facebook/react-native.git' }
|
||||
if version == '1000.0.0'
|
||||
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in.
|
||||
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1")
|
||||
else
|
||||
source[:tag] = "v#{version}"
|
||||
end
|
||||
|
||||
header_search_paths = []
|
||||
|
||||
if ENV['USE_FRAMEWORKS']
|
||||
header_search_paths << "\"$(PODS_TARGET_SRCROOT)/../../..\"" # this is needed to allow the defaultsnativemodule to access its own files
|
||||
end
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "React-defaultsnativemodule"
|
||||
s.version = version
|
||||
s.summary = "React Native Default native modules"
|
||||
s.homepage = "https://reactnative.dev/"
|
||||
s.license = package["license"]
|
||||
s.author = "Meta Platforms, Inc. and its affiliates"
|
||||
s.platforms = min_supported_versions
|
||||
s.source = source
|
||||
s.source_files = "*.{cpp,h}"
|
||||
s.header_dir = "react/nativemodule/defaults"
|
||||
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
|
||||
"HEADER_SEARCH_PATHS" => header_search_paths.join(' '),
|
||||
"DEFINES_MODULE" => "YES" }
|
||||
|
||||
if ENV['USE_FRAMEWORKS']
|
||||
s.module_name = "React_defaultsnativemodule"
|
||||
s.header_mappings_dir = "../.."
|
||||
end
|
||||
|
||||
install_modules_dependencies(s)
|
||||
|
||||
s.dependency "React-domnativemodule"
|
||||
s.dependency "React-featureflagsnativemodule"
|
||||
s.dependency "React-microtasksnativemodule"
|
||||
end
|
||||
@@ -123,6 +123,7 @@ def use_react_native! (
|
||||
pod 'React-featureflagsnativemodule', :path => "#{prefix}/ReactCommon/react/nativemodule/featureflags"
|
||||
pod 'React-microtasksnativemodule', :path => "#{prefix}/ReactCommon/react/nativemodule/microtasks"
|
||||
pod 'React-domnativemodule', :path => "#{prefix}/ReactCommon/react/nativemodule/dom"
|
||||
pod 'React-defaultsnativemodule', :path => "#{prefix}/ReactCommon/react/nativemodule/defaults"
|
||||
pod 'React-Mapbuffer', :path => "#{prefix}/ReactCommon"
|
||||
pod 'React-jserrorhandler', :path => "#{prefix}/ReactCommon/jserrorhandler"
|
||||
pod 'React-nativeconfig', :path => "#{prefix}/ReactCommon"
|
||||
|
||||
Reference in New Issue
Block a user