@solidnative-dev/fabric-host 0.0.0-stage → 0.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -2
  3. package/dist/fatal-error-handler.d.ts +27 -0
  4. package/dist/fatal-error-handler.d.ts.map +1 -0
  5. package/dist/fatal-error-handler.js +106 -0
  6. package/dist/fatal-error-handler.js.map +1 -0
  7. package/dist/index.d.ts +7 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +7 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/native-binding.d.ts +183 -0
  12. package/dist/native-binding.d.ts.map +1 -0
  13. package/dist/native-binding.js +554 -0
  14. package/dist/native-binding.js.map +1 -0
  15. package/dist/native-fabric-host.d.ts +32 -0
  16. package/dist/native-fabric-host.d.ts.map +1 -0
  17. package/dist/native-fabric-host.js +275 -0
  18. package/dist/native-fabric-host.js.map +1 -0
  19. package/dist/native-transaction.d.ts +17 -0
  20. package/dist/native-transaction.d.ts.map +1 -0
  21. package/dist/native-transaction.js +124 -0
  22. package/dist/native-transaction.js.map +1 -0
  23. package/dist/react-native-0.87.d.ts +61 -0
  24. package/dist/react-native-0.87.d.ts.map +1 -0
  25. package/dist/react-native-0.87.js +77 -0
  26. package/dist/react-native-0.87.js.map +1 -0
  27. package/dist/react-native-0.88.d.ts +77 -0
  28. package/dist/react-native-0.88.d.ts.map +1 -0
  29. package/dist/react-native-0.88.js +79 -0
  30. package/dist/react-native-0.88.js.map +1 -0
  31. package/dist/surface-readiness.d.ts +18 -0
  32. package/dist/surface-readiness.d.ts.map +1 -0
  33. package/dist/surface-readiness.js +43 -0
  34. package/dist/surface-readiness.js.map +1 -0
  35. package/native/README.md +502 -0
  36. package/native/SolidNativeFabric.podspec +84 -0
  37. package/native/android/SolidNativeBindingsInstaller.cpp +4218 -0
  38. package/native/android/SolidNativeBindingsInstaller.h +8 -0
  39. package/native/android/SolidNativeRuntime.cmake +61 -0
  40. package/native/android/java/dev/solidnative/runtime/SolidNativeBindingsInstaller.kt +239 -0
  41. package/native/android/java/dev/solidnative/runtime/SolidNativeDebugModule.kt +191 -0
  42. package/native/android/java/dev/solidnative/runtime/SolidNativePackage.kt +43 -0
  43. package/native/android/java/dev/solidnative/runtime/SolidNativePlatformModule.kt +81 -0
  44. package/native/android/java/dev/solidnative/runtime/SolidNativeStartupFailureView.kt +93 -0
  45. package/native/android/java/dev/solidnative/runtime/SolidNativeSurface.kt +423 -0
  46. package/native/android/solid-native.gradle +90 -0
  47. package/native/apple/SolidNativeDebugRequest.mm +421 -0
  48. package/native/fabric/SolidNativeDebugRequest.h +12 -0
  49. package/native/fabric/SolidNativeDirtyNodes.h +26 -0
  50. package/native/fabric/SolidNativeFabricApi.cpp +224 -0
  51. package/native/fabric/SolidNativeFabricApi.h +107 -0
  52. package/native/fabric/SolidNativeFabricApplication.h +32 -0
  53. package/native/fabric/SolidNativeFabricApplication.mm +373 -0
  54. package/native/fabric/SolidNativeFabricJSIBinding.h +43 -0
  55. package/native/fabric/SolidNativeFabricJSIBinding.mm +4491 -0
  56. package/native/fabric/SolidNativeFabricSmokeApplication.h +26 -0
  57. package/native/fabric/SolidNativeFabricSmokeApplication.mm +331 -0
  58. package/native/fabric/SolidNativeFabricSurface.h +63 -0
  59. package/native/fabric/SolidNativeFabricSurface.mm +549 -0
  60. package/native/fabric/SolidNativeFabricTransactionCoordinator.cpp +1275 -0
  61. package/native/fabric/SolidNativeFabricTransactionCoordinator.h +90 -0
  62. package/native/fabric/SolidNativeFabricTransactionCoordinatorApple.mm +97 -0
  63. package/native/fabric/SolidNativeRootViewController.h +20 -0
  64. package/native/fabric/SolidNativeRootViewController.mm +83 -0
  65. package/native/fabric/SolidNativeStagedNodeMap.h +104 -0
  66. package/native/fabric/SolidNativeStartupFailureView.h +17 -0
  67. package/native/fabric/SolidNativeStartupFailureView.mm +77 -0
  68. package/native/react-native-boundary.json +106 -0
  69. package/native/worklets/SolidNativeUIWorklet.cpp +1080 -0
  70. package/native/worklets/SolidNativeUIWorklet.h +245 -0
  71. package/package.json +41 -3
  72. package/scripts/verify-react-native-boundary.mjs +282 -0
@@ -0,0 +1,107 @@
1
+ #pragma once
2
+
3
+ #include <functional>
4
+ #include <memory>
5
+ #include <string>
6
+ #include <vector>
7
+
8
+ #include <folly/dynamic.h>
9
+ #include <jsi/jsi.h>
10
+ #include <cxxreact/ReactNativeVersion.h>
11
+ #include <react/renderer/core/ReactPrimitives.h>
12
+ #include <react/renderer/core/ShadowNode.h>
13
+
14
+ #if !defined(SOLID_NATIVE_REACT_NATIVE_VERSION_MAJOR) || \
15
+ !defined(SOLID_NATIVE_REACT_NATIVE_VERSION_MINOR) || \
16
+ !defined(SOLID_NATIVE_REACT_NATIVE_VERSION_PATCH)
17
+ #error "Solid Native requires an expected React Native runtime identity from the reviewed boundary manifest."
18
+ #endif
19
+
20
+ #if REACT_NATIVE_VERSION_MAJOR != SOLID_NATIVE_REACT_NATIVE_VERSION_MAJOR || \
21
+ REACT_NATIVE_VERSION_MINOR != SOLID_NATIVE_REACT_NATIVE_VERSION_MINOR || \
22
+ REACT_NATIVE_VERSION_PATCH != SOLID_NATIVE_REACT_NATIVE_VERSION_PATCH
23
+ #error "Solid Native's Fabric adapter does not match the selected React Native runtime."
24
+ #endif
25
+
26
+ #define SOLID_NATIVE_STRINGIFY_DETAIL(value) #value
27
+ #define SOLID_NATIVE_STRINGIFY(value) SOLID_NATIVE_STRINGIFY_DETAIL(value)
28
+ #define SOLID_NATIVE_REACT_NATIVE_RUNTIME_VERSION \
29
+ SOLID_NATIVE_STRINGIFY(SOLID_NATIVE_REACT_NATIVE_VERSION_MAJOR) "." \
30
+ SOLID_NATIVE_STRINGIFY(SOLID_NATIVE_REACT_NATIVE_VERSION_MINOR) "." \
31
+ SOLID_NATIVE_STRINGIFY(SOLID_NATIVE_REACT_NATIVE_VERSION_PATCH)
32
+
33
+ namespace facebook::react {
34
+ class InstanceHandle;
35
+ class UIManager;
36
+ }
37
+
38
+ namespace facebook::jsi {
39
+ class Runtime;
40
+ }
41
+
42
+ namespace solid_native::fabric::react_native {
43
+
44
+ inline constexpr const char *ReactNativeVersion =
45
+ SOLID_NATIVE_REACT_NATIVE_RUNTIME_VERSION;
46
+
47
+ using ShadowNode = facebook::react::ShadowNode;
48
+ using ShadowNodePtr = std::shared_ptr<const ShadowNode>;
49
+ using ShadowNodeList = std::vector<ShadowNodePtr>;
50
+ using NativeResourceResolver = std::function<facebook::jsi::Value(
51
+ facebook::jsi::Runtime &,
52
+ int64_t,
53
+ const std::string &)>;
54
+
55
+ // This is the narrow renderer-operation layer inside the manifest-selected
56
+ // adapter. Platform installation, event interception, and mount observation
57
+ // also use pinned React Native APIs, but application-facing code never does.
58
+ class FabricApi final {
59
+ public:
60
+ static ShadowNodePtr createNode(
61
+ facebook::react::UIManager &uiManager,
62
+ facebook::react::Tag tag,
63
+ const std::string &componentName,
64
+ facebook::react::SurfaceId surfaceId,
65
+ const folly::dynamic &props,
66
+ std::shared_ptr<const facebook::react::InstanceHandle> instanceHandle,
67
+ facebook::jsi::Runtime *runtime,
68
+ const NativeResourceResolver *resourceResolver);
69
+
70
+ static ShadowNodePtr cloneNode(
71
+ facebook::react::UIManager &uiManager,
72
+ const ShadowNode &node,
73
+ std::shared_ptr<const ShadowNodeList> children,
74
+ const folly::dynamic &props,
75
+ facebook::jsi::Runtime *runtime,
76
+ const NativeResourceResolver *resourceResolver);
77
+
78
+ static void appendChild(
79
+ facebook::react::UIManager &uiManager,
80
+ const ShadowNodePtr &parent,
81
+ const ShadowNodePtr &child);
82
+
83
+ static void completeSurface(
84
+ facebook::react::UIManager &uiManager,
85
+ facebook::react::SurfaceId surfaceId,
86
+ std::shared_ptr<ShadowNodeList> rootChildren);
87
+
88
+ static int64_t currentRevisionNumber(
89
+ facebook::react::UIManager &uiManager,
90
+ facebook::react::SurfaceId surfaceId);
91
+
92
+ static void dispatchCommand(
93
+ facebook::react::UIManager &uiManager,
94
+ const ShadowNodePtr &node,
95
+ const std::string &command,
96
+ const folly::dynamic &args);
97
+
98
+ static void sendAccessibilityFocus(
99
+ facebook::react::UIManager &uiManager,
100
+ const ShadowNodePtr &node);
101
+ };
102
+
103
+ } // namespace solid_native::fabric::react_native
104
+
105
+ #undef SOLID_NATIVE_REACT_NATIVE_RUNTIME_VERSION
106
+ #undef SOLID_NATIVE_STRINGIFY
107
+ #undef SOLID_NATIVE_STRINGIFY_DETAIL
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #import <UIKit/UIKit.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ typedef void (^SolidNativeFabricStatusHandler)(
8
+ NSString *status,
9
+ NSError *_Nullable error);
10
+
11
+ // Owns one React Native host, one empty Fabric surface, and the Solid Native
12
+ // JSI binding. Start and stop this application on the main thread. The factory
13
+ // parameter remains `id` so Swift callers do not need to import RCTHost's
14
+ // Objective-C++ declaration.
15
+ @interface SolidNativeFabricApplication : NSObject
16
+
17
+ + (instancetype)startWithFactory:(id)factory
18
+ containerView:(UIView *)containerView
19
+ launchOptions:(nullable NSDictionary *)launchOptions
20
+ statusHandler:
21
+ (nullable SolidNativeFabricStatusHandler)statusHandler;
22
+
23
+ // Requests the same in-process runtime replacement used by React Native's
24
+ // development reload command. The application process and empty Fabric
25
+ // surface remain owned by this object across the replacement.
26
+ - (void)requestDevelopmentReload;
27
+
28
+ - (void)stop;
29
+
30
+ @end
31
+
32
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,373 @@
1
+ #import "SolidNativeFabricApplication.h"
2
+
3
+ #import <React/RCTBridge.h>
4
+ #import <React/RCTReloadCommand.h>
5
+ #import <React/RCTReactNativeFactory.h>
6
+ #import <React/RCTRootViewFactory.h>
7
+ #import <React/RCTSurfacePresenter.h>
8
+ #import <ReactCommon/RCTHost.h>
9
+ #import <React_RCTAppDelegate/RCTJSRuntimeConfiguratorProtocol.h>
10
+
11
+ #include <react/runtime/JSRuntimeFactoryCAPI.h>
12
+
13
+ #include <atomic>
14
+ #include <stdexcept>
15
+
16
+ #import "SolidNativeFabricJSIBinding.h"
17
+ #import "SolidNativeFabricSurface.h"
18
+ #import "SolidNativeRootViewController.h"
19
+ #import "SolidNativeStartupFailureView.h"
20
+
21
+ namespace {
22
+
23
+ constexpr NSInteger MaxHostStartAttempts = 500;
24
+ constexpr int64_t HostStartRetryNanoseconds = 10 * NSEC_PER_MSEC;
25
+
26
+ NSError *hostStartError(void) {
27
+ return [NSError
28
+ errorWithDomain:@"SolidNativeFabricApplication"
29
+ code:1
30
+ userInfo:@{
31
+ NSLocalizedDescriptionKey :
32
+ @"The React Native host did not expose its Fabric scheduler within five seconds."
33
+ }];
34
+ }
35
+
36
+ SolidNativeRootViewController *_Nullable findRootViewController(UIView *view) {
37
+ UIResponder *responder = view;
38
+ while (responder != nil) {
39
+ if ([responder isKindOfClass:[SolidNativeRootViewController class]]) {
40
+ return (SolidNativeRootViewController *)responder;
41
+ }
42
+ responder = responder.nextResponder;
43
+ }
44
+ return nil;
45
+ }
46
+
47
+ UIStatusBarStyle parseStatusBarStyle(NSString *style) {
48
+ if ([style isEqualToString:@"light-content"]) {
49
+ return UIStatusBarStyleLightContent;
50
+ }
51
+ if ([style isEqualToString:@"dark-content"]) {
52
+ return UIStatusBarStyleDarkContent;
53
+ }
54
+ return UIStatusBarStyleDefault;
55
+ }
56
+
57
+ UIStatusBarAnimation parseStatusBarAnimation(NSString *animation) {
58
+ if ([animation isEqualToString:@"fade"]) {
59
+ return UIStatusBarAnimationFade;
60
+ }
61
+ if ([animation isEqualToString:@"slide"]) {
62
+ return UIStatusBarAnimationSlide;
63
+ }
64
+ return UIStatusBarAnimationNone;
65
+ }
66
+
67
+ } // namespace
68
+
69
+ @interface SolidNativeFabricApplication () <RCTHostDelegate>
70
+ - (void)handleFatalErrorWithName:(NSString *)name
71
+ message:(NSString *)message;
72
+ - (void)prepareSurfaceForJSIOwnership:(SolidNativeFabricSurface *)surface
73
+ generation:(NSUInteger)generation;
74
+ @end
75
+
76
+ @implementation SolidNativeFabricApplication {
77
+ RCTReactNativeFactory *_factory;
78
+ id<RCTReactNativeFactoryDelegate> _factoryDelegate;
79
+ RCTHost *_host;
80
+ UIView *_containerView;
81
+ SolidNativeFabricSurface *_surface;
82
+ SolidNativeFabricJSIBinding *_binding;
83
+ SolidNativeFabricStatusHandler _statusHandler;
84
+ std::atomic<bool> _stopped;
85
+ NSUInteger _surfacePreparationGeneration;
86
+ }
87
+
88
+ + (instancetype)startWithFactory:(id)factory
89
+ containerView:(UIView *)containerView
90
+ launchOptions:(NSDictionary *)launchOptions
91
+ statusHandler:
92
+ (SolidNativeFabricStatusHandler)statusHandler {
93
+ return [[self alloc] initWithFactory:factory
94
+ containerView:containerView
95
+ launchOptions:launchOptions
96
+ statusHandler:statusHandler];
97
+ }
98
+
99
+ - (instancetype)initWithFactory:(RCTReactNativeFactory *)factory
100
+ containerView:(UIView *)containerView
101
+ launchOptions:(NSDictionary *)launchOptions
102
+ statusHandler:
103
+ (SolidNativeFabricStatusHandler)statusHandler {
104
+ if (self = [super init]) {
105
+ NSAssert(
106
+ NSThread.isMainThread,
107
+ @"The Solid Native application must start on the main thread.");
108
+ NSParameterAssert(factory != nil);
109
+ NSParameterAssert(factory.delegate != nil);
110
+ NSParameterAssert(containerView != nil);
111
+ _stopped.store(false, std::memory_order_release);
112
+ _factory = factory;
113
+ _factoryDelegate = factory.delegate;
114
+ _containerView = containerView;
115
+ _statusHandler = [statusHandler copy];
116
+ _binding = [[SolidNativeFabricJSIBinding alloc] init];
117
+ __weak SolidNativeFabricApplication *weakSelf = self;
118
+ [_binding setFatalErrorHandler:^(NSString *name, NSString *message) {
119
+ [weakSelf handleFatalErrorWithName:name message:message];
120
+ }];
121
+ if (SolidNativeRootViewController *rootViewController =
122
+ findRootViewController(containerView)) {
123
+ __weak SolidNativeRootViewController *weakRootController =
124
+ rootViewController;
125
+ [_binding setStatusBarStyleHandler:^(NSString *style, BOOL animated) {
126
+ [weakRootController
127
+ setSolidNativeStatusBarStyle:parseStatusBarStyle(style)
128
+ animated:animated];
129
+ }];
130
+ [_binding setStatusBarHiddenHandler:^(BOOL hidden, NSString *animation) {
131
+ [weakRootController
132
+ setSolidNativeStatusBarHidden:hidden
133
+ animation:parseStatusBarAnimation(animation)];
134
+ }];
135
+ }
136
+
137
+ #ifndef RCT_REMOVE_LEGACY_MODULE_INTEROP
138
+ // RCTRootViewFactory enables this before constructing its RCTHost. Solid
139
+ // Native owns the host directly, so preserve the same bridgeless-module
140
+ // contract for linked RCTBridgeModule dependencies before the manager takes
141
+ // its registration snapshot.
142
+ RCTEnableTurboModuleInterop(YES);
143
+ #endif
144
+
145
+ __weak id<RCTReactNativeFactoryDelegate> weakFactoryDelegate =
146
+ _factoryDelegate;
147
+ _host = [[RCTHost alloc]
148
+ initWithBundleURLProvider:^NSURL *() {
149
+ return [weakFactoryDelegate bundleURL];
150
+ }
151
+ hostDelegate:self
152
+ turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)_factory
153
+ jsEngineProvider:
154
+ ^std::shared_ptr<facebook::react::JSRuntimeFactory>() {
155
+ auto factoryRef =
156
+ [weakFactoryDelegate createJSRuntimeFactory];
157
+ if (factoryRef == nullptr) {
158
+ throw std::runtime_error(
159
+ "The React Native factory did not create a JavaScript runtime factory.");
160
+ }
161
+ return std::shared_ptr<facebook::react::JSRuntimeFactory>(
162
+ reinterpret_cast<facebook::react::JSRuntimeFactory *>(
163
+ factoryRef),
164
+ [](facebook::react::JSRuntimeFactory *runtimeFactory) {
165
+ js_runtime_factory_destroy(
166
+ reinterpret_cast<JSRuntimeFactoryRef>(runtimeFactory));
167
+ });
168
+ }
169
+ launchOptions:launchOptions
170
+ bundleConfiguration:_factory.bundleConfiguration
171
+ devMenuConfiguration:_factory.devMenuConfiguration];
172
+ _factory.rootViewFactory.reactHost = _host;
173
+ [_host start];
174
+ [self waitForHostWithAttempt:0];
175
+ }
176
+ return self;
177
+ }
178
+
179
+ - (void)handleFatalErrorWithName:(NSString *)name
180
+ message:(NSString *)message {
181
+ if (_stopped.load(std::memory_order_acquire)) return;
182
+ auto containerView = _containerView;
183
+ if (containerView == nil) return;
184
+ auto error = [NSError
185
+ errorWithDomain:name
186
+ code:3
187
+ userInfo:@{NSLocalizedDescriptionKey : message}];
188
+ [self reportStatus:@"runtime-failed" error:error];
189
+ [self stop];
190
+ [SolidNativeStartupFailureView showInContainerView:containerView error:error];
191
+ }
192
+
193
+ - (void)hostDidStart:(RCTHost *)host {
194
+ [(id<RCTHostDelegate>)_factory hostDidStart:host];
195
+ if (_stopped.load(std::memory_order_acquire) || _surface == nil) return;
196
+
197
+ // RCTHost calls this again before it resets attached surfaces for a
198
+ // development reload. Hide the retiring surface from the replacement
199
+ // runtime immediately, then let RCTHost finish its synchronous reset before
200
+ // starting and republishing our empty surface on the main queue.
201
+ [_binding markSurfaceReloading];
202
+ auto surface = _surface;
203
+ const auto generation = ++_surfacePreparationGeneration;
204
+ __weak SolidNativeFabricApplication *weakSelf = self;
205
+ dispatch_async(dispatch_get_main_queue(), ^{
206
+ SolidNativeFabricApplication *strongSelf = weakSelf;
207
+ if (strongSelf == nil ||
208
+ strongSelf->_stopped.load(std::memory_order_acquire) ||
209
+ strongSelf->_surface != surface ||
210
+ strongSelf->_surfacePreparationGeneration != generation) {
211
+ return;
212
+ }
213
+ [surface rebindToCurrentHostAfterJSRuntimeReload];
214
+ [strongSelf prepareSurfaceForJSIOwnership:surface
215
+ generation:generation];
216
+ });
217
+ }
218
+
219
+ - (void)host:(RCTHost *)host
220
+ didInitializeRuntime:(facebook::jsi::Runtime &)runtime {
221
+ if (_stopped.load(std::memory_order_acquire)) return;
222
+ auto binding = _binding;
223
+ if (binding == nil) return;
224
+ try {
225
+ [binding installIntoRuntime:runtime];
226
+ if (_stopped.load(std::memory_order_acquire)) {
227
+ [binding invalidate];
228
+ return;
229
+ }
230
+ [self reportStatus:@"jsi-installed" error:nil];
231
+ } catch (const std::exception &exception) {
232
+ auto message = [NSString stringWithUTF8String:exception.what()] ?:
233
+ @"The Solid Native JSI binding failed to install.";
234
+ [self reportStatus:
235
+ @"jsi-failed"
236
+ error:[NSError
237
+ errorWithDomain:@"SolidNativeFabricApplication"
238
+ code:2
239
+ userInfo:@{
240
+ NSLocalizedDescriptionKey : message
241
+ }]];
242
+ __weak SolidNativeFabricApplication *weakSelf = self;
243
+ dispatch_async(dispatch_get_main_queue(), ^{
244
+ [weakSelf stop];
245
+ });
246
+ throw;
247
+ }
248
+ }
249
+
250
+ - (BOOL)respondsToSelector:(SEL)selector {
251
+ return [super respondsToSelector:selector] ||
252
+ [_factory respondsToSelector:selector];
253
+ }
254
+
255
+ - (id)forwardingTargetForSelector:(SEL)selector {
256
+ if ([_factory respondsToSelector:selector]) return _factory;
257
+ return [super forwardingTargetForSelector:selector];
258
+ }
259
+
260
+ - (void)waitForHostWithAttempt:(NSInteger)attempt {
261
+ if (_stopped.load(std::memory_order_acquire)) return;
262
+ if (_host.surfacePresenter.scheduler != nil) {
263
+ [self mountApplicationSurface];
264
+ return;
265
+ }
266
+ if (attempt >= MaxHostStartAttempts) {
267
+ [self reportStatus:@"host-failed" error:hostStartError()];
268
+ [self stop];
269
+ return;
270
+ }
271
+
272
+ __weak SolidNativeFabricApplication *weakSelf = self;
273
+ dispatch_after(
274
+ dispatch_time(DISPATCH_TIME_NOW, HostStartRetryNanoseconds),
275
+ dispatch_get_main_queue(),
276
+ ^{
277
+ [weakSelf waitForHostWithAttempt:attempt + 1];
278
+ });
279
+ }
280
+
281
+ - (void)mountApplicationSurface {
282
+ if (_stopped.load(std::memory_order_acquire)) return;
283
+ [self reportStatus:@"host-started" error:nil];
284
+ _surface = [[SolidNativeFabricSurface alloc]
285
+ initWithHost:_host
286
+ size:_containerView.bounds.size];
287
+ [_binding publishSurface:_surface];
288
+ _surface.view.frame = _containerView.bounds;
289
+ [_containerView addSubview:_surface.view];
290
+
291
+ const auto generation = ++_surfacePreparationGeneration;
292
+ [self prepareSurfaceForJSIOwnership:_surface generation:generation];
293
+ }
294
+
295
+ - (void)prepareSurfaceForJSIOwnership:(SolidNativeFabricSurface *)surface
296
+ generation:(NSUInteger)generation {
297
+ __weak SolidNativeFabricApplication *weakSelf = self;
298
+ [surface prepareEmptySurfaceForJSIOwnershipWithCompletion:
299
+ ^(NSError *error) {
300
+ SolidNativeFabricApplication *strongSelf = weakSelf;
301
+ if (strongSelf == nil ||
302
+ strongSelf->_stopped.load(std::memory_order_acquire) ||
303
+ strongSelf->_surface != surface ||
304
+ strongSelf->_surfacePreparationGeneration != generation) {
305
+ return;
306
+ }
307
+ if (error != nil) {
308
+ [strongSelf reportStatus:@"jsi-surface-failed"
309
+ error:error];
310
+ [strongSelf stop];
311
+ return;
312
+ }
313
+ [strongSelf->_binding markSurfaceReady];
314
+ [strongSelf reportStatus:@"jsi-surface-ready" error:nil];
315
+ }];
316
+ }
317
+
318
+ - (void)reportStatus:(NSString *)status error:(NSError *)error {
319
+ if (NSThread.isMainThread) {
320
+ if (_stopped.load(std::memory_order_acquire)) return;
321
+ auto handler = _statusHandler;
322
+ if (handler == nil) return;
323
+ handler(status, error);
324
+ return;
325
+ }
326
+ __weak SolidNativeFabricApplication *weakSelf = self;
327
+ dispatch_async(dispatch_get_main_queue(), ^{
328
+ SolidNativeFabricApplication *strongSelf = weakSelf;
329
+ if (strongSelf == nil ||
330
+ strongSelf->_stopped.load(std::memory_order_acquire)) {
331
+ return;
332
+ }
333
+ auto handler = strongSelf->_statusHandler;
334
+ if (handler == nil) return;
335
+ handler(status, error);
336
+ });
337
+ }
338
+
339
+ - (void)requestDevelopmentReload {
340
+ NSAssert(
341
+ NSThread.isMainThread,
342
+ @"A Solid Native development reload must be requested on the main thread.");
343
+ if (_stopped.load(std::memory_order_acquire) || _host == nil) return;
344
+ RCTTriggerReloadCommandListeners(@"Solid Native development reload");
345
+ }
346
+
347
+ - (void)stop {
348
+ if (_stopped.load(std::memory_order_acquire)) return;
349
+ NSAssert(
350
+ NSThread.isMainThread,
351
+ @"The Solid Native application must stop on the main thread.");
352
+ if (_stopped.exchange(true, std::memory_order_acq_rel)) return;
353
+ [_binding setFatalErrorHandler:nil];
354
+ [_binding setStatusBarStyleHandler:nil];
355
+ [_binding setStatusBarHiddenHandler:nil];
356
+ [_binding invalidate];
357
+ [_surface stop];
358
+ [_surface.view removeFromSuperview];
359
+ _surface = nil;
360
+ if (_factory.rootViewFactory.reactHost == _host) {
361
+ _factory.rootViewFactory.reactHost = nil;
362
+ }
363
+ _host = nil;
364
+ _binding = nil;
365
+ _containerView = nil;
366
+ _statusHandler = nil;
367
+ }
368
+
369
+ - (void)dealloc {
370
+ [self stop];
371
+ }
372
+
373
+ @end
@@ -0,0 +1,43 @@
1
+ #pragma once
2
+
3
+ #import <Foundation/Foundation.h>
4
+
5
+ namespace facebook::jsi {
6
+ class Runtime;
7
+ }
8
+
9
+ @class SolidNativeFabricSurface;
10
+
11
+ NS_ASSUME_NONNULL_BEGIN
12
+
13
+ typedef void (^SolidNativeFabricFatalErrorHandler)(
14
+ NSString *name,
15
+ NSString *message);
16
+ typedef void (^SolidNativeFabricStatusBarStyleHandler)(
17
+ NSString *style,
18
+ BOOL animated);
19
+ typedef void (^SolidNativeFabricStatusBarHiddenHandler)(
20
+ BOOL hidden,
21
+ NSString *animation);
22
+
23
+ // Installs the production versioned JavaScript-to-Fabric transport. The binding
24
+ // never retains JSI values outside the runtime-owned host functions and may
25
+ // only be installed or invoked on React Native's JS thread.
26
+ @interface SolidNativeFabricJSIBinding : NSObject
27
+
28
+ - (void)installIntoRuntime:(facebook::jsi::Runtime &)runtime;
29
+
30
+ - (void)publishSurface:(SolidNativeFabricSurface *)surface;
31
+ - (void)markSurfaceReloading;
32
+ - (void)markSurfaceReady;
33
+ - (void)setFatalErrorHandler:
34
+ (nullable SolidNativeFabricFatalErrorHandler)handler;
35
+ - (void)setStatusBarStyleHandler:
36
+ (nullable SolidNativeFabricStatusBarStyleHandler)handler;
37
+ - (void)setStatusBarHiddenHandler:
38
+ (nullable SolidNativeFabricStatusBarHiddenHandler)handler;
39
+ - (void)invalidate;
40
+
41
+ @end
42
+
43
+ NS_ASSUME_NONNULL_END