7
7
8
8
#import " RCTAppSetupUtils.h"
9
9
10
+ #if RCT_TM_FABRIC_ENABLED
11
+ #import < React/CoreModulesPlugins.h>
12
+ #import < React/RCTDataRequestHandler.h>
13
+ #import < React/RCTFileRequestHandler.h>
14
+ #import < React/RCTGIFImageDecoder.h>
15
+ #import < React/RCTHTTPRequestHandler.h>
16
+ #import < React/RCTImageLoader.h>
17
+ #import < React/RCTJSIExecutorRuntimeInstaller.h>
18
+ #import < React/RCTLocalAssetImageLoader.h>
19
+ #import < React/RCTNetworking.h>
20
+ #endif
21
+
10
22
#ifdef FB_SONARKIT_ENABLED
11
23
#import < FlipperKit/FlipperClient.h>
12
24
#import < FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
@@ -35,6 +47,10 @@ + (void)prepareApp:(UIApplication *)application
35
47
#ifdef FB_SONARKIT_ENABLED
36
48
InitializeFlipper (application);
37
49
#endif
50
+
51
+ #if RCT_TM_FABRIC_ENABLED
52
+ RCTEnableTurboModule (YES );
53
+ #endif
38
54
}
39
55
40
56
+ (RCTRootView *)defaultRootViewWithBridge : (RCTBridge *)bridge
@@ -44,4 +60,66 @@ + (RCTRootView *)defaultRootViewWithBridge:(RCTBridge *)bridge
44
60
return [[RCTRootView alloc ] initWithBridge: bridge moduleName: moduleName initialProperties: initialProperties];
45
61
}
46
62
63
+ #if RCT_TM_FABRIC_ENABLED
64
+ + (id <RCTTurboModule>)defaultModuleInstanceFromClass : (Class )moduleClass
65
+ {
66
+ // Set up the default RCTImageLoader and RCTNetworking modules.
67
+ if (moduleClass == RCTImageLoader.class ) {
68
+ return [[moduleClass alloc ] initWithRedirectDelegate: nil
69
+ loadersProvider: ^NSArray <id <RCTImageURLLoader>> *(RCTModuleRegistry *moduleRegistry) {
70
+ return @[ [RCTLocalAssetImageLoader new ] ];
71
+ }
72
+ decodersProvider: ^NSArray <id <RCTImageDataDecoder>> *(RCTModuleRegistry *moduleRegistry) {
73
+ return @[ [RCTGIFImageDecoder new ] ];
74
+ }];
75
+ } else if (moduleClass == RCTNetworking.class ) {
76
+ return [[moduleClass alloc ]
77
+ initWithHandlersProvider: ^NSArray <id <RCTURLRequestHandler>> *(RCTModuleRegistry *moduleRegistry) {
78
+ return @[
79
+ [RCTHTTPRequestHandler new ],
80
+ [RCTDataRequestHandler new ],
81
+ [RCTFileRequestHandler new ],
82
+ ];
83
+ }];
84
+ }
85
+ // No custom initializer here.
86
+ return [moduleClass new ];
87
+ }
88
+
89
+ + (std::unique_ptr<facebook::react::JSExecutorFactory>)defaultJsExecutorFactoryForBridge : (RCTBridge *)bridge
90
+ withTurboModuleManager :
91
+ (RCTTurboModuleManager *)turboModuleManager ;
92
+ {
93
+ // Necessary to allow NativeModules to lookup TurboModules
94
+ [bridge setRCTTurboModuleRegistry: turboModuleManager];
95
+
96
+ #if RCT_DEV
97
+ if (!RCTTurboModuleEagerInitEnabled ()) {
98
+ /* *
99
+ * Instantiating DevMenu has the side-effect of registering
100
+ * shortcuts for CMD + d, CMD + i, and CMD + n via RCTDevMenu.
101
+ * Therefore, when TurboModules are enabled, we must manually create this
102
+ * NativeModule.
103
+ */
104
+ [turboModuleManager moduleForName: " RCTDevMenu" ];
105
+ }
106
+ #endif
107
+
108
+ #if RCT_USE_HERMES
109
+ return std::make_unique<facebook::react::HermesExecutorFactory>(
110
+ #else
111
+ return std::make_unique<facebook::react::JSCExecutorFactory>(
112
+ #endif
113
+ facebook::react::RCTJSIExecutorRuntimeInstaller ([turboModuleManager, bridge](facebook::jsi::Runtime &runtime) {
114
+ if (!bridge || !turboModuleManager) {
115
+ return ;
116
+ }
117
+ facebook::react::RuntimeExecutor syncRuntimeExecutor =
118
+ [&](std::function<void (facebook::jsi::Runtime & runtime_)> &&callback) { callback (runtime); };
119
+ [turboModuleManager installJSBindingWithRuntimeExecutor: syncRuntimeExecutor];
120
+ }));
121
+ }
122
+
123
+ #endif
124
+
47
125
@end
0 commit comments