diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate+Protected.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate+Protected.h new file mode 100644 index 000000000000..e74c9c8b4320 --- /dev/null +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate+Protected.h @@ -0,0 +1,12 @@ +/* + * 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. + */ + +#import +#import "RCTAppDelegate.h" + +@interface RCTAppDelegate () +@end diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index a53a42303d7d..702c4ab2888a 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -12,6 +12,7 @@ #import #import #import +#import "RCTAppDelegate+Protected.h" #import "RCTAppSetupUtils.h" #if RN_DISABLE_OSS_PLUGIN_HEADER @@ -35,14 +36,12 @@ #import #import #import +#import #import #import #import -@interface RCTAppDelegate () < - RCTTurboModuleManagerDelegate, - RCTComponentViewFactoryComponentProvider, - RCTContextContainerHandling> { +@interface RCTAppDelegate () { std::shared_ptr _reactNativeConfig; facebook::react::ContextContainer::Shared _contextContainer; } @@ -273,6 +272,10 @@ - (Class)getModuleClassFromName:(const char *)name - (std::shared_ptr)getTurboModule:(const std::string &)name jsInvoker:(std::shared_ptr)jsInvoker { + if (name == facebook::react::NativeReactNativeFeatureFlags::kModuleName) { + return std::make_shared(jsInvoker); + } + return nullptr; } diff --git a/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec b/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec index bb919f23b91d..4ddc800c2d7d 100644 --- a/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec +++ b/packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec @@ -77,6 +77,7 @@ Pod::Spec.new do |s| s.dependency "React-CoreModules" s.dependency "React-nativeconfig" s.dependency "ReactCodegen" + s.dependency "React-featureflagsnativemodule" add_dependency(s, "ReactCommon", :subspec => "turbomodule/core", :additional_framework_paths => ["react/nativemodule/core"]) add_dependency(s, "React-NativeModulesApple") diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index dac5ad3f417f..33f7fcfa6878 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<26be12cc19ed1a9cd2dbdab684594204>> */ /** @@ -21,6 +21,8 @@ #if __has_include("rncoreJSI.h") // Cmake headers on Android #include "rncoreJSI.h" +#elif __has_include("FBReactNativeSpecJSI.h") // CocoaPod headers on Apple +#include "FBReactNativeSpecJSI.h" #else #include #endif diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec b/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec new file mode 100644 index 000000000000..5edea69a167c --- /dev/null +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/React-featureflagsnativemodule.podspec @@ -0,0 +1,48 @@ +# 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 feature flags access its own files +end + +Pod::Spec.new do |s| + s.name = "React-featureflagsnativemodule" + s.version = version + s.summary = "React Native internal feature flags" + 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/featureflags" + 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_featureflagsnativemodule" + s.header_mappings_dir = "../.." + end + + install_modules_dependencies(s) + + s.dependency "ReactCommon/turbomodule/core" +end diff --git a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js index 06d30348cd35..6bc09d3ffd3a 100644 --- a/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js +++ b/packages/react-native/scripts/featureflags/templates/js/NativeReactNativeFeatureFlags.h-template.js @@ -29,6 +29,8 @@ ${DO_NOT_MODIFY_COMMENT} #if __has_include("rncoreJSI.h") // Cmake headers on Android #include "rncoreJSI.h" +#elif __has_include("FBReactNativeSpecJSI.h") // CocoaPod headers on Apple +#include "FBReactNativeSpecJSI.h" #else #include #endif diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index 7752d48f4259..6c13f048bfee 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -125,6 +125,7 @@ def use_react_native! ( pod 'React-debug', :path => "#{prefix}/ReactCommon/react/debug" pod 'React-utils', :path => "#{prefix}/ReactCommon/react/utils" pod 'React-featureflags', :path => "#{prefix}/ReactCommon/react/featureflags" + pod 'React-featureflagsnativemodule', :path => "#{prefix}/ReactCommon/react/nativemodule/featureflags" pod 'React-Mapbuffer', :path => "#{prefix}/ReactCommon" pod 'React-jserrorhandler', :path => "#{prefix}/ReactCommon/jserrorhandler" pod 'React-nativeconfig', :path => "#{prefix}/ReactCommon" diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index fcb6360c7242..eacc13101b2c 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -9,10 +9,12 @@ #import +#import #import #import #import #import +#import #import #import @@ -83,10 +85,12 @@ - (void)loadSourceForBridge:(RCTBridge *)bridge if (name == std::string([@"SampleTurboCxxModule" UTF8String])) { return std::make_shared(jsInvoker); } + if (name == facebook::react::NativeCxxModuleExample::kModuleName) { return std::make_shared(jsInvoker); } - return nullptr; + + return [super getTurboModule:name jsInvoker:jsInvoker]; } // Required for the remoteNotificationsRegistered event.