react-native-yoga-jsi 0.7.7

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 (69) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +166 -0
  3. package/android/CMakeLists.txt +72 -0
  4. package/android/build.gradle +190 -0
  5. package/android/gradle.properties +6 -0
  6. package/android/src/main/AndroidManifestNew.xml +3 -0
  7. package/android/src/main/cpp/cpp-adapter.cpp +17 -0
  8. package/android/src/main/java/com/yogajsi/YogaJSIModule.java +51 -0
  9. package/android/src/main/java/com/yogajsi/YogaJSIPackage.java +25 -0
  10. package/cpp/configCreation.h +91 -0
  11. package/cpp/macros.h +111 -0
  12. package/cpp/nodeCreation.h +65 -0
  13. package/cpp/nodeProperties.h +609 -0
  14. package/cpp/yogaJSI.h +23 -0
  15. package/ios/YogaJSIModule.h +5 -0
  16. package/ios/YogaJSIModule.mm +40 -0
  17. package/lib/commonjs/coreTypes.js +133 -0
  18. package/lib/commonjs/coreTypes.js.map +1 -0
  19. package/lib/commonjs/derived/index.js +39 -0
  20. package/lib/commonjs/derived/index.js.map +1 -0
  21. package/lib/commonjs/derived/styleHandler.js +326 -0
  22. package/lib/commonjs/derived/styleHandler.js.map +1 -0
  23. package/lib/commonjs/derived/useOnDepsChaneg.js +20 -0
  24. package/lib/commonjs/derived/useOnDepsChaneg.js.map +1 -0
  25. package/lib/commonjs/derived/useStyle.js +52 -0
  26. package/lib/commonjs/derived/useStyle.js.map +1 -0
  27. package/lib/commonjs/derived/utils.js +67 -0
  28. package/lib/commonjs/derived/utils.js.map +1 -0
  29. package/lib/commonjs/index.js +46 -0
  30. package/lib/commonjs/index.js.map +1 -0
  31. package/lib/commonjs/package.json +1 -0
  32. package/lib/module/coreTypes.js +129 -0
  33. package/lib/module/coreTypes.js.map +1 -0
  34. package/lib/module/derived/index.js +6 -0
  35. package/lib/module/derived/index.js.map +1 -0
  36. package/lib/module/derived/styleHandler.js +322 -0
  37. package/lib/module/derived/styleHandler.js.map +1 -0
  38. package/lib/module/derived/useOnDepsChaneg.js +17 -0
  39. package/lib/module/derived/useOnDepsChaneg.js.map +1 -0
  40. package/lib/module/derived/useStyle.js +49 -0
  41. package/lib/module/derived/useStyle.js.map +1 -0
  42. package/lib/module/derived/utils.js +61 -0
  43. package/lib/module/derived/utils.js.map +1 -0
  44. package/lib/module/index.js +21 -0
  45. package/lib/module/index.js.map +1 -0
  46. package/lib/module/package.json +1 -0
  47. package/lib/typescript/src/coreTypes.d.ts +259 -0
  48. package/lib/typescript/src/coreTypes.d.ts.map +1 -0
  49. package/lib/typescript/src/derived/index.d.ts +4 -0
  50. package/lib/typescript/src/derived/index.d.ts.map +1 -0
  51. package/lib/typescript/src/derived/styleHandler.d.ts +69 -0
  52. package/lib/typescript/src/derived/styleHandler.d.ts.map +1 -0
  53. package/lib/typescript/src/derived/useOnDepsChaneg.d.ts +3 -0
  54. package/lib/typescript/src/derived/useOnDepsChaneg.d.ts.map +1 -0
  55. package/lib/typescript/src/derived/useStyle.d.ts +15 -0
  56. package/lib/typescript/src/derived/useStyle.d.ts.map +1 -0
  57. package/lib/typescript/src/derived/utils.d.ts +21 -0
  58. package/lib/typescript/src/derived/utils.d.ts.map +1 -0
  59. package/lib/typescript/src/index.d.ts +6 -0
  60. package/lib/typescript/src/index.d.ts.map +1 -0
  61. package/package.json +147 -0
  62. package/react-native-yoga-jsi.podspec +40 -0
  63. package/src/coreTypes.ts +298 -0
  64. package/src/derived/index.ts +3 -0
  65. package/src/derived/styleHandler.ts +433 -0
  66. package/src/derived/useOnDepsChaneg.ts +20 -0
  67. package/src/derived/useStyle.ts +79 -0
  68. package/src/derived/utils.ts +86 -0
  69. package/src/index.ts +22 -0
@@ -0,0 +1,609 @@
1
+ #ifndef NODE_PROPERTIES_H
2
+ #define NODE_PROPERTIES_H
3
+
4
+ #include <jsi/jsi.h>
5
+ #include <yoga/Yoga.h>
6
+ #include "macros.h"
7
+
8
+ #define INSTALL_HOST_FUN(funcName, argCount, body) \
9
+ auto funcName = Function::createFromHostFunction(rt, \
10
+ PropNameID::forAscii(rt, #funcName), \
11
+ argCount, \
12
+ [node](Runtime & runtime, const Value &thisValue, const Value *arguments, size_t count) -> Value body); \
13
+ nodeObject.setProperty(rt, #funcName, std::move(funcName));
14
+
15
+ using namespace facebook::jsi;
16
+
17
+ namespace nodeProperties
18
+ {
19
+
20
+ void set(Object &nodeObject, Runtime &rt, YGNodeRef node)
21
+ {
22
+ INSTALL_HOST_FUN(setWidth, 1, {
23
+ SET_AUTO_PERCENT_NUMBER(YGNodeStyleSetWidthAuto, YGNodeStyleSetWidthPercent, YGNodeStyleSetWidth);
24
+ });
25
+
26
+ INSTALL_HOST_FUN(setWidthAuto, 0, {
27
+ YGNodeStyleSetWidthAuto(node);
28
+ return Value::undefined();
29
+ });
30
+
31
+ INSTALL_HOST_FUN(setWidthPercent, 1, {
32
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetWidthAuto(node), YGNodeStyleSetWidthPercent(node, arguments[0].getNumber()));
33
+ })
34
+
35
+ INSTALL_HOST_FUN(setMaxWidth, 1, {
36
+ ON_VALUE_PERCENT_UND_NUM(
37
+ arguments[0],
38
+ YGNodeStyleSetMaxWidthPercent(node, percentage),
39
+ YGNodeStyleSetMaxWidth(node, YGUndefined),
40
+ YGNodeStyleSetMaxWidth(node, arguments[0].getNumber()));
41
+ })
42
+
43
+ INSTALL_HOST_FUN(setMaxWidthPercent, 1, {
44
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetMaxWidthPercent(node, YGUndefined), YGNodeStyleSetMaxWidthPercent(node, arguments[0].getNumber()));
45
+ })
46
+
47
+ INSTALL_HOST_FUN(setMinWidth, 1, {
48
+ ON_VALUE_PERCENT_UND_NUM(
49
+ arguments[0],
50
+ YGNodeStyleSetMinWidthPercent(node, percentage),
51
+ YGNodeStyleSetMinWidth(node, YGUndefined),
52
+ YGNodeStyleSetMinWidth(node, arguments[0].getNumber()));
53
+ })
54
+
55
+ INSTALL_HOST_FUN(setMinWidthPercent, 1, {
56
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetMinWidthPercent(node, YGUndefined), YGNodeStyleSetMinWidthPercent(node, arguments[0].getNumber()));
57
+ })
58
+
59
+ INSTALL_HOST_FUN(getWidth, 0, {
60
+ SET_YGVALUE(YGNodeStyleGetWidth(node));
61
+ })
62
+
63
+ INSTALL_HOST_FUN(getMaxWidth, 0, {
64
+ SET_YGVALUE(YGNodeStyleGetMaxWidth(node));
65
+ })
66
+
67
+ INSTALL_HOST_FUN(getMinWidth, 0, {
68
+ SET_YGVALUE(YGNodeStyleGetMinWidth(node));
69
+ })
70
+
71
+ INSTALL_HOST_FUN(getComputedWidth, 0, {
72
+ RETURN_AS_DOUBLE(YGNodeLayoutGetWidth(node));
73
+ })
74
+
75
+ INSTALL_HOST_FUN(setHeight, 1, {
76
+ SET_AUTO_PERCENT_NUMBER(YGNodeStyleSetHeightAuto, YGNodeStyleSetHeightPercent, YGNodeStyleSetHeight);
77
+ });
78
+
79
+ INSTALL_HOST_FUN(setHeightAuto, 0, {
80
+ YGNodeStyleSetHeightAuto(node);
81
+ return Value::undefined();
82
+ });
83
+
84
+ INSTALL_HOST_FUN(setHeightPercent, 1, {
85
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetHeightPercent(node, YGUndefined), YGNodeStyleSetHeightPercent(node, arguments[0].getNumber()));
86
+ })
87
+
88
+ INSTALL_HOST_FUN(setMaxHeight, 1, {
89
+ ON_VALUE_PERCENT_UND_NUM(
90
+ arguments[0],
91
+ YGNodeStyleSetMaxHeightPercent(node, percentage),
92
+ YGNodeStyleSetMaxHeight(node, YGUndefined),
93
+ YGNodeStyleSetMaxHeight(node, arguments[0].getNumber()));
94
+ })
95
+
96
+ INSTALL_HOST_FUN(setMaxHeightPercent, 1, {
97
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetMaxHeightPercent(node, YGUndefined), YGNodeStyleSetMaxHeightPercent(node, arguments[0].getNumber()));
98
+ })
99
+
100
+ INSTALL_HOST_FUN(setMinHeight, 1, {
101
+ ON_VALUE_PERCENT_UND_NUM(
102
+ arguments[0],
103
+ YGNodeStyleSetMinHeightPercent(node, percentage),
104
+ YGNodeStyleSetMinHeight(node, YGUndefined),
105
+ YGNodeStyleSetMinHeight(node, arguments[0].getNumber()));
106
+ })
107
+
108
+ INSTALL_HOST_FUN(setMinHeightPercent, 1, {
109
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetMinHeightPercent(node, YGUndefined), YGNodeStyleSetMinHeightPercent(node, arguments[0].getNumber()));
110
+ })
111
+
112
+ INSTALL_HOST_FUN(getHeight, 0, {
113
+ return Value(static_cast<double>(YGNodeLayoutGetWidth(node)));
114
+ })
115
+
116
+ INSTALL_HOST_FUN(getComputedHeight, 0, {
117
+ RETURN_AS_DOUBLE(YGNodeLayoutGetHeight(node));
118
+ })
119
+
120
+ INSTALL_HOST_FUN(getMaxHeight, 0, {
121
+ SET_YGVALUE(YGNodeStyleGetMaxHeight(node));
122
+ })
123
+
124
+ INSTALL_HOST_FUN(getMinHeight, 0, {
125
+ SET_YGVALUE(YGNodeStyleGetMinHeight(node));
126
+ })
127
+
128
+ INSTALL_HOST_FUN(setPadding, 2, {
129
+ auto edge = YGEdge(arguments[0].getNumber());
130
+ printf("edge: %d\n", edge);
131
+ printf("value: %f\n", arguments[1].getNumber());
132
+ ON_VALUE_PERCENT_UND_NUM(
133
+ arguments[1],
134
+ YGNodeStyleSetPaddingPercent(node, edge, percentage),
135
+ YGNodeStyleSetPadding(node, edge, YGUndefined),
136
+ YGNodeStyleSetPadding(node, edge, arguments[1].getNumber()));
137
+ })
138
+
139
+ INSTALL_HOST_FUN(setPaddingPercent, 2, {
140
+ auto edge = YGEdge(arguments[0].getNumber());
141
+ ON_NUM_UNDEFINED(arguments[1], YGNodeStyleSetPaddingPercent(node, edge, YGUndefined), YGNodeStyleSetPaddingPercent(node, edge, arguments[1].getNumber()));
142
+ })
143
+
144
+ INSTALL_HOST_FUN(getPadding, 1, {
145
+ SET_YGVALUE(YGNodeStyleGetPadding(node, YGEdge(arguments[0].getNumber())));
146
+ })
147
+
148
+ INSTALL_HOST_FUN(getComputedPadding, 1, {
149
+ RETURN_AS_DOUBLE(YGNodeLayoutGetPadding(node, YGEdge(arguments[0].getNumber())));
150
+ })
151
+
152
+ INSTALL_HOST_FUN(setMargin, 2, {
153
+ auto edge = YGEdge(arguments[0].getNumber());
154
+ ON_VALUE_AUTO_PERCENT_UND_NUM(
155
+ arguments[1],
156
+ YGNodeStyleSetMarginAuto(node, edge),
157
+ YGNodeStyleSetMarginPercent(node, edge, percentage),
158
+ YGNodeStyleSetMargin(node, edge, YGUndefined),
159
+ YGNodeStyleSetMargin(node, edge, arguments[1].getNumber()));
160
+ })
161
+
162
+ INSTALL_HOST_FUN(setMarginAuto, 1, {
163
+ auto edge = YGEdge(arguments[0].getNumber());
164
+ YGNodeStyleSetMarginAuto(node, edge);
165
+ return Value::undefined();
166
+ })
167
+
168
+ INSTALL_HOST_FUN(setMarginPercent, 2, {
169
+ auto edge = YGEdge(arguments[0].getNumber());
170
+ ON_NUM_UNDEFINED(arguments[1], YGNodeStyleSetMarginPercent(node, edge, YGUndefined), YGNodeStyleSetMarginPercent(node, edge, arguments[1].getNumber()));
171
+ })
172
+
173
+ INSTALL_HOST_FUN(setPosition, 2, {
174
+ auto edge = YGEdge(arguments[0].getNumber());
175
+ ON_VALUE_PERCENT_UND_NUM(
176
+ arguments[1],
177
+ YGNodeStyleSetPositionPercent(node, edge, percentage),
178
+ YGNodeStyleSetPosition(node, edge, YGUndefined),
179
+ YGNodeStyleSetPosition(node, edge, arguments[1].getNumber()));
180
+ })
181
+
182
+ INSTALL_HOST_FUN(setPositionPercent, 2, {
183
+ auto edge = YGEdge(arguments[0].getNumber());
184
+ ON_NUM_UNDEFINED(arguments[1], YGNodeStyleSetPositionPercent(node, edge, YGUndefined), YGNodeStyleSetPositionPercent(node, edge, arguments[1].getNumber()));
185
+ })
186
+
187
+ INSTALL_HOST_FUN(getMargin, 1, {
188
+ SET_YGVALUE(YGNodeStyleGetMargin(node, YGEdge(arguments[0].getNumber())));
189
+ })
190
+
191
+ INSTALL_HOST_FUN(getComputedMargin, 1, {
192
+ RETURN_AS_DOUBLE(YGNodeLayoutGetMargin(node, YGEdge(arguments[0].getNumber())));
193
+ })
194
+
195
+ INSTALL_HOST_FUN(setPositionType, 1, {
196
+ YGNodeStyleSetPositionType(node, static_cast<YGPositionType>(arguments[0].getNumber()));
197
+ return Value::undefined();
198
+ });
199
+
200
+ INSTALL_HOST_FUN(getPosition, 1, {
201
+ SET_YGVALUE(YGNodeStyleGetPosition(node, YGEdge(arguments[0].getNumber())));
202
+ });
203
+
204
+ INSTALL_HOST_FUN(getPositionType, 0, {
205
+ return Value(static_cast<double>(YGNodeStyleGetPositionType(node)));
206
+ });
207
+
208
+ INSTALL_HOST_FUN(setDisplay, 1, {
209
+ YGNodeStyleSetDisplay(node, static_cast<YGDisplay>(arguments[0].getNumber()));
210
+ return Value::undefined();
211
+ });
212
+
213
+ INSTALL_HOST_FUN(getDisplay, 0, {
214
+ return Value(static_cast<double>(YGNodeStyleGetDisplay(node)));
215
+ });
216
+
217
+ INSTALL_HOST_FUN(setFlex, 1, {
218
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetFlex(node, YGUndefined), YGNodeStyleSetFlex(node, arguments[0].getNumber()));
219
+ });
220
+
221
+ INSTALL_HOST_FUN(setFlexGrow, 1, {
222
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetFlexGrow(node, YGUndefined), YGNodeStyleSetFlexGrow(node, arguments[0].getNumber()));
223
+ });
224
+
225
+ INSTALL_HOST_FUN(setFlexShrink, 1, {
226
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetFlexShrink(node, YGUndefined), YGNodeStyleSetFlexShrink(node, arguments[0].getNumber()));
227
+ });
228
+
229
+ INSTALL_HOST_FUN(setFlexBasis, 1, {
230
+ SET_AUTO_PERCENT_NUMBER(YGNodeStyleSetFlexBasisAuto, YGNodeStyleSetFlexBasisPercent, YGNodeStyleSetFlexBasis);
231
+ });
232
+
233
+ INSTALL_HOST_FUN(setFlexBasisAuto, 0, {
234
+ YGNodeStyleSetFlexBasisAuto(node);
235
+ return Value::undefined();
236
+ });
237
+
238
+ INSTALL_HOST_FUN(setFlexBasisPercent, 1, {
239
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetFlexBasisPercent(node, YGUndefined), YGNodeStyleSetFlexBasisPercent(node, arguments[0].getNumber()));
240
+ });
241
+
242
+ INSTALL_HOST_FUN(setFlexDirection, 1, {
243
+ YGNodeStyleSetFlexDirection(node, static_cast<YGFlexDirection>(arguments[0].getNumber()));
244
+ return Value::undefined();
245
+ });
246
+
247
+ INSTALL_HOST_FUN(setFlexWrap, 1, {
248
+ YGNodeStyleSetFlexWrap(node, static_cast<YGWrap>(arguments[0].getNumber()));
249
+ return Value::undefined();
250
+ });
251
+
252
+ INSTALL_HOST_FUN(getFlexBasis, 0, {
253
+ SET_YGVALUE(YGNodeStyleGetFlexBasis(node));
254
+ });
255
+
256
+ INSTALL_HOST_FUN(getFlexDirection, 0, {
257
+ return Value(static_cast<double>(YGNodeStyleGetFlexDirection(node)));
258
+ });
259
+
260
+ INSTALL_HOST_FUN(getFlexGrow, 0, {
261
+ RETURN_AS_DOUBLE(YGNodeStyleGetFlexGrow(node));
262
+ });
263
+
264
+ INSTALL_HOST_FUN(getFlexShrink, 0, {
265
+ RETURN_AS_DOUBLE(YGNodeStyleGetFlexShrink(node));
266
+ });
267
+
268
+ INSTALL_HOST_FUN(getFlexWrap, 0, {
269
+ return Value(static_cast<double>(YGNodeStyleGetFlexWrap(node)));
270
+ });
271
+
272
+ INSTALL_HOST_FUN(setDirection, 1, {
273
+ YGNodeStyleSetDirection(node, static_cast<YGDirection>(arguments[0].getNumber()));
274
+ return Value::undefined();
275
+ });
276
+
277
+ INSTALL_HOST_FUN(getDirection, 0, {
278
+ return Value(static_cast<double>(YGNodeStyleGetDirection(node)));
279
+ });
280
+
281
+ INSTALL_HOST_FUN(setBorder, 2, {
282
+ auto edge = YGEdge(arguments[0].getNumber());
283
+ ON_NUM_UNDEFINED(arguments[1], YGNodeStyleSetBorder(node, edge, YGUndefined), YGNodeStyleSetBorder(node, edge, arguments[1].getNumber()));
284
+ });
285
+
286
+ INSTALL_HOST_FUN(getBorder, 1, {
287
+ RETURN_AS_DOUBLE(YGNodeStyleGetBorder(node, YGEdge(arguments[0].getNumber())));
288
+ });
289
+
290
+ INSTALL_HOST_FUN(getComputedBorder, 1, {
291
+ RETURN_AS_DOUBLE(YGNodeLayoutGetBorder(node, YGEdge(arguments[0].getNumber())));
292
+ });
293
+
294
+ INSTALL_HOST_FUN(getComputedLayout, 0, {
295
+ auto valueObject = Object(runtime);
296
+ valueObject.setProperty(runtime, "left", YGNodeLayoutGetLeft(node));
297
+ valueObject.setProperty(runtime, "right", YGNodeLayoutGetRight(node));
298
+ valueObject.setProperty(runtime, "top", YGNodeLayoutGetTop(node));
299
+ valueObject.setProperty(runtime, "bottom", YGNodeLayoutGetBottom(node));
300
+ valueObject.setProperty(runtime, "width", YGNodeLayoutGetWidth(node));
301
+ valueObject.setProperty(runtime, "height", YGNodeLayoutGetHeight(node));
302
+ return valueObject;
303
+ });
304
+
305
+ INSTALL_HOST_FUN(getLayoutInRoot, 0, {
306
+ auto getLeftInRoot = [](YGNodeRef node) -> float
307
+ {
308
+ float left = 0.0f;
309
+ YGNodeRef current = node;
310
+ while (current != nullptr)
311
+ {
312
+ left += YGNodeLayoutGetLeft(current);
313
+ current = YGNodeGetParent(current);
314
+ }
315
+ return left;
316
+ };
317
+
318
+ auto getTopInRoot = [](YGNodeRef node) -> float
319
+ {
320
+ float top = 0.0f;
321
+ YGNodeRef current = node;
322
+ while (current != nullptr)
323
+ {
324
+ top += YGNodeLayoutGetTop(current);
325
+ current = YGNodeGetParent(current);
326
+ }
327
+ return top;
328
+ };
329
+
330
+ auto valueObject = Object(runtime);
331
+
332
+ float absoluteTop = getTopInRoot(node);
333
+ float absoluteLeft = getLeftInRoot(node);
334
+
335
+ valueObject.setProperty(runtime, "top", absoluteTop);
336
+ valueObject.setProperty(runtime, "left", absoluteLeft);
337
+ valueObject.setProperty(runtime, "width", YGNodeLayoutGetWidth(node));
338
+ valueObject.setProperty(runtime, "height", YGNodeLayoutGetHeight(node));
339
+
340
+ return valueObject;
341
+ });
342
+
343
+ INSTALL_HOST_FUN(getComputedLeft, 0, {
344
+ RETURN_AS_DOUBLE(YGNodeLayoutGetLeft(node));
345
+ });
346
+
347
+ INSTALL_HOST_FUN(getComputedRight, 0, {
348
+ RETURN_AS_DOUBLE(YGNodeLayoutGetRight(node));
349
+ });
350
+
351
+ INSTALL_HOST_FUN(getComputedTop, 0, {
352
+ RETURN_AS_DOUBLE(YGNodeLayoutGetTop(node));
353
+ });
354
+
355
+ INSTALL_HOST_FUN(getComputedBottom, 0, {
356
+ RETURN_AS_DOUBLE(YGNodeLayoutGetBottom(node));
357
+ });
358
+
359
+ INSTALL_HOST_FUN(calculateLayout, 3, {
360
+ auto ownerWidth = YGUndefined;
361
+ auto ownerHeight = YGUndefined;
362
+ auto direction = YGDirection::YGDirectionInherit;
363
+ if (count > 0 && arguments[0].isNumber())
364
+ ownerWidth = arguments[0].getNumber();
365
+
366
+ if (count > 1 && arguments[1].isNumber())
367
+ ownerHeight = arguments[1].getNumber();
368
+
369
+ if (count == 3)
370
+ direction = static_cast<YGDirection>(arguments[2].getNumber());
371
+
372
+ YGNodeCalculateLayout(node, ownerWidth, ownerHeight, direction);
373
+ return Value::undefined();
374
+ });
375
+
376
+ INSTALL_HOST_FUN(setAlignItems, 1, {
377
+ YGNodeStyleSetAlignItems(node, static_cast<YGAlign>(arguments[0].getNumber()));
378
+ return Value::undefined();
379
+ });
380
+
381
+ INSTALL_HOST_FUN(setAlignSelf, 1, {
382
+ YGNodeStyleSetAlignSelf(node, static_cast<YGAlign>(arguments[0].getNumber()));
383
+ return Value::undefined();
384
+ });
385
+
386
+ INSTALL_HOST_FUN(setAlignContent, 1, {
387
+ YGNodeStyleSetAlignContent(node, static_cast<YGAlign>(arguments[0].getNumber()));
388
+ return Value::undefined();
389
+ });
390
+
391
+ INSTALL_HOST_FUN(getAlignItems, 0, {
392
+ return Value(static_cast<double>(YGNodeStyleGetAlignItems(node)));
393
+ });
394
+
395
+ INSTALL_HOST_FUN(getAlignSelf, 0, {
396
+ return Value(static_cast<double>(YGNodeStyleGetAlignSelf(node)));
397
+ });
398
+
399
+ INSTALL_HOST_FUN(getAlignContent, 0, {
400
+ return Value(static_cast<double>(YGNodeStyleGetAlignContent(node)));
401
+ });
402
+
403
+ INSTALL_HOST_FUN(setJustifyContent, 1, {
404
+ YGNodeStyleSetJustifyContent(node, static_cast<YGJustify>(arguments[0].getNumber()));
405
+ return Value::undefined();
406
+ });
407
+
408
+ INSTALL_HOST_FUN(getJustifyContent, 0, {
409
+ return Value(static_cast<double>(YGNodeStyleGetJustifyContent(node)));
410
+ });
411
+
412
+ INSTALL_HOST_FUN(setOverflow, 1, {
413
+ YGNodeStyleSetOverflow(node, static_cast<YGOverflow>(arguments[0].getNumber()));
414
+ return Value::undefined();
415
+ });
416
+
417
+ INSTALL_HOST_FUN(getOverflow, 0, {
418
+ return Value(static_cast<double>(YGNodeStyleGetOverflow(node)));
419
+ });
420
+
421
+ INSTALL_HOST_FUN(setAspectRatio, 1, {
422
+ ON_NUM_UNDEFINED(arguments[0], YGNodeStyleSetAspectRatio(node, YGUndefined), YGNodeStyleSetAspectRatio(node, arguments[0].getNumber()));
423
+ });
424
+
425
+ INSTALL_HOST_FUN(getAspectRatio, 0, {
426
+ RETURN_AS_DOUBLE(YGNodeStyleGetAspectRatio(node));
427
+ });
428
+
429
+ INSTALL_HOST_FUN(free, 0, {
430
+ YGNodeFree(node);
431
+ return Value::undefined();
432
+ });
433
+
434
+ INSTALL_HOST_FUN(freeRecursive, 0, {
435
+ YGNodeFreeRecursive(node);
436
+ return Value::undefined();
437
+ });
438
+
439
+ INSTALL_HOST_FUN(isDirty, 0, {
440
+ return Value(YGNodeIsDirty(node));
441
+ });
442
+
443
+ INSTALL_HOST_FUN(markDirty, 0, {
444
+ YGNodeMarkDirty(node);
445
+ return Value::undefined();
446
+ });
447
+
448
+ INSTALL_HOST_FUN(reset, 0, {
449
+ YGNodeReset(node);
450
+ return Value::undefined();
451
+ });
452
+
453
+ INSTALL_HOST_FUN(markLayoutSeen, 0, {
454
+ YGNodeSetHasNewLayout(node, false);
455
+ return Value::undefined();
456
+ });
457
+
458
+ INSTALL_HOST_FUN(copyStyle, 1, {
459
+ READ_NODE(arguments[0].asObject(runtime));
460
+ YGNodeCopyStyle(node, nodeFromRt);
461
+
462
+ return Value::undefined();
463
+ });
464
+
465
+ INSTALL_HOST_FUN(getChildCount, 0, {
466
+ RETURN_AS_DOUBLE(YGNodeGetChildCount(node));
467
+ });
468
+
469
+ INSTALL_HOST_FUN(insertChild, 2, {
470
+ auto index = arguments[1].getNumber();
471
+ READ_NODE(arguments[0].asObject(runtime));
472
+ YGNodeInsertChild(node, nodeFromRt, index);
473
+ return Value::undefined();
474
+ });
475
+
476
+ INSTALL_HOST_FUN(getChild, 1, {
477
+ auto index = arguments[0].getNumber();
478
+ auto childNode = YGNodeGetChild(node, index);
479
+ auto childNodeObj = Object(runtime);
480
+ set(childNodeObj, runtime, childNode);
481
+ return childNodeObj;
482
+ });
483
+
484
+ INSTALL_HOST_FUN(removeChild, 1, {
485
+ READ_NODE(arguments[0].asObject(runtime));
486
+ YGNodeRemoveChild(node, nodeFromRt);
487
+ return Value::undefined();
488
+ });
489
+
490
+ INSTALL_HOST_FUN(getParent, 0, {
491
+ auto parentNode = YGNodeGetParent(node);
492
+ if (!parentNode)
493
+ return Value::null();
494
+ auto parentNodeObj = Object(runtime);
495
+ set(parentNodeObj, runtime, parentNode);
496
+ return parentNodeObj;
497
+ });
498
+
499
+ // INSTALL_HOST_FUN(getOwner, 0, {
500
+ // auto ownerNode = YGNodeGetOwner(node);
501
+ // if (!ownerNode)
502
+ // return Value::null();
503
+ // auto ownerNodeObj = Object(runtime);
504
+ // setNodeNodee(ownerNodeObj, runtime, ownerNode);
505
+ // return ownerNodeObj;
506
+ // });
507
+
508
+ INSTALL_HOST_FUN(isReferenceBaseline, 0, {
509
+ return Value(YGNodeIsReferenceBaseline(node));
510
+ });
511
+
512
+ INSTALL_HOST_FUN(setIsReferenceBaseline, 1, {
513
+ YGNodeSetIsReferenceBaseline(node, arguments[0].getBool());
514
+ return Value::undefined();
515
+ });
516
+
517
+ INSTALL_HOST_FUN(hasNewLayout, 0, {
518
+ return Value(YGNodeGetHasNewLayout(node));
519
+ });
520
+
521
+ INSTALL_HOST_FUN(unsetDirtiedFunc, 0, {
522
+ YGNodeSetDirtiedFunc(node, nullptr);
523
+ return Value::undefined();
524
+ });
525
+
526
+ INSTALL_HOST_FUN(unsetMeasureFunc, 0, {
527
+ YGNodeSetMeasureFunc(node, nullptr);
528
+ return Value::undefined();
529
+ });
530
+
531
+ // #ifdef YGNodeStyleSetGap
532
+ INSTALL_HOST_FUN(setGap, 2, {
533
+ YGNodeStyleSetGap(node, static_cast<YGGutter>(arguments[0].getNumber()), arguments[1].getNumber());
534
+ return Value::undefined();
535
+ });
536
+
537
+ INSTALL_HOST_FUN(getGap, 1, {
538
+ auto gap = YGNodeStyleGetGap(node, static_cast<YGGutter>(arguments[0].getNumber()));
539
+ return Value(static_cast<double>(gap));
540
+ });
541
+
542
+ INSTALL_HOST_FUN(setDirtiedFunc, 1, {
543
+ auto dirtiedFunc = std::make_shared<Function>(arguments[0].asObject(runtime).asFunction(runtime));
544
+
545
+ YGNodeSetDirtiedFunc(node, [](YGNodeRef node)
546
+ {
547
+ auto *context = static_cast<std::pair<std::shared_ptr<Function>, Runtime*> *>(YGNodeGetContext(node));
548
+ if (!context)
549
+ {
550
+ return;
551
+ }
552
+
553
+ auto &dirtiedFunc = context->first;
554
+ auto *runtime = context->second;
555
+ if (dirtiedFunc && runtime)
556
+ {
557
+ dirtiedFunc->call(*runtime);
558
+ } });
559
+
560
+ YGNodeSetContext(node, new std::pair<std::shared_ptr<Function>, Runtime *>(dirtiedFunc, &runtime));
561
+ return Value::undefined();
562
+ })
563
+
564
+ INSTALL_HOST_FUN(setMeasureFunc, 1, {
565
+ auto measureFunc = std::make_shared<Function>(arguments[0].asObject(runtime).asFunction(runtime));
566
+
567
+ YGNodeSetMeasureFunc(node, [](YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) -> YGSize
568
+ {
569
+ auto *context = static_cast<std::pair<std::shared_ptr<Function>, Runtime*> *>(YGNodeGetContext(node));
570
+ if (!context)
571
+ {
572
+ return YGSize{width, height};
573
+ }
574
+
575
+ auto &measureFunc = context->first;
576
+ auto *runtime = context->second;
577
+
578
+ if (!measureFunc || !runtime)
579
+ {
580
+ return YGSize{width, height};
581
+ }
582
+
583
+ Value widthValue(static_cast<double>(width));
584
+ Value heightValue(static_cast<double>(height));
585
+ Value widthModeValue(static_cast<double>(widthMode));
586
+ Value heightModeValue(static_cast<double>(heightMode));
587
+
588
+ auto result = measureFunc->call(*runtime, widthValue, widthModeValue, heightValue, heightModeValue);
589
+
590
+ auto resultObj = result.asObject(*runtime);
591
+ float measuredWidth = resultObj.getProperty(*runtime, "width").asNumber();
592
+ float measuredHeight = resultObj.getProperty(*runtime, "height").asNumber();
593
+
594
+ return YGSize{measuredWidth, measuredHeight}; });
595
+
596
+ YGNodeSetContext(node, new std::pair<std::shared_ptr<Function>, Runtime *>(measureFunc, &runtime));
597
+
598
+ return Value::undefined();
599
+ })
600
+
601
+ std::uintptr_t nodePtr = reinterpret_cast<std::uintptr_t>(node);
602
+ char buffer[20];
603
+ std::snprintf(buffer, sizeof(buffer), "%lx", nodePtr);
604
+ std::string nodeStr(buffer);
605
+ nodeObject.setProperty(rt, "__node__", nodeStr);
606
+ }
607
+ }
608
+
609
+ #endif // NODE_PROPERTIES_H
package/cpp/yogaJSI.h ADDED
@@ -0,0 +1,23 @@
1
+ #ifndef YOGA_JSI_H
2
+ #define YOGA_JSI_H
3
+
4
+ #include <jsi/jsi.h>
5
+
6
+ #include "nodeCreation.h"
7
+ #include "configCreation.h"
8
+
9
+ namespace yogaJSI
10
+ {
11
+ void install(facebook::jsi::Runtime &rt)
12
+ {
13
+ auto yogaJSi = facebook::jsi::Object(rt);
14
+
15
+ nodeCreation::setNodeCreationObj(yogaJSi, rt);
16
+ configCreation::setConfigCreationObj(yogaJSi, rt);
17
+
18
+ rt.global()
19
+ .setProperty(rt, "Yoga", std::move(yogaJSi));
20
+ }
21
+ }
22
+
23
+ #endif
@@ -0,0 +1,5 @@
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface QuickCryptoModule : NSObject <RCTBridgeModule>
4
+
5
+ @end
@@ -0,0 +1,40 @@
1
+ #import "YogaJSIModule.h"
2
+
3
+ #import <React/RCTBridge+Private.h>
4
+ #import <React/RCTUtils.h>
5
+ #import <ReactCommon/RCTTurboModule.h>
6
+ #import <jsi/jsi.h>
7
+ #import "../cpp/yogaJSI.h"
8
+
9
+
10
+ @implementation QuickCryptoModule
11
+
12
+ @synthesize bridge=_bridge;
13
+
14
+ RCT_EXPORT_MODULE(YogaJSI)
15
+
16
+ - (void)setBridge:(RCTBridge *)bridge {
17
+ _bridge = bridge;
18
+ }
19
+
20
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
21
+ NSLog(@"Installing JSI bindings for react-native-quick-crypto...");
22
+ RCTCxxBridge* cxxBridge = (RCTCxxBridge*)_bridge;
23
+ if (cxxBridge == nil) {
24
+ return @false;
25
+ }
26
+
27
+ using namespace facebook;
28
+
29
+ auto jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
30
+ if (jsiRuntime == nil) {
31
+ return @false;
32
+ }
33
+
34
+ yogaJSI::install(*(facebook::jsi::Runtime *)jsiRuntime);
35
+
36
+ NSLog(@"Successfully installed JSI bindings for react-native-quick-crypto!");
37
+ return @true;
38
+ }
39
+
40
+ @end