Skip to content

Commit 3fc7627

Browse files
cipolleschifacebook-github-bot
authored andcommitted
Use runtime scheduler in the old architecture (#39057)
Summary: Pull Request resolved: #39057 ## Changelog: [iOS][Changed] - Use the runtime scheduler in the old Architecture ## Facebook Reviewed By: sammy-SC Differential Revision: D48430129 fbshipit-source-id: ea7c90e83c1adcedf8f5952f7b978cdc022d0b36
1 parent f6945cb commit 3fc7627

File tree

9 files changed

+90
-63
lines changed

9 files changed

+90
-63
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
*/
77

88
#import "RCTAppDelegate.h"
9+
#import <React/RCTCxxBridgeDelegate.h>
910
#import <React/RCTRootView.h>
11+
#import <React/RCTSurfacePresenterBridgeAdapter.h>
12+
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
1013
#import "RCTAppSetupUtils.h"
1114
#import "RCTLegacyInteropComponents.h"
1215

@@ -15,12 +18,10 @@
1518
#import <React/RCTBundleURLProvider.h>
1619
#import <React/RCTComponentViewFactory.h>
1720
#import <React/RCTComponentViewProtocol.h>
18-
#import <React/RCTCxxBridgeDelegate.h>
1921
#import <React/RCTFabricSurface.h>
2022
#import <React/RCTLegacyViewManagerInteropComponentView.h>
2123
#import <React/RCTSurfaceHostingProxyRootView.h>
2224
#import <React/RCTSurfacePresenter.h>
23-
#import <React/RCTSurfacePresenterBridgeAdapter.h>
2425
#import <ReactCommon/RCTContextContainerHandling.h>
2526
#if USE_HERMES
2627
#import <ReactCommon/RCTHermesInstance.h>
@@ -39,17 +40,20 @@
3940

4041
@interface RCTAppDelegate () <
4142
RCTTurboModuleManagerDelegate,
42-
RCTCxxBridgeDelegate,
4343
RCTComponentViewFactoryComponentProvider,
4444
RCTContextContainerHandling> {
4545
std::shared_ptr<const facebook::react::ReactNativeConfig> _reactNativeConfig;
4646
facebook::react::ContextContainer::Shared _contextContainer;
47-
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
4847
}
4948
@end
5049

5150
#endif
5251

52+
@interface RCTAppDelegate () <RCTCxxBridgeDelegate> {
53+
std::shared_ptr<facebook::react::RuntimeScheduler> _runtimeScheduler;
54+
}
55+
@end
56+
5357
@implementation RCTAppDelegate {
5458
#if RCT_NEW_ARCH_ENABLED
5559
RCTHost *_reactHost;
@@ -173,11 +177,11 @@ - (BOOL)runtimeSchedulerEnabled
173177
return YES;
174178
}
175179

176-
#if RCT_NEW_ARCH_ENABLED
177180
#pragma mark - RCTCxxBridgeDelegate
178181
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
179182
{
180183
_runtimeScheduler = std::make_shared<facebook::react::RuntimeScheduler>(RCTRuntimeExecutorFromBridge(bridge));
184+
#if RCT_NEW_ARCH_ENABLED
181185
std::shared_ptr<facebook::react::CallInvoker> callInvoker =
182186
std::make_shared<facebook::react::RuntimeSchedulerCallInvoker>(_runtimeScheduler);
183187
RCTTurboModuleManager *turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge
@@ -186,8 +190,13 @@ - (BOOL)runtimeSchedulerEnabled
186190
_contextContainer->erase("RuntimeScheduler");
187191
_contextContainer->insert("RuntimeScheduler", _runtimeScheduler);
188192
return RCTAppSetupDefaultJsExecutorFactory(bridge, turboModuleManager, _runtimeScheduler);
193+
#else
194+
return RCTAppSetupJsExecutorFactoryForOldArch(bridge, _runtimeScheduler);
195+
#endif
189196
}
190197

198+
#if RCT_NEW_ARCH_ENABLED
199+
191200
#pragma mark - RCTTurboModuleManagerDelegate
192201

193202
- (Class)getModuleClassFromName:(const char *)name

packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#ifdef __cplusplus
1313

14-
#if RCT_NEW_ARCH_ENABLED
14+
#import <memory>
1515

1616
#ifndef RCT_USE_HERMES
1717
#if __has_include(<reacthermes/HermesExecutorFactory.h>)
@@ -27,21 +27,27 @@
2727
#import <React/JSCExecutorFactory.h>
2828
#endif
2929

30+
#if RCT_NEW_ARCH_ENABLED
3031
#import <ReactCommon/RCTTurboModuleManager.h>
3132
#endif
3233

33-
#if RCT_NEW_ARCH_ENABLED
3434
// Forward declaration to decrease compilation coupling
3535
namespace facebook::react {
3636
class RuntimeScheduler;
3737
}
3838

39+
#if RCT_NEW_ARCH_ENABLED
40+
3941
RCT_EXTERN id<RCTTurboModule> RCTAppSetupDefaultModuleFromClass(Class moduleClass);
4042

4143
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupDefaultJsExecutorFactory(
4244
RCTBridge *bridge,
4345
RCTTurboModuleManager *turboModuleManager,
4446
std::shared_ptr<facebook::react::RuntimeScheduler> const &runtimeScheduler);
47+
#else
48+
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
49+
RCTBridge *bridge,
50+
std::shared_ptr<facebook::react::RuntimeScheduler> const &runtimeScheduler);
4551
#endif
4652

4753
#endif // __cplusplus

packages/react-native/Libraries/AppDelegate/RCTAppSetupUtils.mm

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
#import "RCTAppSetupUtils.h"
99

10+
#import <React/RCTJSIExecutorRuntimeInstaller.h>
11+
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
12+
#import <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
13+
1014
#if RCT_NEW_ARCH_ENABLED
1115
// Turbo Module
1216
#import <React/CoreModulesPlugins.h>
@@ -16,14 +20,11 @@
1620
#import <React/RCTGIFImageDecoder.h>
1721
#import <React/RCTHTTPRequestHandler.h>
1822
#import <React/RCTImageLoader.h>
19-
#import <React/RCTJSIExecutorRuntimeInstaller.h>
2023
#import <React/RCTNetworking.h>
2124

2225
// Fabric
2326
#import <React/RCTFabricSurface.h>
2427
#import <React/RCTSurfaceHostingProxyRootView.h>
25-
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
26-
#import <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
2728
#endif
2829

2930
#ifdef FB_SONARKIT_ENABLED
@@ -120,13 +121,13 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
120121
* NativeModule.
121122
*/
122123
[turboModuleManager moduleForName:"RCTDevMenu"];
123-
#endif
124+
#endif // end RCT_DEV
124125

125126
#if RCT_USE_HERMES
126127
return std::make_unique<facebook::react::HermesExecutorFactory>(
127128
#else
128129
return std::make_unique<facebook::react::JSCExecutorFactory>(
129-
#endif
130+
#endif // end RCT_USE_HERMES
130131
facebook::react::RCTJSIExecutorRuntimeInstaller(
131132
[turboModuleManager, bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
132133
if (!bridge || !turboModuleManager) {
@@ -139,4 +140,24 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
139140
}));
140141
}
141142

142-
#endif
143+
#else // else !RCT_NEW_ARCH_ENABLED
144+
145+
std::unique_ptr<facebook::react::JSExecutorFactory> RCTAppSetupJsExecutorFactoryForOldArch(
146+
RCTBridge *bridge,
147+
std::shared_ptr<facebook::react::RuntimeScheduler> const &runtimeScheduler)
148+
{
149+
#if RCT_USE_HERMES
150+
return std::make_unique<facebook::react::HermesExecutorFactory>(
151+
#else
152+
return std::make_unique<facebook::react::JSCExecutorFactory>(
153+
#endif // end RCT_USE_HERMES
154+
facebook::react::RCTJSIExecutorRuntimeInstaller([bridge, runtimeScheduler](facebook::jsi::Runtime &runtime) {
155+
if (!bridge) {
156+
return;
157+
}
158+
if (runtimeScheduler) {
159+
facebook::react::RuntimeSchedulerBinding::createAndInstallIfNeeded(runtime, runtimeScheduler);
160+
}
161+
}));
162+
}
163+
#endif // end RCT_NEW_ARCH_ENABLED

packages/react-native/Libraries/AppDelegate/React-RCTAppDelegate.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Pod::Spec.new do |s|
9393
s.dependency "React-CoreModules"
9494
s.dependency "React-nativeconfig"
9595
s.dependency "React-runtimescheduler"
96+
s.dependency "React-RCTFabric"
9697

9798
if is_new_arch_enabled
9899
s.dependency "React-BridgelessCore"
@@ -110,7 +111,6 @@ Pod::Spec.new do |s|
110111

111112
if is_new_arch_enabled
112113
s.dependency "React-Fabric"
113-
s.dependency "React-RCTFabric"
114114
s.dependency "React-graphics"
115115
s.dependency "React-utils"
116116
s.dependency "React-debug"

packages/react-native/scripts/cocoapods/__tests__/codegen-test.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing(
4747

4848
# Arrange
4949
FileMock.mocked_existing_files([
50-
@prefix + "/React/Fabric/" + @third_party_provider_header,
51-
@prefix + "/React/Fabric/" + @third_party_provider_implementation,
50+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
51+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_implementation,
5252
])
5353

5454
# Act
@@ -58,8 +58,8 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenFileAlreadyExists_doNothing(
5858
assert_equal(Pathname.pwd_invocation_count, 1)
5959
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
6060
assert_equal(FileMock.exist_invocation_params, [
61-
@prefix + "/React/Fabric/" + @third_party_provider_header,
62-
@prefix + "/React/Fabric/" + @third_party_provider_implementation,
61+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
62+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_implementation,
6363
])
6464
assert_equal(DirMock.exist_invocation_params, [])
6565
assert_equal(Pod::UI.collected_messages, [])
@@ -84,7 +84,7 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenHeaderMissingAndCodegenMissi
8484
assert_equal(Pathname.pwd_invocation_count, 1)
8585
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
8686
assert_equal(FileMock.exist_invocation_params, [
87-
@prefix + "/React/Fabric/" + @third_party_provider_header
87+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header
8888
])
8989
assert_equal(DirMock.exist_invocation_params, [
9090
@base_path + "/"+ @prefix + "/../react-native-codegen",
@@ -100,8 +100,8 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode
100100

101101
# Arrange
102102
FileMock.mocked_existing_files([
103-
@prefix + "/React/Fabric/" + @third_party_provider_header,
104-
@prefix + "/React/Fabric/tmpSchemaList.txt"
103+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
104+
@base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt"
105105
])
106106

107107
DirMock.mocked_existing_dirs([
@@ -116,9 +116,9 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode
116116
assert_equal(Pathname.pwd_invocation_count, 1)
117117
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
118118
assert_equal(FileMock.exist_invocation_params, [
119-
@prefix + "/React/Fabric/" + @third_party_provider_header,
120-
@prefix + "/React/Fabric/" + @third_party_provider_implementation,
121-
@prefix + "/React/Fabric/tmpSchemaList.txt",
119+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
120+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_implementation,
121+
@base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt",
122122
])
123123
assert_equal(DirMock.exist_invocation_params, [
124124
@base_path + "/"+ @prefix + "/../react-native-codegen",
@@ -127,20 +127,20 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenImplementationMissingAndCode
127127
assert_equal(Pod::UI.collected_messages, ["[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"])
128128
assert_equal($collected_commands, [])
129129
assert_equal(FileMock.open_invocation_count, 1)
130-
assert_equal(FileMock.open_files_with_mode[@prefix + "/React/Fabric/tmpSchemaList.txt"], 'w')
130+
assert_equal(FileMock.open_files_with_mode[@prefix + "/React/Fabric/tmpSchemaList.txt"], nil)
131131
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
132132
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
133133
assert_equal(Pod::Executable.executed_commands[0], {
134134
"command" => "node",
135135
"arguments" => [
136136
@base_path + "/" + @prefix + "/scripts/generate-provider-cli.js",
137137
"--platform", 'ios',
138-
"--schemaListPath", @prefix + "/React/Fabric/tmpSchemaList.txt",
139-
"--outputDir", @prefix + "/React/Fabric"
138+
"--schemaListPath", @base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt",
139+
"--outputDir", @base_path + "/" + @prefix + "/React/Fabric"
140140
]
141141
})
142142
assert_equal(FileMock.delete_invocation_count, 1)
143-
assert_equal(FileMock.deleted_files, [ @prefix + "/React/Fabric/tmpSchemaList.txt"])
143+
assert_equal(FileMock.deleted_files, [ @base_path + "/" + @prefix + "/React/Fabric/tmpSchemaList.txt"])
144144
end
145145

146146
def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
@@ -156,8 +156,8 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
156156
assert_equal(Pathname.pwd_invocation_count, 1)
157157
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
158158
assert_equal(FileMock.exist_invocation_params, [
159-
@prefix + "/React/Fabric/" + @third_party_provider_header,
160-
@prefix + "/React/Fabric/" + @tmp_schema_list_file
159+
@base_path + "/" + @prefix + "/React/Fabric/" + @third_party_provider_header,
160+
@base_path + "/" + @prefix + "/React/Fabric/" + @tmp_schema_list_file
161161
])
162162
assert_equal(DirMock.exist_invocation_params, [
163163
@base_path + "/" + @prefix + "/../react-native-codegen",
@@ -176,18 +176,18 @@ def testCheckAndGenerateEmptyThirdPartyProvider_whenBothMissing_buildCodegen()
176176
"arguments" => [
177177
@base_path + "/" + @prefix + "/scripts/generate-provider-cli.js",
178178
"--platform", 'ios',
179-
"--schemaListPath", @prefix + "/React/Fabric/" + @tmp_schema_list_file,
180-
"--outputDir", @prefix + "/React/Fabric"
179+
"--schemaListPath", @base_path + "/" + @prefix + "/React/Fabric/" + @tmp_schema_list_file,
180+
"--outputDir", @base_path + "/" + @prefix + "/React/Fabric"
181181
]
182182
})
183183
end
184184

185185
def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buildCodegen()
186186
# Arrange
187-
rn_path = '/Users/distiller/react-native/packages/react-native'
187+
rn_path = 'packages/react-native'
188188
codegen_cli_path = rn_path + "/../@react-native/codegen"
189189
DirMock.mocked_existing_dirs([
190-
codegen_cli_path,
190+
@base_path + "/" + codegen_cli_path,
191191
])
192192

193193
# Act
@@ -197,28 +197,28 @@ def testCheckAndGenerateEmptyThirdPartyProvider_withAbsoluteReactNativePath_buil
197197
assert_equal(Pathname.pwd_invocation_count, 1)
198198
assert_equal(Pod::Config.instance.installation_root.relative_path_from_invocation_count, 1)
199199
assert_equal(FileMock.exist_invocation_params, [
200-
rn_path + "/React/Fabric/" + @third_party_provider_header,
201-
rn_path + "/React/Fabric/" + @tmp_schema_list_file
200+
@base_path + "/" + rn_path + "/React/Fabric/" + @third_party_provider_header,
201+
@base_path + "/" + rn_path + "/React/Fabric/" + @tmp_schema_list_file
202202
])
203203
assert_equal(DirMock.exist_invocation_params, [
204-
rn_path + "/../react-native-codegen",
205-
codegen_cli_path,
206-
codegen_cli_path + "/lib",
204+
@base_path + "/" + rn_path + "/../react-native-codegen",
205+
@base_path + "/" + codegen_cli_path,
206+
@base_path + "/" + codegen_cli_path + "/lib",
207207
])
208208
assert_equal(Pod::UI.collected_messages, [
209-
"[Codegen] building #{codegen_cli_path}.",
209+
"[Codegen] building #{@base_path + "/" + codegen_cli_path}.",
210210
"[Codegen] generating an empty RCTThirdPartyFabricComponentsProvider"
211211
])
212-
assert_equal($collected_commands, [rn_path + "/../@react-native/codegen/scripts/oss/build.sh"])
212+
assert_equal($collected_commands, [@base_path + "/" + rn_path + "/../@react-native/codegen/scripts/oss/build.sh"])
213213
assert_equal(FileMock.open_files[0].collected_write, ["[]"])
214214
assert_equal(FileMock.open_files[0].fsync_invocation_count, 1)
215215
assert_equal(Pod::Executable.executed_commands[0], {
216216
"command" => "node",
217217
"arguments" => [
218-
rn_path + "/scripts/generate-provider-cli.js",
218+
@base_path + "/" + rn_path + "/scripts/generate-provider-cli.js",
219219
"--platform", 'ios',
220-
"--schemaListPath", rn_path + "/React/Fabric/" + @tmp_schema_list_file,
221-
"--outputDir", rn_path + "/React/Fabric"
220+
"--schemaListPath", @base_path + "/" + rn_path + "/React/Fabric/" + @tmp_schema_list_file,
221+
"--outputDir", @base_path + "/" + rn_path + "/React/Fabric"
222222
]
223223
})
224224
end

packages/react-native/scripts/cocoapods/__tests__/fabric-test.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def teardown
2222
# ================== #
2323
# TEST - setupFabric #
2424
# ================== #
25-
def test_setupFabric_whenNewArchDisabled_installsPods
25+
def test_setupFabric_installsPods
2626
# Arrange
2727
prefix = "../.."
2828

@@ -33,18 +33,6 @@ def test_setupFabric_whenNewArchDisabled_installsPods
3333
check_installed_pods(prefix)
3434
end
3535

36-
def test_setupFabric_whenNewArchEnabled_installPods
37-
# Arrange
38-
prefix = "../.."
39-
ENV['RCT_NEW_ARCH_ENABLED'] = "1"
40-
41-
# Act
42-
setup_fabric!(:react_native_path => prefix, new_arch_enabled: true)
43-
44-
# Assert
45-
check_installed_pods(prefix)
46-
end
47-
4836
def check_installed_pods(prefix)
4937
assert_equal(6, $podInvocationCount)
5038

packages/react-native/scripts/cocoapods/codegen.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def checkAndGenerateEmptyThirdPartyProvider!(react_native_path, new_arch_enabled
4141

4242
relative_installation_root = Pod::Config.instance.installation_root.relative_path_from(Pathname.pwd)
4343

44-
output_dir = "#{react_native_path}/React/Fabric"
44+
output_dir = "#{relative_installation_root}/#{react_native_path}/React/Fabric"
4545

4646
provider_h_path = "#{output_dir}/RCTThirdPartyFabricComponentsProvider.h"
4747
provider_cpp_path ="#{output_dir}/RCTThirdPartyFabricComponentsProvider.mm"

packages/react-native/scripts/cocoapods/fabric.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# It sets up the Fabric dependencies.
88
#
99
# @parameter react_native_path: relative path to react-native
10-
def setup_fabric!(react_native_path: "../node_modules/react-native", new_arch_enabled: false)
10+
def setup_fabric!(react_native_path: "../node_modules/react-native")
1111
pod 'React-Fabric', :path => "#{react_native_path}/ReactCommon"
1212
pod 'React-graphics', :path => "#{react_native_path}/ReactCommon/react/renderer/graphics"
1313
pod 'React-RCTFabric', :path => "#{react_native_path}/React", :modular_headers => true

0 commit comments

Comments
 (0)