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
package/cpp/macros.h ADDED
@@ -0,0 +1,111 @@
1
+ #ifndef RN_YOGA_MACROS_H
2
+ #define RN_YOGA_MACROS_H
3
+
4
+ // #define CREATE_INSTALL_HOST_FUN(funcName, argCount, scopeVar, rt, where, body) \
5
+ // auto funcName = Function::createFromHostFunction(rt, \
6
+ // PropNameID::forAscii(rt, #funcName), \
7
+ // argCount, \
8
+ // [scopeVar](Runtime & runtime, const Value &thisValue, const Value *arguments, size_t count) -> Value body); \
9
+ // where.setProperty(rt, #funcName, move(funcName));
10
+
11
+ // #define INSTALL_HOST_FUN_TO_CONFIG(funcName, argCount, body) \
12
+ // CREATE_INSTALL_HOST_FUN(funcName, argCount, body, config, jsiRuntime, configObject)
13
+
14
+ // // #define INSTALL_HOST_FUN(funcName, argCount, body) \
15
+ // // CREATE_INSTALL_HOST_FUN(funcName, argCount, body, node, runtime, nodeObject)
16
+
17
+ #define SET_AUTO_PERCENT_NUMBER(autoSetter, percentSetter, numberSetter) \
18
+ if (arguments[0].isString()) \
19
+ { \
20
+ std::string stringValue = arguments[0].getString(runtime).utf8(runtime); \
21
+ if (stringValue == "auto") \
22
+ { \
23
+ autoSetter(node); \
24
+ } \
25
+ else \
26
+ { \
27
+ float percentage = std::stof(stringValue.substr(0, stringValue.size() - 1)); \
28
+ percentSetter(node, percentage); \
29
+ } \
30
+ } \
31
+ else if (arguments[0].isUndefined()) \
32
+ { \
33
+ numberSetter(node, YGUndefined); \
34
+ } \
35
+ else \
36
+ { \
37
+ numberSetter(node, arguments[0].getNumber()); \
38
+ } \
39
+ return Value::undefined();
40
+
41
+ #define ON_VALUE_PERCENT_UND_NUM(arg, onPercentage, onUndefined, onNumber) \
42
+ if (arg.isString()) \
43
+ { \
44
+ std::string stringValue = arguments[0].getString(runtime).utf8(runtime); \
45
+ float percentage = std::stof(stringValue.substr(0, stringValue.size() - 1)); \
46
+ onPercentage; \
47
+ } \
48
+ else if (arg.isUndefined()) \
49
+ { \
50
+ onUndefined; \
51
+ } \
52
+ else \
53
+ { \
54
+ onNumber; \
55
+ } \
56
+ return Value::undefined();
57
+
58
+ #define ON_VALUE_AUTO_PERCENT_UND_NUM(arg, onAuto, onPercentage, onUndefined, onNumber) \
59
+ if (arg.isString()) \
60
+ { \
61
+ std::string stringValue = arguments[0].getString(runtime).utf8(runtime); \
62
+ if (stringValue == "auto") \
63
+ onAuto; \
64
+ else \
65
+ { \
66
+ float percentage = std::stof(stringValue.substr(0, stringValue.size() - 1)); \
67
+ onPercentage; \
68
+ } \
69
+ } \
70
+ else if (arg.isUndefined()) \
71
+ { \
72
+ onUndefined; \
73
+ } \
74
+ else \
75
+ { \
76
+ onNumber; \
77
+ } \
78
+ return Value::undefined();
79
+
80
+ #define ON_NUM_UNDEFINED(arg, onNumber, onUndefined) \
81
+ if (arg.isUndefined()) \
82
+ { \
83
+ onUndefined; \
84
+ } \
85
+ else \
86
+ { \
87
+ onNumber; \
88
+ } \
89
+ return Value::undefined();
90
+
91
+ #define RETURN_AS_DOUBLE(value) \
92
+ return Value(static_cast<double>(value))
93
+
94
+ #define SET_YGVALUE(ygValueGetter) \
95
+ auto ygValue = ygValueGetter; \
96
+ auto valueObject = Object(runtime); \
97
+ valueObject.setProperty(runtime, "value", facebook::jsi::Value(static_cast<double>(ygValue.value))); \
98
+ valueObject.setProperty(runtime, "unit", facebook::jsi::Value(static_cast<int>(ygValue.unit))); \
99
+ return valueObject;
100
+
101
+ #define READ_CONFIG(arg) \
102
+ std::string configStr = arg.asObject(runtime).getProperty(runtime, "__config__").asString(runtime).utf8(runtime); \
103
+ std::uintptr_t configPtr = std::strtoul(configStr.c_str(), nullptr, 16); \
104
+ auto config = reinterpret_cast<YGConfigRef>(configPtr);
105
+
106
+ #define READ_NODE(arg) \
107
+ std::string nodeStr = arg.getProperty(runtime, "__node__").asString(runtime).utf8(runtime); \
108
+ std::uintptr_t nodePtr = std::strtoul(nodeStr.c_str(), nullptr, 16); \
109
+ auto nodeFromRt = reinterpret_cast<YGNodeRef>(nodePtr);
110
+
111
+ #endif
@@ -0,0 +1,65 @@
1
+
2
+ #ifndef NODE_CREATION_H
3
+ #define NODE_CREATION_H
4
+
5
+ #include <jsi/jsi.h>
6
+ #include <yoga/Yoga.h>
7
+ #include "macros.h"
8
+ #include "nodeProperties.h"
9
+
10
+ #define INSTALL_HOST_FUN(funcName, argCount, body) \
11
+ auto funcName = Function::createFromHostFunction(rt, \
12
+ PropNameID::forAscii(rt, #funcName), \
13
+ argCount, \
14
+ [](Runtime & runtime, const Value &thisValue, const Value *arguments, size_t count) -> Value body); \
15
+ nodeCreationObject.setProperty(rt, #funcName, std::move(funcName));
16
+
17
+ using namespace facebook::jsi;
18
+
19
+ namespace nodeCreation
20
+ {
21
+ void setNodeCreationObj(facebook::jsi::Object &yogaJsi, facebook::jsi::Runtime &rt)
22
+ {
23
+ auto nodeCreationObject = facebook::jsi::Object(rt);
24
+
25
+ INSTALL_HOST_FUN(createDefault, 0, {
26
+ auto nodeObject = Object(runtime);
27
+ YGNodeRef node = YGNodeNew();
28
+ nodeProperties::set(nodeObject, runtime, node);
29
+ return nodeObject;
30
+ });
31
+
32
+ INSTALL_HOST_FUN(createWithConfig, 1, {
33
+ READ_CONFIG(arguments[0])
34
+ auto nodeObject = Object(runtime);
35
+ YGNodeRef node = YGNodeNewWithConfig(config);
36
+ nodeProperties::set(nodeObject, runtime, node);
37
+ return nodeObject;
38
+ });
39
+
40
+ INSTALL_HOST_FUN(create, 1, {
41
+ auto nodeObject = Object(runtime);
42
+ if (count > 0 && arguments[0].isObject())
43
+ {
44
+ READ_CONFIG(arguments[0])
45
+ YGNodeRef node = YGNodeNewWithConfig(config);
46
+ nodeProperties::set(nodeObject, runtime, node);
47
+ }
48
+ else
49
+ {
50
+ YGNodeRef node = YGNodeNew();
51
+ nodeProperties::set(nodeObject, runtime, node);
52
+ }
53
+
54
+ return nodeObject;
55
+ });
56
+
57
+ INSTALL_HOST_FUN(destroy, 1, {
58
+ return Value::undefined();
59
+ })
60
+
61
+ yogaJsi.setProperty(rt, "Node", std::move(nodeCreationObject));
62
+ }
63
+ }
64
+
65
+ #endif