@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.
- package/LICENSE +21 -0
- package/README.md +87 -2
- package/dist/fatal-error-handler.d.ts +27 -0
- package/dist/fatal-error-handler.d.ts.map +1 -0
- package/dist/fatal-error-handler.js +106 -0
- package/dist/fatal-error-handler.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/native-binding.d.ts +183 -0
- package/dist/native-binding.d.ts.map +1 -0
- package/dist/native-binding.js +554 -0
- package/dist/native-binding.js.map +1 -0
- package/dist/native-fabric-host.d.ts +32 -0
- package/dist/native-fabric-host.d.ts.map +1 -0
- package/dist/native-fabric-host.js +275 -0
- package/dist/native-fabric-host.js.map +1 -0
- package/dist/native-transaction.d.ts +17 -0
- package/dist/native-transaction.d.ts.map +1 -0
- package/dist/native-transaction.js +124 -0
- package/dist/native-transaction.js.map +1 -0
- package/dist/react-native-0.87.d.ts +61 -0
- package/dist/react-native-0.87.d.ts.map +1 -0
- package/dist/react-native-0.87.js +77 -0
- package/dist/react-native-0.87.js.map +1 -0
- package/dist/react-native-0.88.d.ts +77 -0
- package/dist/react-native-0.88.d.ts.map +1 -0
- package/dist/react-native-0.88.js +79 -0
- package/dist/react-native-0.88.js.map +1 -0
- package/dist/surface-readiness.d.ts +18 -0
- package/dist/surface-readiness.d.ts.map +1 -0
- package/dist/surface-readiness.js +43 -0
- package/dist/surface-readiness.js.map +1 -0
- package/native/README.md +502 -0
- package/native/SolidNativeFabric.podspec +84 -0
- package/native/android/SolidNativeBindingsInstaller.cpp +4218 -0
- package/native/android/SolidNativeBindingsInstaller.h +8 -0
- package/native/android/SolidNativeRuntime.cmake +61 -0
- package/native/android/java/dev/solidnative/runtime/SolidNativeBindingsInstaller.kt +239 -0
- package/native/android/java/dev/solidnative/runtime/SolidNativeDebugModule.kt +191 -0
- package/native/android/java/dev/solidnative/runtime/SolidNativePackage.kt +43 -0
- package/native/android/java/dev/solidnative/runtime/SolidNativePlatformModule.kt +81 -0
- package/native/android/java/dev/solidnative/runtime/SolidNativeStartupFailureView.kt +93 -0
- package/native/android/java/dev/solidnative/runtime/SolidNativeSurface.kt +423 -0
- package/native/android/solid-native.gradle +90 -0
- package/native/apple/SolidNativeDebugRequest.mm +421 -0
- package/native/fabric/SolidNativeDebugRequest.h +12 -0
- package/native/fabric/SolidNativeDirtyNodes.h +26 -0
- package/native/fabric/SolidNativeFabricApi.cpp +224 -0
- package/native/fabric/SolidNativeFabricApi.h +107 -0
- package/native/fabric/SolidNativeFabricApplication.h +32 -0
- package/native/fabric/SolidNativeFabricApplication.mm +373 -0
- package/native/fabric/SolidNativeFabricJSIBinding.h +43 -0
- package/native/fabric/SolidNativeFabricJSIBinding.mm +4491 -0
- package/native/fabric/SolidNativeFabricSmokeApplication.h +26 -0
- package/native/fabric/SolidNativeFabricSmokeApplication.mm +331 -0
- package/native/fabric/SolidNativeFabricSurface.h +63 -0
- package/native/fabric/SolidNativeFabricSurface.mm +549 -0
- package/native/fabric/SolidNativeFabricTransactionCoordinator.cpp +1275 -0
- package/native/fabric/SolidNativeFabricTransactionCoordinator.h +90 -0
- package/native/fabric/SolidNativeFabricTransactionCoordinatorApple.mm +97 -0
- package/native/fabric/SolidNativeRootViewController.h +20 -0
- package/native/fabric/SolidNativeRootViewController.mm +83 -0
- package/native/fabric/SolidNativeStagedNodeMap.h +104 -0
- package/native/fabric/SolidNativeStartupFailureView.h +17 -0
- package/native/fabric/SolidNativeStartupFailureView.mm +77 -0
- package/native/react-native-boundary.json +106 -0
- package/native/worklets/SolidNativeUIWorklet.cpp +1080 -0
- package/native/worklets/SolidNativeUIWorklet.h +245 -0
- package/package.json +41 -3
- package/scripts/verify-react-native-boundary.mjs +282 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
#import "../fabric/SolidNativeDebugRequest.h"
|
|
2
|
+
|
|
3
|
+
#import <ReactCommon/RCTTurboModule.h>
|
|
4
|
+
|
|
5
|
+
#if __has_include(<SolidNativeAppSpec/SolidNativeAppSpec.h>)
|
|
6
|
+
#import <SolidNativeAppSpec/SolidNativeAppSpec.h>
|
|
7
|
+
#elif __has_include(<SolidNativeE2ESpec/SolidNativeE2ESpec.h>)
|
|
8
|
+
#import <SolidNativeE2ESpec/SolidNativeE2ESpec.h>
|
|
9
|
+
#else
|
|
10
|
+
#error "SolidNativeDebug requires the scaffolded Solid Native application Codegen spec."
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
using namespace facebook::react;
|
|
14
|
+
|
|
15
|
+
#ifndef SOLID_NATIVE_CAUSAL_DEBUG_ENABLED
|
|
16
|
+
#define SOLID_NATIVE_CAUSAL_DEBUG_ENABLED 0
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
#if DEBUG || SOLID_NATIVE_CAUSAL_DEBUG_ENABLED
|
|
20
|
+
#define SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE 1
|
|
21
|
+
#else
|
|
22
|
+
#define SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE 0
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
static NSString *const SolidNativeDebugModuleName = @"SolidNativeDebug";
|
|
26
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
27
|
+
static NSString *const SolidNativeDebugURLScheme = @"solid-native-debug";
|
|
28
|
+
static NSString *const SolidNativeDebugRequestIdKey = @"requestId";
|
|
29
|
+
static NSString *const SolidNativeDebugOperationKey = @"operation";
|
|
30
|
+
static NSString *const SolidNativeDebugSessionIdKey = @"sessionId";
|
|
31
|
+
static NSString *const SolidNativeDebugOperationCausalSnapshot = @"causal-snapshot";
|
|
32
|
+
static NSString *const SolidNativeDebugOperationDiagnosticsBegin = @"solid-diagnostics-begin";
|
|
33
|
+
static NSString *const SolidNativeDebugOperationDiagnosticsEnd = @"solid-diagnostics-end";
|
|
34
|
+
static NSString *const SolidNativeDebugOperationTreeSnapshot = @"tree-snapshot";
|
|
35
|
+
static NSString *const SolidNativeDebugResponseDirectory = @"solid-native-debug";
|
|
36
|
+
static NSUInteger const SolidNativeDebugMaximumPendingRequests = 8;
|
|
37
|
+
static NSUInteger const SolidNativeDebugMaximumSnapshotBytes = 16'777'216;
|
|
38
|
+
|
|
39
|
+
@class SolidNativeDebugModule;
|
|
40
|
+
|
|
41
|
+
static NSMutableOrderedSet<NSString *> *SolidNativeDebugPendingRequests(void)
|
|
42
|
+
{
|
|
43
|
+
static NSMutableOrderedSet<NSString *> *requests;
|
|
44
|
+
static dispatch_once_t onceToken;
|
|
45
|
+
dispatch_once(&onceToken, ^{
|
|
46
|
+
requests = [NSMutableOrderedSet orderedSet];
|
|
47
|
+
});
|
|
48
|
+
return requests;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static NSMutableOrderedSet<NSString *> *SolidNativeDebugPublishedRequests(void)
|
|
52
|
+
{
|
|
53
|
+
static NSMutableOrderedSet<NSString *> *requests;
|
|
54
|
+
static dispatch_once_t onceToken;
|
|
55
|
+
dispatch_once(&onceToken, ^{
|
|
56
|
+
requests = [NSMutableOrderedSet orderedSet];
|
|
57
|
+
});
|
|
58
|
+
return requests;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static NSMutableDictionary<NSString *, NSString *> *SolidNativeDebugPendingRequestOperations(void)
|
|
62
|
+
{
|
|
63
|
+
static NSMutableDictionary<NSString *, NSString *> *operations;
|
|
64
|
+
static dispatch_once_t onceToken;
|
|
65
|
+
dispatch_once(&onceToken, ^{
|
|
66
|
+
operations = [NSMutableDictionary dictionary];
|
|
67
|
+
});
|
|
68
|
+
return operations;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static NSMutableDictionary<NSString *, NSString *> *SolidNativeDebugPendingRequestSessions(void)
|
|
72
|
+
{
|
|
73
|
+
static NSMutableDictionary<NSString *, NSString *> *sessions;
|
|
74
|
+
static dispatch_once_t onceToken;
|
|
75
|
+
dispatch_once(&onceToken, ^{
|
|
76
|
+
sessions = [NSMutableDictionary dictionary];
|
|
77
|
+
});
|
|
78
|
+
return sessions;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static BOOL SolidNativeDebugValidRequestId(NSString *requestId)
|
|
82
|
+
{
|
|
83
|
+
if (requestId.length != 32) {
|
|
84
|
+
return NO;
|
|
85
|
+
}
|
|
86
|
+
static NSCharacterSet *invalidCharacters;
|
|
87
|
+
static dispatch_once_t onceToken;
|
|
88
|
+
dispatch_once(&onceToken, ^{
|
|
89
|
+
invalidCharacters = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789abcdef"] invertedSet];
|
|
90
|
+
});
|
|
91
|
+
return [requestId rangeOfCharacterFromSet:invalidCharacters].location == NSNotFound;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static BOOL SolidNativeDebugValidOperation(NSString *operation)
|
|
95
|
+
{
|
|
96
|
+
return [operation isEqualToString:SolidNativeDebugOperationCausalSnapshot] ||
|
|
97
|
+
[operation isEqualToString:SolidNativeDebugOperationDiagnosticsBegin] ||
|
|
98
|
+
[operation isEqualToString:SolidNativeDebugOperationDiagnosticsEnd] ||
|
|
99
|
+
[operation isEqualToString:SolidNativeDebugOperationTreeSnapshot];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static NSURL *SolidNativeDebugResponseDirectoryURL(void)
|
|
103
|
+
{
|
|
104
|
+
NSURL *cache = [NSFileManager.defaultManager URLsForDirectory:NSCachesDirectory
|
|
105
|
+
inDomains:NSUserDomainMask].firstObject;
|
|
106
|
+
return [cache URLByAppendingPathComponent:SolidNativeDebugResponseDirectory isDirectory:YES];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static NSURL *SolidNativeDebugResponseURL(NSString *requestId)
|
|
110
|
+
{
|
|
111
|
+
return [SolidNativeDebugResponseDirectoryURL()
|
|
112
|
+
URLByAppendingPathComponent:[requestId stringByAppendingPathExtension:@"json"]
|
|
113
|
+
isDirectory:NO];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static void SolidNativeDebugRemoveUntrackedResponses(NSSet<NSString *> *retainedRequestIds)
|
|
117
|
+
{
|
|
118
|
+
NSArray<NSURL *> *responses = [NSFileManager.defaultManager
|
|
119
|
+
contentsOfDirectoryAtURL:SolidNativeDebugResponseDirectoryURL()
|
|
120
|
+
includingPropertiesForKeys:@[ NSURLIsRegularFileKey ]
|
|
121
|
+
options:NSDirectoryEnumerationSkipsHiddenFiles
|
|
122
|
+
error:nil];
|
|
123
|
+
for (NSURL *response in responses) {
|
|
124
|
+
NSNumber *regularFile;
|
|
125
|
+
if (![response getResourceValue:®ularFile forKey:NSURLIsRegularFileKey error:nil] || !regularFile.boolValue ||
|
|
126
|
+
![response.pathExtension isEqualToString:@"json"]) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
NSString *requestId = response.URLByDeletingPathExtension.lastPathComponent;
|
|
130
|
+
if (SolidNativeDebugValidRequestId(requestId) && ![retainedRequestIds containsObject:requestId]) {
|
|
131
|
+
[NSFileManager.defaultManager removeItemAtURL:response error:nil];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
#endif
|
|
136
|
+
|
|
137
|
+
@interface SolidNativeDebugModule : NativeSolidNativeDebugSpecBase <NativeSolidNativeDebugSpec>
|
|
138
|
+
|
|
139
|
+
+ (void)enqueueRequestId:(NSString *)requestId operation:(NSString *)operation sessionId:(NSString *)sessionId;
|
|
140
|
+
+ (void)acknowledgeRequestId:(NSString *)requestId;
|
|
141
|
+
|
|
142
|
+
@end
|
|
143
|
+
|
|
144
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
145
|
+
static __weak SolidNativeDebugModule *SolidNativeDebugActiveModule;
|
|
146
|
+
#endif
|
|
147
|
+
|
|
148
|
+
@implementation SolidNativeDebugRequest
|
|
149
|
+
|
|
150
|
+
+ (BOOL)handleURL:(NSURL *)url
|
|
151
|
+
{
|
|
152
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
153
|
+
if (![url.scheme isEqualToString:SolidNativeDebugURLScheme]) {
|
|
154
|
+
return NO;
|
|
155
|
+
}
|
|
156
|
+
NSString *operation = url.host;
|
|
157
|
+
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
|
|
158
|
+
NSString *requestId;
|
|
159
|
+
NSString *requestedOperation;
|
|
160
|
+
NSString *sessionId;
|
|
161
|
+
for (NSURLQueryItem *item in components.queryItems) {
|
|
162
|
+
if ([item.name isEqualToString:SolidNativeDebugRequestIdKey]) {
|
|
163
|
+
if (requestId != nil) {
|
|
164
|
+
return NO;
|
|
165
|
+
}
|
|
166
|
+
requestId = item.value;
|
|
167
|
+
} else if ([item.name isEqualToString:SolidNativeDebugOperationKey]) {
|
|
168
|
+
if (requestedOperation != nil) {
|
|
169
|
+
return NO;
|
|
170
|
+
}
|
|
171
|
+
requestedOperation = item.value;
|
|
172
|
+
} else if ([item.name isEqualToString:SolidNativeDebugSessionIdKey]) {
|
|
173
|
+
if (sessionId != nil) {
|
|
174
|
+
return NO;
|
|
175
|
+
}
|
|
176
|
+
sessionId = item.value;
|
|
177
|
+
} else {
|
|
178
|
+
return NO;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!SolidNativeDebugValidRequestId(requestId)) {
|
|
182
|
+
return NO;
|
|
183
|
+
}
|
|
184
|
+
if ([operation isEqualToString:@"capture"]) {
|
|
185
|
+
NSString *debugOperation = requestedOperation ?: SolidNativeDebugOperationCausalSnapshot;
|
|
186
|
+
if (!SolidNativeDebugValidOperation(debugOperation)) {
|
|
187
|
+
return NO;
|
|
188
|
+
}
|
|
189
|
+
if ([debugOperation isEqualToString:SolidNativeDebugOperationDiagnosticsEnd]) {
|
|
190
|
+
if (!SolidNativeDebugValidRequestId(sessionId)) {
|
|
191
|
+
return NO;
|
|
192
|
+
}
|
|
193
|
+
} else if (sessionId != nil) {
|
|
194
|
+
return NO;
|
|
195
|
+
}
|
|
196
|
+
[SolidNativeDebugModule enqueueRequestId:requestId operation:debugOperation sessionId:sessionId];
|
|
197
|
+
return YES;
|
|
198
|
+
}
|
|
199
|
+
if ([operation isEqualToString:@"ack"]) {
|
|
200
|
+
if (requestedOperation != nil || sessionId != nil) {
|
|
201
|
+
return NO;
|
|
202
|
+
}
|
|
203
|
+
[SolidNativeDebugModule acknowledgeRequestId:requestId];
|
|
204
|
+
return YES;
|
|
205
|
+
}
|
|
206
|
+
#else
|
|
207
|
+
(void)url;
|
|
208
|
+
#endif
|
|
209
|
+
return NO;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@end
|
|
213
|
+
|
|
214
|
+
@implementation SolidNativeDebugModule {
|
|
215
|
+
BOOL _hasListeners;
|
|
216
|
+
NSMutableOrderedSet<NSString *> *_outstandingRequestIds;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
+ (NSString *)moduleName
|
|
220
|
+
{
|
|
221
|
+
return SolidNativeDebugModuleName;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
+ (BOOL)requiresMainQueueSetup
|
|
225
|
+
{
|
|
226
|
+
return YES;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
- (instancetype)init
|
|
230
|
+
{
|
|
231
|
+
if ((self = [super init])) {
|
|
232
|
+
_outstandingRequestIds = [NSMutableOrderedSet orderedSet];
|
|
233
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
234
|
+
@synchronized(SolidNativeDebugModule.class) {
|
|
235
|
+
SolidNativeDebugRemoveUntrackedResponses(
|
|
236
|
+
[NSSet setWithArray:SolidNativeDebugPublishedRequests().array]);
|
|
237
|
+
}
|
|
238
|
+
#endif
|
|
239
|
+
}
|
|
240
|
+
return self;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
- (dispatch_queue_t)methodQueue
|
|
244
|
+
{
|
|
245
|
+
return dispatch_get_main_queue();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
- (void)setSnapshotListenerReady:(BOOL)ready
|
|
249
|
+
{
|
|
250
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
251
|
+
_hasListeners = ready;
|
|
252
|
+
@synchronized(SolidNativeDebugModule.class) {
|
|
253
|
+
if (ready) {
|
|
254
|
+
SolidNativeDebugActiveModule = self;
|
|
255
|
+
} else if (SolidNativeDebugActiveModule == self) {
|
|
256
|
+
SolidNativeDebugActiveModule = nil;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (ready) {
|
|
260
|
+
[self flushPendingRequests];
|
|
261
|
+
} else {
|
|
262
|
+
[_outstandingRequestIds removeAllObjects];
|
|
263
|
+
}
|
|
264
|
+
#else
|
|
265
|
+
(void)ready;
|
|
266
|
+
#endif
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
- (void)invalidate
|
|
270
|
+
{
|
|
271
|
+
[self setSnapshotListenerReady:NO];
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
+ (void)enqueueRequestId:(NSString *)requestId operation:(NSString *)operation sessionId:(NSString *)sessionId
|
|
275
|
+
{
|
|
276
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
277
|
+
@synchronized(self) {
|
|
278
|
+
NSMutableOrderedSet<NSString *> *requests = SolidNativeDebugPendingRequests();
|
|
279
|
+
NSMutableDictionary<NSString *, NSString *> *operations = SolidNativeDebugPendingRequestOperations();
|
|
280
|
+
NSMutableDictionary<NSString *, NSString *> *sessions = SolidNativeDebugPendingRequestSessions();
|
|
281
|
+
[requests removeObject:requestId];
|
|
282
|
+
[operations removeObjectForKey:requestId];
|
|
283
|
+
[sessions removeObjectForKey:requestId];
|
|
284
|
+
while (requests.count >= SolidNativeDebugMaximumPendingRequests) {
|
|
285
|
+
NSString *evictedRequestId = requests.firstObject;
|
|
286
|
+
[requests removeObjectAtIndex:0];
|
|
287
|
+
[operations removeObjectForKey:evictedRequestId];
|
|
288
|
+
[sessions removeObjectForKey:evictedRequestId];
|
|
289
|
+
}
|
|
290
|
+
[requests addObject:requestId];
|
|
291
|
+
operations[requestId] = operation;
|
|
292
|
+
if (sessionId != nil) {
|
|
293
|
+
sessions[requestId] = sessionId;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
[NSFileManager.defaultManager removeItemAtURL:SolidNativeDebugResponseURL(requestId) error:nil];
|
|
297
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
298
|
+
SolidNativeDebugModule *module;
|
|
299
|
+
@synchronized(self) {
|
|
300
|
+
module = SolidNativeDebugActiveModule;
|
|
301
|
+
}
|
|
302
|
+
[module flushPendingRequests];
|
|
303
|
+
});
|
|
304
|
+
#else
|
|
305
|
+
(void)requestId;
|
|
306
|
+
(void)operation;
|
|
307
|
+
(void)sessionId;
|
|
308
|
+
#endif
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
+ (void)acknowledgeRequestId:(NSString *)requestId
|
|
312
|
+
{
|
|
313
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
314
|
+
@synchronized(self) {
|
|
315
|
+
[SolidNativeDebugPendingRequests() removeObject:requestId];
|
|
316
|
+
[SolidNativeDebugPendingRequestOperations() removeObjectForKey:requestId];
|
|
317
|
+
[SolidNativeDebugPendingRequestSessions() removeObjectForKey:requestId];
|
|
318
|
+
[SolidNativeDebugPublishedRequests() removeObject:requestId];
|
|
319
|
+
}
|
|
320
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
321
|
+
SolidNativeDebugModule *module;
|
|
322
|
+
@synchronized(self) {
|
|
323
|
+
module = SolidNativeDebugActiveModule;
|
|
324
|
+
}
|
|
325
|
+
[module->_outstandingRequestIds removeObject:requestId];
|
|
326
|
+
[NSFileManager.defaultManager removeItemAtURL:SolidNativeDebugResponseURL(requestId) error:nil];
|
|
327
|
+
});
|
|
328
|
+
#else
|
|
329
|
+
(void)requestId;
|
|
330
|
+
#endif
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
- (void)flushPendingRequests
|
|
334
|
+
{
|
|
335
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
336
|
+
if (!_hasListeners) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
NSArray<NSString *> *requests;
|
|
340
|
+
NSDictionary<NSString *, NSString *> *operations;
|
|
341
|
+
NSDictionary<NSString *, NSString *> *sessions;
|
|
342
|
+
@synchronized(SolidNativeDebugModule.class) {
|
|
343
|
+
requests = [SolidNativeDebugPendingRequests().array copy];
|
|
344
|
+
operations = [SolidNativeDebugPendingRequestOperations() copy];
|
|
345
|
+
sessions = [SolidNativeDebugPendingRequestSessions() copy];
|
|
346
|
+
[SolidNativeDebugPendingRequests() removeAllObjects];
|
|
347
|
+
[SolidNativeDebugPendingRequestOperations() removeAllObjects];
|
|
348
|
+
[SolidNativeDebugPendingRequestSessions() removeAllObjects];
|
|
349
|
+
}
|
|
350
|
+
for (NSString *requestId in requests) {
|
|
351
|
+
while (_outstandingRequestIds.count >= SolidNativeDebugMaximumPendingRequests) {
|
|
352
|
+
[_outstandingRequestIds removeObjectAtIndex:0];
|
|
353
|
+
}
|
|
354
|
+
[_outstandingRequestIds addObject:requestId];
|
|
355
|
+
NSString *operation = operations[requestId] ?: SolidNativeDebugOperationCausalSnapshot;
|
|
356
|
+
NSMutableDictionary<NSString *, NSString *> *event = [@{
|
|
357
|
+
SolidNativeDebugRequestIdKey : requestId,
|
|
358
|
+
SolidNativeDebugOperationKey : operation,
|
|
359
|
+
} mutableCopy];
|
|
360
|
+
NSString *sessionId = sessions[requestId];
|
|
361
|
+
if (sessionId != nil) {
|
|
362
|
+
event[SolidNativeDebugSessionIdKey] = sessionId;
|
|
363
|
+
}
|
|
364
|
+
[self emitOnSnapshotRequest:event];
|
|
365
|
+
}
|
|
366
|
+
#endif
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
- (void)publishSnapshot:(NSString *)requestId
|
|
370
|
+
payload:(NSString *)payload
|
|
371
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
372
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
373
|
+
{
|
|
374
|
+
#if SOLID_NATIVE_CAUSAL_DEBUG_ACTIVE
|
|
375
|
+
if (!SolidNativeDebugValidRequestId(requestId) || ![_outstandingRequestIds containsObject:requestId]) {
|
|
376
|
+
reject(@"E_SOLID_NATIVE_DEBUG_REQUEST", @"Native debug request is invalid, unknown, or already settled.", nil);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
[_outstandingRequestIds removeObject:requestId];
|
|
380
|
+
NSData *bytes = [payload dataUsingEncoding:NSUTF8StringEncoding];
|
|
381
|
+
if (bytes.length == 0 || bytes.length > SolidNativeDebugMaximumSnapshotBytes) {
|
|
382
|
+
reject(@"E_SOLID_NATIVE_DEBUG_PAYLOAD", @"Native debug response is empty or exceeds 16777216 UTF-8 bytes.", nil);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
NSError *error;
|
|
386
|
+
NSURL *directory = SolidNativeDebugResponseDirectoryURL();
|
|
387
|
+
if (![NSFileManager.defaultManager createDirectoryAtURL:directory
|
|
388
|
+
withIntermediateDirectories:YES
|
|
389
|
+
attributes:nil
|
|
390
|
+
error:&error] ||
|
|
391
|
+
![bytes writeToURL:SolidNativeDebugResponseURL(requestId)
|
|
392
|
+
options:NSDataWritingAtomic
|
|
393
|
+
error:&error]) {
|
|
394
|
+
reject(@"E_SOLID_NATIVE_DEBUG_WRITE", @"Could not publish the native debug response.", error);
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
@synchronized(SolidNativeDebugModule.class) {
|
|
398
|
+
NSMutableOrderedSet<NSString *> *published = SolidNativeDebugPublishedRequests();
|
|
399
|
+
[published removeObject:requestId];
|
|
400
|
+
while (published.count >= SolidNativeDebugMaximumPendingRequests) {
|
|
401
|
+
NSString *evictedRequestId = published.firstObject;
|
|
402
|
+
[published removeObjectAtIndex:0];
|
|
403
|
+
[NSFileManager.defaultManager removeItemAtURL:SolidNativeDebugResponseURL(evictedRequestId) error:nil];
|
|
404
|
+
}
|
|
405
|
+
[published addObject:requestId];
|
|
406
|
+
}
|
|
407
|
+
resolve(nil);
|
|
408
|
+
#else
|
|
409
|
+
(void)requestId;
|
|
410
|
+
(void)payload;
|
|
411
|
+
(void)resolve;
|
|
412
|
+
reject(@"E_SOLID_NATIVE_DEBUG_UNAVAILABLE", @"Native debug transport requires a debuggable build.", nil);
|
|
413
|
+
#endif
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
- (std::shared_ptr<TurboModule>)getTurboModule:(const ObjCTurboModule::InitParams &)params
|
|
417
|
+
{
|
|
418
|
+
return std::make_shared<NativeSolidNativeDebugSpecJSI>(params);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
@end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
|
|
3
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
4
|
+
|
|
5
|
+
/** Routes one CoreDevice payload URL into the debuggable causal snapshot module. */
|
|
6
|
+
@interface SolidNativeDebugRequest : NSObject
|
|
7
|
+
|
|
8
|
+
+ (BOOL)handleURL:(NSURL *)url NS_SWIFT_NAME(handle(url:));
|
|
9
|
+
|
|
10
|
+
@end
|
|
11
|
+
|
|
12
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
|
|
6
|
+
namespace solid_native::fabric::react_native {
|
|
7
|
+
|
|
8
|
+
// Mounted dirty nodes always have dirty ancestors. Structural mutations must
|
|
9
|
+
// invalidate both the old and new parent paths, including when a detached,
|
|
10
|
+
// already-dirty subtree is inserted into a previously clean tree.
|
|
11
|
+
template <typename Nodes>
|
|
12
|
+
void invalidateNodeAncestors(Nodes &nodes, int64_t handle) {
|
|
13
|
+
for (;;) {
|
|
14
|
+
const auto *node = nodes.get(handle);
|
|
15
|
+
if (node == nullptr) {
|
|
16
|
+
throw std::invalid_argument("Cannot invalidate a missing native node.");
|
|
17
|
+
}
|
|
18
|
+
if (node->dirty) return;
|
|
19
|
+
const auto parent = node->parent;
|
|
20
|
+
nodes.edit(handle)->dirty = true;
|
|
21
|
+
if (!parent.has_value()) return;
|
|
22
|
+
handle = *parent;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
} // namespace solid_native::fabric::react_native
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#include "SolidNativeFabricApi.h"
|
|
2
|
+
|
|
3
|
+
#include <algorithm>
|
|
4
|
+
#include <cmath>
|
|
5
|
+
#include <stdexcept>
|
|
6
|
+
|
|
7
|
+
#include <jsi/JSIDynamic.h>
|
|
8
|
+
#include <react/renderer/core/InstanceHandle.h>
|
|
9
|
+
#include <react/renderer/core/RawProps.h>
|
|
10
|
+
#include <react/renderer/mounting/ShadowTree.h>
|
|
11
|
+
#include <react/renderer/uimanager/UIManager.h>
|
|
12
|
+
|
|
13
|
+
namespace solid_native::fabric::react_native {
|
|
14
|
+
namespace {
|
|
15
|
+
|
|
16
|
+
constexpr char NativeResourceReferenceKey[] = "__solidNativeResource";
|
|
17
|
+
|
|
18
|
+
bool sameChildFamilies(
|
|
19
|
+
const ShadowNodeList &previous,
|
|
20
|
+
const ShadowNodeList &next) {
|
|
21
|
+
return previous.size() == next.size() &&
|
|
22
|
+
std::equal(
|
|
23
|
+
previous.begin(),
|
|
24
|
+
previous.end(),
|
|
25
|
+
next.begin(),
|
|
26
|
+
[](const ShadowNodePtr &left, const ShadowNodePtr &right) {
|
|
27
|
+
return ShadowNode::sameFamily(*left, *right);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const folly::dynamic *nativeResourcePayload(const folly::dynamic &value) {
|
|
32
|
+
if (!value.isObject() || value.size() != 1 ||
|
|
33
|
+
value.count(NativeResourceReferenceKey) == 0) {
|
|
34
|
+
return nullptr;
|
|
35
|
+
}
|
|
36
|
+
const auto &payload = value.at(NativeResourceReferenceKey);
|
|
37
|
+
if (!payload.isObject() || payload.size() != 2 ||
|
|
38
|
+
payload.count("handle") == 0 || payload.count("kind") == 0) {
|
|
39
|
+
throw std::invalid_argument(
|
|
40
|
+
"A native resource reference has an invalid transport shape.");
|
|
41
|
+
}
|
|
42
|
+
return &payload;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
facebook::jsi::Value rawPropsValue(
|
|
46
|
+
facebook::jsi::Runtime &runtime,
|
|
47
|
+
const folly::dynamic &props,
|
|
48
|
+
const NativeResourceResolver *resourceResolver) {
|
|
49
|
+
if (!props.isObject()) {
|
|
50
|
+
throw std::invalid_argument("Fabric props must be an object.");
|
|
51
|
+
}
|
|
52
|
+
facebook::jsi::Object result(runtime);
|
|
53
|
+
for (const auto &item : props.items()) {
|
|
54
|
+
const auto name = item.first.asString();
|
|
55
|
+
const auto *resource = nativeResourcePayload(item.second);
|
|
56
|
+
if (resource == nullptr) {
|
|
57
|
+
result.setProperty(
|
|
58
|
+
runtime,
|
|
59
|
+
name.c_str(),
|
|
60
|
+
facebook::jsi::valueFromDynamic(runtime, item.second));
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (resourceResolver == nullptr) {
|
|
64
|
+
throw std::invalid_argument(
|
|
65
|
+
"Native resource props require an owning JSI runtime registry.");
|
|
66
|
+
}
|
|
67
|
+
const auto &handleValue = resource->at("handle");
|
|
68
|
+
const auto &kindValue = resource->at("kind");
|
|
69
|
+
if ((!handleValue.isInt() && !handleValue.isDouble()) ||
|
|
70
|
+
!kindValue.isString()) {
|
|
71
|
+
throw std::invalid_argument(
|
|
72
|
+
"A native resource reference has an invalid handle or kind.");
|
|
73
|
+
}
|
|
74
|
+
const auto handleNumber = handleValue.asDouble();
|
|
75
|
+
if (!std::isfinite(handleNumber) ||
|
|
76
|
+
std::trunc(handleNumber) != handleNumber || handleNumber <= 0 ||
|
|
77
|
+
handleNumber > 9007199254740991.0) {
|
|
78
|
+
throw std::invalid_argument(
|
|
79
|
+
"A native resource reference handle must be a positive safe integer.");
|
|
80
|
+
}
|
|
81
|
+
result.setProperty(
|
|
82
|
+
runtime,
|
|
83
|
+
name.c_str(),
|
|
84
|
+
(*resourceResolver)(
|
|
85
|
+
runtime,
|
|
86
|
+
static_cast<int64_t>(handleNumber),
|
|
87
|
+
kindValue.getString()));
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
} // namespace
|
|
93
|
+
|
|
94
|
+
ShadowNodePtr FabricApi::createNode(
|
|
95
|
+
facebook::react::UIManager &uiManager,
|
|
96
|
+
facebook::react::Tag tag,
|
|
97
|
+
const std::string &componentName,
|
|
98
|
+
facebook::react::SurfaceId surfaceId,
|
|
99
|
+
const folly::dynamic &props,
|
|
100
|
+
std::shared_ptr<const facebook::react::InstanceHandle> instanceHandle,
|
|
101
|
+
facebook::jsi::Runtime *runtime,
|
|
102
|
+
const NativeResourceResolver *resourceResolver) {
|
|
103
|
+
if (runtime != nullptr) {
|
|
104
|
+
auto value = rawPropsValue(*runtime, props, resourceResolver);
|
|
105
|
+
return uiManager.createNode(
|
|
106
|
+
tag,
|
|
107
|
+
componentName,
|
|
108
|
+
surfaceId,
|
|
109
|
+
facebook::react::RawProps{*runtime, value},
|
|
110
|
+
std::move(instanceHandle));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The native-only feasibility harness deliberately has no JavaScript
|
|
114
|
+
// runtime. Keep RN's legacy dynamic mode isolated to that diagnostic path;
|
|
115
|
+
// all application commits provide their owning JSI runtime above.
|
|
116
|
+
return uiManager.createNode(
|
|
117
|
+
tag,
|
|
118
|
+
componentName,
|
|
119
|
+
surfaceId,
|
|
120
|
+
facebook::react::RawProps{props},
|
|
121
|
+
std::move(instanceHandle));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
ShadowNodePtr FabricApi::cloneNode(
|
|
125
|
+
facebook::react::UIManager &uiManager,
|
|
126
|
+
const ShadowNode &node,
|
|
127
|
+
std::shared_ptr<const ShadowNodeList> children,
|
|
128
|
+
const folly::dynamic &props,
|
|
129
|
+
facebook::jsi::Runtime *runtime,
|
|
130
|
+
const NativeResourceResolver *resourceResolver) {
|
|
131
|
+
// Stateful Fabric views (notably TextInput and ScrollView) can advance their
|
|
132
|
+
// ShadowNode state from the native mounting thread between Solid commits.
|
|
133
|
+
// The coordinator deliberately retains immutable nodes for its own tree,
|
|
134
|
+
// so rebase every application clone onto the newest mounted member of the
|
|
135
|
+
// same family before changing props or children. Otherwise a controlled
|
|
136
|
+
// update can fork from an obsolete TextInput event count and Fabric will
|
|
137
|
+
// correctly reject the following setTextAndSelection command as stale.
|
|
138
|
+
const auto newestNode = uiManager.getNewestCloneOfShadowNode(node);
|
|
139
|
+
const auto &sourceNode = newestNode ? *newestNode : node;
|
|
140
|
+
// RN 0.87's Yoga clone path compares child counts and styles, not identity
|
|
141
|
+
// order. Passing equally styled siblings in a new order can leave layout
|
|
142
|
+
// clean and retain their old positions. For structural changes, clone empty
|
|
143
|
+
// and append through UIManager so Yoga sees the changed structure. Comparing
|
|
144
|
+
// families (not clone pointers) preserves the cheaper path when only child
|
|
145
|
+
// props/state changed. Keep the newest native state as the clone source.
|
|
146
|
+
const bool rebuildChildren = children &&
|
|
147
|
+
!sameChildFamilies(sourceNode.getChildren(), *children);
|
|
148
|
+
auto cloneChildren = rebuildChildren
|
|
149
|
+
? std::make_shared<const ShadowNodeList>()
|
|
150
|
+
: children;
|
|
151
|
+
ShadowNodePtr clone;
|
|
152
|
+
if (runtime != nullptr) {
|
|
153
|
+
auto value = rawPropsValue(*runtime, props, resourceResolver);
|
|
154
|
+
clone = uiManager.cloneNode(
|
|
155
|
+
sourceNode,
|
|
156
|
+
std::move(cloneChildren),
|
|
157
|
+
facebook::react::RawProps{*runtime, value});
|
|
158
|
+
} else {
|
|
159
|
+
clone = uiManager.cloneNode(
|
|
160
|
+
sourceNode,
|
|
161
|
+
std::move(cloneChildren),
|
|
162
|
+
facebook::react::RawProps{props});
|
|
163
|
+
}
|
|
164
|
+
if (rebuildChildren) {
|
|
165
|
+
for (const auto &child : *children) {
|
|
166
|
+
uiManager.appendChild(clone, child);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return clone;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
void FabricApi::appendChild(
|
|
173
|
+
facebook::react::UIManager &uiManager,
|
|
174
|
+
const ShadowNodePtr &parent,
|
|
175
|
+
const ShadowNodePtr &child) {
|
|
176
|
+
uiManager.appendChild(parent, child);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
void FabricApi::completeSurface(
|
|
180
|
+
facebook::react::UIManager &uiManager,
|
|
181
|
+
facebook::react::SurfaceId surfaceId,
|
|
182
|
+
std::shared_ptr<ShadowNodeList> rootChildren) {
|
|
183
|
+
uiManager.completeSurface(
|
|
184
|
+
surfaceId,
|
|
185
|
+
std::move(rootChildren),
|
|
186
|
+
{
|
|
187
|
+
.enableStateReconciliation = true,
|
|
188
|
+
.mountSynchronously = true,
|
|
189
|
+
.source = facebook::react::ShadowTree::CommitSource::Unknown,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
int64_t FabricApi::currentRevisionNumber(
|
|
194
|
+
facebook::react::UIManager &uiManager,
|
|
195
|
+
facebook::react::SurfaceId surfaceId) {
|
|
196
|
+
int64_t revision = 0;
|
|
197
|
+
const auto found = uiManager.getShadowTreeRegistry().visit(
|
|
198
|
+
surfaceId, [&revision](const facebook::react::ShadowTree &shadowTree) {
|
|
199
|
+
revision = shadowTree.getCurrentRevision().number;
|
|
200
|
+
});
|
|
201
|
+
if (!found) {
|
|
202
|
+
throw std::runtime_error(
|
|
203
|
+
"Fabric did not expose the committed surface revision.");
|
|
204
|
+
}
|
|
205
|
+
return revision;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
void FabricApi::dispatchCommand(
|
|
209
|
+
facebook::react::UIManager &uiManager,
|
|
210
|
+
const ShadowNodePtr &node,
|
|
211
|
+
const std::string &command,
|
|
212
|
+
const folly::dynamic &args) {
|
|
213
|
+
const auto newestNode = uiManager.getNewestCloneOfShadowNode(*node);
|
|
214
|
+
uiManager.dispatchCommand(newestNode ? newestNode : node, command, args);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
void FabricApi::sendAccessibilityFocus(
|
|
218
|
+
facebook::react::UIManager &uiManager,
|
|
219
|
+
const ShadowNodePtr &node) {
|
|
220
|
+
const auto newestNode = uiManager.getNewestCloneOfShadowNode(*node);
|
|
221
|
+
uiManager.sendAccessibilityEvent(newestNode ? newestNode : node, "focus");
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
} // namespace solid_native::fabric::react_native
|