99#import " AppDelegate.h"
1010
1111#import < React/JSCExecutorFactory.h>
12+ #import < React/RCTJSIExecutorRuntimeInstaller.h>
1213#import < React/RCTBridge.h>
1314#import < React/RCTBundleURLProvider.h>
1415#import < React/RCTCxxBridgeDelegate.h>
16+ #import < React/RCTJavaScriptLoader.h>
1517#import < React/RCTLinkingManager.h>
18+ #import < React/RCTImageLoader.h>
19+ #import < React/RCTLocalAssetImageLoader.h>
20+ #import < React/RCTGIFImageDecoder.h>
21+ #import < React/RCTNetworking.h>
22+ #import < React/RCTHTTPRequestHandler.h>
23+ #import < React/RCTDataRequestHandler.h>
24+ #import < React/RCTFileRequestHandler.h>
25+ #import < React/RCTRootView.h>
26+
27+ #import < cxxreact/JSExecutor.h>
28+
29+ #if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
1630#import < React/RCTPushNotificationManager.h>
17- #import < React/RCTTextAttributes.h>
18- #import < ReactCommon/TurboModule.h>
19- #import " ../NativeModuleExample/ScreenshotMacOS.h"
31+ #endif
32+
33+ #ifdef RN_FABRIC_ENABLED
34+ #import < React/RCTSurfacePresenter.h>
35+ #import < React/RCTFabricSurfaceHostingProxyRootView.h>
36+ #endif
2037
2138#import < ReactCommon/RCTTurboModuleManager.h>
39+ #import < React/RCTTextAttributes.h> // TODO(OSS Candidate ISS#2710739)
40+
41+ #import " RNTesterTurboModuleProvider.h"
2242
2343NSString *kBundleNameJS = @" RNTesterApp" ;
2444
25- @interface AppDelegate () <RCTCxxBridgeDelegate, NSUserNotificationCenterDelegate >
45+ @interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate, NSUserNotificationCenterDelegate >
2646{
27- ScreenshotManagerTurboModuleManagerDelegate *_turboModuleManagerDelegate;
47+ #ifdef RN_FABRIC_ENABLED
48+ RCTSurfacePresenter *_surfacePresenter;
49+ #endif
50+
2851 RCTTurboModuleManager *_turboModuleManager;
2952}
3053@end
@@ -37,6 +60,8 @@ @implementation AppDelegate
3760- (void )awakeFromNib
3861{
3962 [super awakeFromNib ];
63+
64+ RCTEnableTurboModule (YES );
4065
4166 _bridge = [[RCTBridge alloc ] initWithDelegate: self
4267 launchOptions: nil ];
@@ -84,20 +109,64 @@ - (NSURL *)sourceURLForBridge:(__unused RCTBridge *)bridge
84109
85110- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge : (RCTBridge *)bridge
86111{
112+ _turboModuleManager = [[RCTTurboModuleManager alloc ] initWithBridge: bridge
113+ delegate: self
114+ jsInvoker: bridge.jsCallInvoker];
87115 __weak __typeof (self) weakSelf = self;
88- return std::make_unique<facebook::react::JSCExecutorFactory>([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
89- if (!bridge) {
90- return ;
91- }
92- __typeof (self) strongSelf = weakSelf;
93- if (strongSelf) {
94- strongSelf->_turboModuleManagerDelegate = [ScreenshotManagerTurboModuleManagerDelegate new ];
95- strongSelf->_turboModuleManager = [[RCTTurboModuleManager alloc ] initWithBridge: bridge
96- delegate: strongSelf->_turboModuleManagerDelegate
97- jsInvoker: bridge.jsCallInvoker];
98- [strongSelf->_turboModuleManager installJSBindingWithRuntime: &runtime];
99- }
100- });
116+ return std::make_unique<facebook::react::JSCExecutorFactory>(
117+ facebook::react::RCTJSIExecutorRuntimeInstaller ([weakSelf, bridge](facebook::jsi::Runtime &runtime) {
118+ if (!bridge) {
119+ return ;
120+ }
121+ __typeof (self) strongSelf = weakSelf;
122+ if (strongSelf) {
123+ [strongSelf->_turboModuleManager installJSBindingWithRuntime: &runtime];
124+ }
125+ })
126+ );
127+ }
128+
129+ #pragma mark RCTTurboModuleManagerDelegate
130+
131+ - (Class )getModuleClassFromName : (const char *)name
132+ {
133+ return facebook::react::RNTesterTurboModuleClassProvider (name);
134+ }
135+
136+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
137+ jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
138+ {
139+ return facebook::react::RNTesterTurboModuleProvider (name, jsInvoker);
140+ }
141+
142+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule : (const std::string &)name
143+ instance : (id <RCTTurboModule>)instance
144+ jsInvoker : (std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
145+ nativeInvoker : (std::shared_ptr<facebook::react::CallInvoker>)nativeInvoker
146+ perfLogger : (id <RCTTurboModulePerformanceLogger>)perfLogger
147+ {
148+ return facebook::react::RNTesterTurboModuleProvider (name, instance, jsInvoker, nativeInvoker, perfLogger);
149+ }
150+
151+ - (id <RCTTurboModule>)getModuleInstanceFromClass : (Class )moduleClass
152+ {
153+ if (moduleClass == RCTImageLoader.class ) {
154+ return [[moduleClass alloc ] initWithRedirectDelegate: nil loadersProvider: ^NSArray <id <RCTImageURLLoader>> *{
155+ return @[[RCTLocalAssetImageLoader new ]];
156+ } decodersProvider: ^NSArray <id <RCTImageDataDecoder>> *{
157+ return @[[RCTGIFImageDecoder new ]];
158+ }];
159+ } else if (moduleClass == RCTNetworking.class ) {
160+ return [[moduleClass alloc ] initWithHandlersProvider: ^NSArray <id <RCTURLRequestHandler>> *{
161+ return @[
162+ [RCTHTTPRequestHandler new ],
163+ [RCTDataRequestHandler new ],
164+ [RCTFileRequestHandler new ],
165+ ];
166+ }];
167+ }
168+ // No custom initializer here.
169+ return [moduleClass new ];
101170}
102171
103172# pragma mark - Push Notifications
@@ -135,4 +204,4 @@ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentN
135204 return YES ;
136205}
137206
138- @end
207+ @end
0 commit comments