@shopify/react-native-skia 1.11.1 → 1.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (266) hide show
  1. package/android/CMakeLists.txt +0 -8
  2. package/android/cpp/jni/JniLoad.cpp +0 -2
  3. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -1
  4. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +4 -2
  5. package/cpp/jsi/ViewProperty.h +5 -16
  6. package/cpp/rnskia/RNSkManager.cpp +1 -7
  7. package/lib/commonjs/dom/nodes/index.d.ts +0 -1
  8. package/lib/commonjs/dom/nodes/index.js +0 -11
  9. package/lib/commonjs/dom/nodes/index.js.map +1 -1
  10. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +0 -6
  11. package/lib/commonjs/external/reanimated/renderHelpers.js +0 -73
  12. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  13. package/lib/commonjs/index.d.ts +0 -1
  14. package/lib/commonjs/index.js +0 -12
  15. package/lib/commonjs/index.js.map +1 -1
  16. package/lib/commonjs/renderer/Canvas.d.ts +10 -1
  17. package/lib/commonjs/renderer/Canvas.js +3 -1
  18. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  19. package/lib/commonjs/sksg/Container.d.ts +2 -0
  20. package/lib/commonjs/sksg/Container.js +10 -0
  21. package/lib/commonjs/sksg/Container.js.map +1 -1
  22. package/lib/commonjs/sksg/Elements.d.ts +65 -0
  23. package/lib/commonjs/sksg/Elements.js +6 -0
  24. package/lib/commonjs/sksg/Elements.js.map +1 -0
  25. package/lib/commonjs/sksg/Reconciler.d.ts +1 -0
  26. package/lib/commonjs/sksg/Reconciler.js +2 -0
  27. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  28. package/lib/commonjs/views/index.d.ts +0 -1
  29. package/lib/commonjs/views/index.js +0 -11
  30. package/lib/commonjs/views/index.js.map +1 -1
  31. package/lib/module/dom/nodes/index.d.ts +0 -1
  32. package/lib/module/dom/nodes/index.js +0 -1
  33. package/lib/module/dom/nodes/index.js.map +1 -1
  34. package/lib/module/external/reanimated/renderHelpers.d.ts +0 -6
  35. package/lib/module/external/reanimated/renderHelpers.js +0 -68
  36. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  37. package/lib/module/index.d.ts +0 -1
  38. package/lib/module/index.js +0 -1
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/renderer/Canvas.d.ts +10 -1
  41. package/lib/module/renderer/Canvas.js +1 -0
  42. package/lib/module/renderer/Canvas.js.map +1 -1
  43. package/lib/module/sksg/Container.d.ts +2 -0
  44. package/lib/module/sksg/Container.js +10 -0
  45. package/lib/module/sksg/Container.js.map +1 -1
  46. package/lib/module/sksg/Elements.d.ts +65 -0
  47. package/lib/module/sksg/Elements.js +2 -0
  48. package/lib/module/sksg/Elements.js.map +1 -0
  49. package/lib/module/sksg/Reconciler.d.ts +1 -0
  50. package/lib/module/sksg/Reconciler.js +2 -0
  51. package/lib/module/sksg/Reconciler.js.map +1 -1
  52. package/lib/module/views/index.d.ts +0 -1
  53. package/lib/module/views/index.js +0 -1
  54. package/lib/module/views/index.js.map +1 -1
  55. package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +0 -3
  56. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +1 -0
  57. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +2 -0
  58. package/lib/typescript/lib/commonjs/sksg/Elements.d.ts +1 -0
  59. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +6 -0
  60. package/lib/typescript/lib/module/dom/nodes/index.d.ts +0 -1
  61. package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +0 -3
  62. package/lib/typescript/lib/module/index.d.ts +0 -1
  63. package/lib/typescript/lib/module/mock/index.d.ts +0 -1
  64. package/lib/typescript/lib/module/renderer/Canvas.d.ts +1 -0
  65. package/lib/typescript/lib/module/sksg/Container.d.ts +2 -0
  66. package/lib/typescript/lib/module/sksg/Elements.d.ts +1 -0
  67. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +6 -0
  68. package/lib/typescript/lib/module/views/index.d.ts +0 -1
  69. package/lib/typescript/src/dom/nodes/index.d.ts +0 -1
  70. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +0 -6
  71. package/lib/typescript/src/index.d.ts +0 -1
  72. package/lib/typescript/src/renderer/Canvas.d.ts +10 -1
  73. package/lib/typescript/src/sksg/Container.d.ts +2 -0
  74. package/lib/typescript/src/sksg/Elements.d.ts +65 -0
  75. package/lib/typescript/src/sksg/Reconciler.d.ts +1 -0
  76. package/lib/typescript/src/views/index.d.ts +0 -1
  77. package/package.json +1 -1
  78. package/react-native-skia.podspec +1 -1
  79. package/src/dom/nodes/index.ts +0 -1
  80. package/src/external/reanimated/renderHelpers.ts +1 -78
  81. package/src/index.ts +0 -1
  82. package/src/renderer/Canvas.tsx +11 -1
  83. package/src/sksg/Container.ts +11 -0
  84. package/src/sksg/Elements.tsx +136 -0
  85. package/src/sksg/Reconciler.ts +2 -0
  86. package/src/views/index.ts +0 -1
  87. package/android/cpp/jni/include/JniSkiaDomView.h +0 -82
  88. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomView.java +0 -41
  89. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomViewManager.java +0 -32
  90. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +0 -34
  91. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +0 -18
  92. package/cpp/rnskia/RNSkDomView.cpp +0 -121
  93. package/cpp/rnskia/RNSkDomView.h +0 -97
  94. package/cpp/rnskia/dom/JsiDomApi.h +0 -165
  95. package/cpp/rnskia/dom/base/BaseNodeProp.h +0 -72
  96. package/cpp/rnskia/dom/base/ConcatablePaint.cpp +0 -117
  97. package/cpp/rnskia/dom/base/ConcatablePaint.h +0 -49
  98. package/cpp/rnskia/dom/base/Declaration.h +0 -86
  99. package/cpp/rnskia/dom/base/DeclarationContext.h +0 -79
  100. package/cpp/rnskia/dom/base/DerivedNodeProp.h +0 -203
  101. package/cpp/rnskia/dom/base/DrawingContext.cpp +0 -55
  102. package/cpp/rnskia/dom/base/DrawingContext.h +0 -104
  103. package/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +0 -119
  104. package/cpp/rnskia/dom/base/JsiDomDrawingNode.h +0 -71
  105. package/cpp/rnskia/dom/base/JsiDomNode.h +0 -572
  106. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +0 -262
  107. package/cpp/rnskia/dom/base/NodeProp.h +0 -139
  108. package/cpp/rnskia/dom/base/NodePropsContainer.h +0 -158
  109. package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +0 -64
  110. package/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h +0 -49
  111. package/cpp/rnskia/dom/nodes/JsiBlendNode.h +0 -94
  112. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +0 -75
  113. package/cpp/rnskia/dom/nodes/JsiBoxNode.h +0 -94
  114. package/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +0 -33
  115. package/cpp/rnskia/dom/nodes/JsiCircleNode.h +0 -35
  116. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +0 -164
  117. package/cpp/rnskia/dom/nodes/JsiDiffRectNode.h +0 -37
  118. package/cpp/rnskia/dom/nodes/JsiFillNode.h +0 -22
  119. package/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +0 -53
  120. package/cpp/rnskia/dom/nodes/JsiGroupNode.h +0 -25
  121. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +0 -361
  122. package/cpp/rnskia/dom/nodes/JsiImageNode.h +0 -43
  123. package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +0 -63
  124. package/cpp/rnskia/dom/nodes/JsiLayerNode.h +0 -74
  125. package/cpp/rnskia/dom/nodes/JsiLineNode.h +0 -38
  126. package/cpp/rnskia/dom/nodes/JsiOvalNode.h +0 -32
  127. package/cpp/rnskia/dom/nodes/JsiPaintNode.h +0 -119
  128. package/cpp/rnskia/dom/nodes/JsiParagraphNode.h +0 -62
  129. package/cpp/rnskia/dom/nodes/JsiPatchNode.h +0 -50
  130. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +0 -268
  131. package/cpp/rnskia/dom/nodes/JsiPathNode.h +0 -181
  132. package/cpp/rnskia/dom/nodes/JsiPictureNode.h +0 -31
  133. package/cpp/rnskia/dom/nodes/JsiPointsNode.h +0 -48
  134. package/cpp/rnskia/dom/nodes/JsiRRectNode.h +0 -33
  135. package/cpp/rnskia/dom/nodes/JsiRectNode.h +0 -33
  136. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +0 -434
  137. package/cpp/rnskia/dom/nodes/JsiTextBlobNode.h +0 -44
  138. package/cpp/rnskia/dom/nodes/JsiTextNode.h +0 -51
  139. package/cpp/rnskia/dom/nodes/JsiTextPathNode.h +0 -33
  140. package/cpp/rnskia/dom/nodes/JsiVerticesNode.h +0 -41
  141. package/cpp/rnskia/dom/props/BezierProps.h +0 -65
  142. package/cpp/rnskia/dom/props/BlendModeProp.h +0 -103
  143. package/cpp/rnskia/dom/props/BoxShadowProps.h +0 -62
  144. package/cpp/rnskia/dom/props/CircleProp.h +0 -49
  145. package/cpp/rnskia/dom/props/ClipProp.h +0 -57
  146. package/cpp/rnskia/dom/props/ColorProp.h +0 -96
  147. package/cpp/rnskia/dom/props/FontProp.h +0 -42
  148. package/cpp/rnskia/dom/props/GlyphsProp.h +0 -55
  149. package/cpp/rnskia/dom/props/LayerProp.h +0 -52
  150. package/cpp/rnskia/dom/props/MatrixProp.h +0 -54
  151. package/cpp/rnskia/dom/props/NumbersProp.h +0 -67
  152. package/cpp/rnskia/dom/props/PaintProps.h +0 -133
  153. package/cpp/rnskia/dom/props/ParagraphProp.h +0 -45
  154. package/cpp/rnskia/dom/props/PathProp.h +0 -59
  155. package/cpp/rnskia/dom/props/PictureProp.h +0 -40
  156. package/cpp/rnskia/dom/props/PointProp.h +0 -65
  157. package/cpp/rnskia/dom/props/PointsProp.h +0 -81
  158. package/cpp/rnskia/dom/props/RRectProp.h +0 -222
  159. package/cpp/rnskia/dom/props/RSXformProp.h +0 -52
  160. package/cpp/rnskia/dom/props/RadiusProp.h +0 -43
  161. package/cpp/rnskia/dom/props/RectProp.h +0 -164
  162. package/cpp/rnskia/dom/props/SamplingProp.h +0 -54
  163. package/cpp/rnskia/dom/props/SkImageProps.h +0 -196
  164. package/cpp/rnskia/dom/props/StrokeProps.h +0 -79
  165. package/cpp/rnskia/dom/props/SvgProp.h +0 -45
  166. package/cpp/rnskia/dom/props/TextBlobProp.h +0 -133
  167. package/cpp/rnskia/dom/props/TileModeProp.h +0 -52
  168. package/cpp/rnskia/dom/props/TransformProp.h +0 -147
  169. package/cpp/rnskia/dom/props/TransformsProps.h +0 -66
  170. package/cpp/rnskia/dom/props/UniformsProp.h +0 -159
  171. package/cpp/rnskia/dom/props/VertexModeProp.h +0 -49
  172. package/cpp/rnskia/dom/props/VerticesProps.h +0 -63
  173. package/ios/RNSkia-iOS/SkiaDomView.h +0 -7
  174. package/ios/RNSkia-iOS/SkiaDomView.mm +0 -63
  175. package/ios/RNSkia-iOS/SkiaDomViewManager.h +0 -8
  176. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +0 -51
  177. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +0 -64
  178. package/lib/commonjs/dom/nodes/JsiSkDOM.js +0 -196
  179. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +0 -1
  180. package/lib/commonjs/renderer/CanvasOld.d.ts +0 -11
  181. package/lib/commonjs/renderer/CanvasOld.js +0 -96
  182. package/lib/commonjs/renderer/CanvasOld.js.map +0 -1
  183. package/lib/commonjs/renderer/Container.d.ts +0 -10
  184. package/lib/commonjs/renderer/Container.js +0 -26
  185. package/lib/commonjs/renderer/Container.js.map +0 -1
  186. package/lib/commonjs/renderer/HostComponents.d.ts +0 -129
  187. package/lib/commonjs/renderer/HostComponents.js +0 -141
  188. package/lib/commonjs/renderer/HostComponents.js.map +0 -1
  189. package/lib/commonjs/renderer/HostConfig.d.ts +0 -18
  190. package/lib/commonjs/renderer/HostConfig.js +0 -157
  191. package/lib/commonjs/renderer/HostConfig.js.map +0 -1
  192. package/lib/commonjs/renderer/Reconciler.d.ts +0 -9
  193. package/lib/commonjs/renderer/Reconciler.js +0 -44
  194. package/lib/commonjs/renderer/Reconciler.js.map +0 -1
  195. package/lib/commonjs/specs/SkiaDomViewNativeComponent.d.ts +0 -6
  196. package/lib/commonjs/specs/SkiaDomViewNativeComponent.js +0 -11
  197. package/lib/commonjs/specs/SkiaDomViewNativeComponent.js.map +0 -1
  198. package/lib/commonjs/views/SkiaDomView.d.ts +0 -33
  199. package/lib/commonjs/views/SkiaDomView.js +0 -119
  200. package/lib/commonjs/views/SkiaDomView.js.map +0 -1
  201. package/lib/commonjs/views/SkiaDomView.web.d.ts +0 -0
  202. package/lib/commonjs/views/SkiaDomView.web.js +0 -2
  203. package/lib/commonjs/views/SkiaDomView.web.js.map +0 -1
  204. package/lib/module/dom/nodes/JsiSkDOM.d.ts +0 -64
  205. package/lib/module/dom/nodes/JsiSkDOM.js +0 -189
  206. package/lib/module/dom/nodes/JsiSkDOM.js.map +0 -1
  207. package/lib/module/renderer/CanvasOld.d.ts +0 -11
  208. package/lib/module/renderer/CanvasOld.js +0 -87
  209. package/lib/module/renderer/CanvasOld.js.map +0 -1
  210. package/lib/module/renderer/Container.d.ts +0 -10
  211. package/lib/module/renderer/Container.js +0 -19
  212. package/lib/module/renderer/Container.js.map +0 -1
  213. package/lib/module/renderer/HostComponents.d.ts +0 -129
  214. package/lib/module/renderer/HostComponents.js +0 -134
  215. package/lib/module/renderer/HostComponents.js.map +0 -1
  216. package/lib/module/renderer/HostConfig.d.ts +0 -18
  217. package/lib/module/renderer/HostConfig.js +0 -150
  218. package/lib/module/renderer/HostConfig.js.map +0 -1
  219. package/lib/module/renderer/Reconciler.d.ts +0 -9
  220. package/lib/module/renderer/Reconciler.js +0 -36
  221. package/lib/module/renderer/Reconciler.js.map +0 -1
  222. package/lib/module/specs/SkiaDomViewNativeComponent.d.ts +0 -6
  223. package/lib/module/specs/SkiaDomViewNativeComponent.js +0 -4
  224. package/lib/module/specs/SkiaDomViewNativeComponent.js.map +0 -1
  225. package/lib/module/views/SkiaDomView.d.ts +0 -33
  226. package/lib/module/views/SkiaDomView.js +0 -111
  227. package/lib/module/views/SkiaDomView.js.map +0 -1
  228. package/lib/module/views/SkiaDomView.web.d.ts +0 -0
  229. package/lib/module/views/SkiaDomView.web.js +0 -2
  230. package/lib/module/views/SkiaDomView.web.js.map +0 -1
  231. package/lib/typescript/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +0 -60
  232. package/lib/typescript/lib/commonjs/renderer/CanvasOld.d.ts +0 -3
  233. package/lib/typescript/lib/commonjs/renderer/Container.d.ts +0 -9
  234. package/lib/typescript/lib/commonjs/renderer/HostComponents.d.ts +0 -2
  235. package/lib/typescript/lib/commonjs/renderer/HostConfig.d.ts +0 -40
  236. package/lib/typescript/lib/commonjs/renderer/Reconciler.d.ts +0 -10
  237. package/lib/typescript/lib/commonjs/specs/SkiaDomViewNativeComponent.d.ts +0 -3
  238. package/lib/typescript/lib/commonjs/views/SkiaDomView.d.ts +0 -30
  239. package/lib/typescript/lib/commonjs/views/SkiaDomView.web.d.ts +0 -0
  240. package/lib/typescript/lib/module/dom/nodes/JsiSkDOM.d.ts +0 -59
  241. package/lib/typescript/lib/module/renderer/CanvasOld.d.ts +0 -3
  242. package/lib/typescript/lib/module/renderer/Container.d.ts +0 -9
  243. package/lib/typescript/lib/module/renderer/HostComponents.d.ts +0 -1
  244. package/lib/typescript/lib/module/renderer/HostConfig.d.ts +0 -39
  245. package/lib/typescript/lib/module/renderer/Reconciler.d.ts +0 -9
  246. package/lib/typescript/lib/module/specs/SkiaDomViewNativeComponent.d.ts +0 -2
  247. package/lib/typescript/lib/module/views/SkiaDomView.d.ts +0 -27
  248. package/lib/typescript/lib/module/views/SkiaDomView.web.d.ts +0 -0
  249. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +0 -64
  250. package/lib/typescript/src/renderer/CanvasOld.d.ts +0 -11
  251. package/lib/typescript/src/renderer/Container.d.ts +0 -10
  252. package/lib/typescript/src/renderer/HostComponents.d.ts +0 -129
  253. package/lib/typescript/src/renderer/HostConfig.d.ts +0 -18
  254. package/lib/typescript/src/renderer/Reconciler.d.ts +0 -9
  255. package/lib/typescript/src/specs/SkiaDomViewNativeComponent.d.ts +0 -6
  256. package/lib/typescript/src/views/SkiaDomView.d.ts +0 -33
  257. package/lib/typescript/src/views/SkiaDomView.web.d.ts +0 -0
  258. package/src/dom/nodes/JsiSkDOM.ts +0 -298
  259. package/src/renderer/CanvasOld.tsx +0 -126
  260. package/src/renderer/Container.tsx +0 -19
  261. package/src/renderer/HostComponents.ts +0 -399
  262. package/src/renderer/HostConfig.ts +0 -258
  263. package/src/renderer/Reconciler.tsx +0 -54
  264. package/src/specs/SkiaDomViewNativeComponent.ts +0 -9
  265. package/src/views/SkiaDomView.tsx +0 -124
  266. package/src/views/SkiaDomView.web.tsx +0 -0
@@ -1,71 +0,0 @@
1
- #pragma once
2
-
3
- #include "JsiDomRenderNode.h"
4
- #include "JsiPaintNode.h"
5
-
6
- #include <memory>
7
-
8
- namespace RNSkia {
9
-
10
- class JsiDomDrawingNode : public JsiDomRenderNode {
11
- public:
12
- JsiDomDrawingNode(std::shared_ptr<RNSkPlatformContext> context,
13
- const char *type)
14
- : JsiDomRenderNode(context, type) {}
15
-
16
- protected:
17
- void defineProperties(NodePropsContainer *container) override {
18
- JsiDomRenderNode::defineProperties(container);
19
- _paintProp = container->defineProperty<PaintDrawingContextProp>();
20
- }
21
-
22
- /**
23
- Override to implement drawing.
24
- */
25
- virtual void draw(DrawingContext *context) = 0;
26
-
27
- void renderNode(DrawingContext *context) override {
28
- #if SKIA_DOM_DEBUG
29
- printDebugInfo("Begin Draw", 1);
30
- #endif
31
- // Save paint if the paint property is set
32
- if (_paintProp->isSet()) {
33
- auto localCtx = _paintProp->getUnsafeDerivedValue().get();
34
- localCtx->setCanvas(context->getCanvas());
35
- draw(localCtx);
36
- } else {
37
- // Call abstract draw method
38
- draw(context);
39
- }
40
-
41
- // Draw once more for each child paint node
42
- auto declarationCtx = context->getDeclarationContext();
43
- for (auto &child : getChildren()) {
44
- if (child->getNodeClass() == NodeClass::DeclarationNode &&
45
- std::static_pointer_cast<JsiDomDeclarationNode>(child)
46
- ->getDeclarationType() == DeclarationType::Paint) {
47
- auto paintNode = std::static_pointer_cast<JsiPaintNode>(child);
48
- // Draw once again with the paint
49
- declarationCtx->save();
50
- paintNode->decorate(declarationCtx);
51
- auto paint = declarationCtx->getPaints()->pop();
52
- declarationCtx->restore();
53
-
54
- // FIXME: Can we avoid creating a new drawing context here each time?
55
- auto localContext =
56
- std::make_shared<DrawingContext>(std::shared_ptr<SkPaint>(paint));
57
- localContext->setCanvas(context->getCanvas());
58
- draw(localContext.get());
59
- }
60
- }
61
-
62
- #if SKIA_DOM_DEBUG
63
- printDebugInfo("End Draw", 1);
64
- #endif
65
- }
66
-
67
- private:
68
- PaintDrawingContextProp *_paintProp;
69
- };
70
-
71
- } // namespace RNSkia
@@ -1,572 +0,0 @@
1
- #pragma once
2
-
3
- #include "JsiHostObject.h"
4
- #include "NodeProp.h"
5
- #include "NodePropsContainer.h"
6
-
7
- #include <memory>
8
- #include <string>
9
- #include <utility>
10
- #include <vector>
11
-
12
- #include "RNSkPlatformContext.h"
13
-
14
- namespace RNSkia {
15
-
16
- template <class TNode> class JsiDomNodeCtor {
17
- public:
18
- /**
19
- Constructor to add to the Api object
20
- */
21
- static const jsi::HostFunctionType
22
- createCtor(std::shared_ptr<RNSkPlatformContext> context) {
23
- return JSI_HOST_FUNCTION_LAMBDA {
24
- auto node = std::make_shared<TNode>(context);
25
- node->initializeNode(runtime, thisValue, arguments, count);
26
- return jsi::Object::createFromHostObject(runtime, std::move(node));
27
- };
28
- }
29
- };
30
-
31
- static std::atomic<size_t> NodeIdent = 1000;
32
-
33
- typedef enum {
34
- RenderNode = 1,
35
- DeclarationNode = 2,
36
- } NodeClass;
37
-
38
- /**
39
- Implements an abstract base class for nodes in the Skia Reconciler. This node
40
- coresponds to the native implementation of the Node.ts class in Javascript.
41
- */
42
- class JsiDomNode : public JsiHostObject,
43
- public std::enable_shared_from_this<JsiDomNode> {
44
- public:
45
- /**
46
- Contructor. Takes as parameters the values comming from the JS world that
47
- initialized the class.
48
- */
49
- JsiDomNode(std::shared_ptr<RNSkPlatformContext> context, const char *type,
50
- NodeClass nodeClass)
51
- : _type(type), _context(context), _nodeClass(nodeClass),
52
- _nodeId(NodeIdent++), JsiHostObject() {
53
- #if SKIA_DOM_DEBUG
54
- printDebugInfo("JsiDomNode." + std::string(_type) +
55
- " CTOR - nodeId: " + std::to_string(_nodeId));
56
- #endif
57
- }
58
-
59
- virtual ~JsiDomNode() {
60
- #if SKIA_DOM_DEBUG
61
- printDebugInfo("JsiDomNode." + std::string(_type) +
62
- " DTOR - nodeId: " + std::to_string(_nodeId));
63
- #endif
64
- }
65
-
66
- /**
67
- Called when creating the node, resolves properties from the node constructor.
68
- These properties are materialized, ie. no animated values or anything.
69
- */
70
- JSI_HOST_FUNCTION(initializeNode) {
71
- return setProps(runtime, thisValue, arguments, count);
72
- }
73
-
74
- /**
75
- JS-function for setting the properties from the JS reconciler on the node.
76
- */
77
- JSI_HOST_FUNCTION(setProps) {
78
- if (count == 1) {
79
- // Initialize properties container
80
- setProps(runtime, arguments[0]);
81
- } else {
82
- setEmptyProps();
83
- }
84
- return jsi::Value::undefined();
85
- }
86
-
87
- /**
88
- Updates the selected property value
89
- */
90
- JSI_HOST_FUNCTION(setProp) {
91
- if (_propsContainer == nullptr) {
92
- // TODO: we ignore individual properties updates if the initial properties
93
- // hasn't been defined. It is likely an error if we reach this branch and
94
- // perhaps should throw an exception but platformContext isn't available
95
- // here.
96
- return jsi::Value::undefined();
97
- }
98
- auto propName = arguments[0].asString(runtime).utf8(runtime);
99
- const jsi::Value &propValue = arguments[1];
100
-
101
- // Enumerate all props with this name and update. The
102
- // enumerateMappedPropsByName function is thread safe and locks props so it
103
- // can be called from all threads.
104
- _propsContainer->enumerateMappedPropsByName(propName, [&](NodeProp *prop) {
105
- prop->updateValue(runtime, propValue);
106
- });
107
-
108
- return jsi::Value::undefined();
109
- }
110
-
111
- /**
112
- JS Function to be called when the node is no longer part of the reconciler
113
- tree. Use for cleaning up.
114
- */
115
- JSI_HOST_FUNCTION(dispose) {
116
- dispose(false);
117
- return jsi::Value::undefined();
118
- }
119
-
120
- /**
121
- JS Function for adding a child node to this node.
122
- */
123
- JSI_HOST_FUNCTION(addChild) {
124
- // child: Node<unknown>
125
- auto newChild =
126
- getArgumentAsHostObject<JsiDomNode>(runtime, arguments, count, 0);
127
- addChild(newChild);
128
- return jsi::Value::undefined();
129
- }
130
-
131
- /*
132
- JS Function for removing a child node from this node
133
- */
134
- JSI_HOST_FUNCTION(removeChild) {
135
- auto child =
136
- getArgumentAsHostObject<JsiDomNode>(runtime, arguments, count, 0);
137
- removeChild(child);
138
- return jsi::Value::undefined();
139
- }
140
-
141
- /**
142
- JS Function for insering a child node to a specific location in the children
143
- array on this node
144
- */
145
- JSI_HOST_FUNCTION(insertChildBefore) {
146
- // child: Node<unknown>, before: Node<unknown>
147
- auto child =
148
- getArgumentAsHostObject<JsiDomNode>(runtime, arguments, count, 0);
149
- auto before =
150
- getArgumentAsHostObject<JsiDomNode>(runtime, arguments, count, 1);
151
- insertChildBefore(child, before);
152
- return jsi::Value::undefined();
153
- }
154
-
155
- /**
156
- JS Function for getting child nodes for this node
157
- */
158
- JSI_HOST_FUNCTION(children) {
159
- auto array = jsi::Array(runtime, _children.size());
160
-
161
- size_t index = 0;
162
- for (auto child : _children) {
163
- array.setValueAtIndex(runtime, index++, child->asHostObject(runtime));
164
- }
165
- return array;
166
- }
167
-
168
- /**
169
- JS Property for getting the type of node
170
- */
171
- JSI_PROPERTY_GET(type) {
172
- return jsi::String::createFromUtf8(runtime, getType());
173
- }
174
-
175
- JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiDomNode, type))
176
-
177
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiDomNode, setProps),
178
- JSI_EXPORT_FUNC(JsiDomNode, setProp),
179
- JSI_EXPORT_FUNC(JsiDomNode, addChild),
180
- JSI_EXPORT_FUNC(JsiDomNode, removeChild),
181
- JSI_EXPORT_FUNC(JsiDomNode, insertChildBefore),
182
- JSI_EXPORT_FUNC(JsiDomNode, children),
183
- JSI_EXPORT_FUNC(JsiDomNode, dispose))
184
-
185
- /**
186
- Returns the node type.
187
- */
188
- const char *getType() { return _type; }
189
-
190
- /**
191
- Returns the identifier for the node
192
- */
193
- size_t getNodeId() { return _nodeId; }
194
-
195
- /**
196
- Returns the container for node properties
197
- */
198
- NodePropsContainer *getPropsContainer() { return _propsContainer.get(); }
199
-
200
- /**
201
- Callback that will be called when the node is disposed - typically registered
202
- from the dependency manager so that nodes can be removed and unsubscribed
203
- from when removed from the reconciler tree.
204
- */
205
- void setDisposeCallback(std::function<void()> disposeCallback) {
206
- _disposeCallback = disposeCallback;
207
- }
208
-
209
- /**
210
- Invalidates and marks then context as changed. The default behaviour is an
211
- empty implementation
212
- */
213
- virtual void invalidateContext() = 0;
214
-
215
- /*
216
- Returns the class of node so that we can do loops faster without
217
- having to check using runtime type information
218
- */
219
- NodeClass getNodeClass() { return _nodeClass; }
220
-
221
- /**
222
- Updates any pending property changes in all nodes and child nodes. This
223
- function will swap any pending property changes in this and children with any
224
- waiting values that has been set by the javascript thread. Props will also be
225
- marked as changed so that we can calculate wether updates are required or
226
- not.
227
- */
228
- void commitPendingChanges() {
229
- // Update properties container
230
- if (_propsContainer != nullptr) {
231
- _propsContainer->updatePendingValues();
232
- }
233
-
234
- // Run all pending node operations
235
- {
236
- std::lock_guard<std::mutex> lock(_childrenLock);
237
- for (auto &op : _queuedNodeOps) {
238
- op();
239
- }
240
-
241
- _queuedNodeOps.clear();
242
- }
243
-
244
- // Update children
245
- for (auto &child : _children) {
246
- child->commitPendingChanges();
247
- }
248
- }
249
-
250
- /**
251
- When pending properties has been updated and all rendering is done, we call
252
- this function to mark any changes as processed. This call also resolves all
253
- child nodes
254
- */
255
- virtual void resetPendingChanges() {
256
- // Mark self as resolved
257
- if (_propsContainer != nullptr) {
258
- _propsContainer->markAsResolved();
259
- }
260
-
261
- // Now let's invalidate if needed
262
- if (_isDisposing && !_isDisposed) {
263
- invalidate();
264
- }
265
-
266
- // Resolve children
267
- for (auto &child : _children) {
268
- child->resetPendingChanges();
269
- }
270
- }
271
-
272
- /**
273
- Empty implementation of the decorate context method
274
- */
275
- virtual void decorateContext(DeclarationContext *context) {
276
- // Empty implementation
277
- }
278
-
279
- /**
280
- Called when a node has been removed from the dom tree and needs to be cleaned
281
- up. If the invalidate parameter is set, we will invalidate the node directly.
282
- Calling dispose from the JS dispose function calls this with invalidate set
283
- to false, while the dom render view calls this with true.
284
- */
285
- virtual void dispose(bool immediate) {
286
- if (_isDisposing) {
287
- return;
288
- }
289
- _isDisposing = true;
290
- if (immediate) {
291
- invalidate();
292
- }
293
- }
294
-
295
- protected:
296
- /**
297
- Adds an operation that will be executed when the render cycle is finished.
298
- */
299
- void enqueAsynOperation(std::function<void()> &&fp) {
300
- std::lock_guard<std::mutex> lock(_childrenLock);
301
- _queuedNodeOps.push_back(std::move(fp));
302
- }
303
- /**
304
- Override to define properties in node implementations
305
- */
306
- virtual void defineProperties(NodePropsContainer *container) {}
307
-
308
- /**
309
- Returns the platform context
310
- */
311
- std::shared_ptr<RNSkPlatformContext> getContext() { return _context; }
312
-
313
- /**
314
- Returns this node as a host object that can be returned to the JS side.
315
- */
316
- jsi::Object asHostObject(jsi::Runtime &runtime) {
317
- return jsi::Object::createFromHostObject(runtime, shared_from_this());
318
- }
319
-
320
- /**
321
- Native implementation of the set properties method. This is called from the
322
- reconciler when properties are set due to changes in React.
323
- */
324
- void setProps(jsi::Runtime &runtime, const jsi::Value &maybeProps) {
325
- #if SKIA_DOM_DEBUG
326
- printDebugInfo("JS:setProps(nodeId: " + std::to_string(_nodeId) + ")");
327
- #endif
328
- // Initialize properties container
329
- ensurePropertyContainer();
330
-
331
- // Update properties container
332
- _propsContainer->setProps(runtime, maybeProps);
333
-
334
- // Invalidate context
335
- invalidateContext();
336
- }
337
-
338
- /**
339
- Called for components that has no properties
340
- */
341
- void setEmptyProps() {
342
- #if SKIA_DOM_DEBUG
343
- printDebugInfo("JS:setEmptyProps(nodeId: " + std::to_string(_nodeId) + ")");
344
- #endif
345
- // Initialize properties container
346
- ensurePropertyContainer();
347
- }
348
-
349
- /**
350
- Returns all child JsiDomNodes for this node.
351
- */
352
- const std::vector<std::shared_ptr<JsiDomNode>> &getChildren() {
353
- std::lock_guard<std::mutex> lock(_childrenLock);
354
- return _children;
355
- }
356
-
357
- /**
358
- Override to be notified when a node property has changed
359
- */
360
- virtual void onPropertyChanged(BaseNodeProp *prop) {}
361
-
362
- /**
363
- Adds a child node to the array of children for this node
364
- */
365
- virtual void addChild(std::shared_ptr<JsiDomNode> child) {
366
- #if SKIA_DOM_DEBUG
367
- printDebugInfo("JS:addChild(childId: " + std::to_string(child->_nodeId) +
368
- ")");
369
- #endif
370
- enqueAsynOperation([child, weakSelf = weak_from_this()]() {
371
- auto self = weakSelf.lock();
372
- if (self) {
373
- // Remove the existing instance of the child, before adding it to the
374
- // end of the list
375
- auto existingPosition =
376
- std::find(self->_children.begin(), self->_children.end(), child);
377
- if (existingPosition != self->_children.end()) {
378
- self->_children.erase(existingPosition);
379
- }
380
-
381
- self->_children.push_back(child);
382
- child->setParent(self.get());
383
- }
384
- });
385
- }
386
-
387
- /**
388
- Inserts a child node before a given child node in the children array for this
389
- node
390
- */
391
- virtual void insertChildBefore(std::shared_ptr<JsiDomNode> child,
392
- std::shared_ptr<JsiDomNode> before) {
393
- #if SKIA_DOM_DEBUG
394
- printDebugInfo(
395
- "JS:insertChildBefore(childId: " + std::to_string(child->_nodeId) +
396
- ", beforeId: " + std::to_string(before->_nodeId) + ")");
397
- #endif
398
- enqueAsynOperation([child, before, weakSelf = weak_from_this()]() {
399
- auto self = weakSelf.lock();
400
- if (self) {
401
- // Remove the existing instance of the child
402
- // before adding it in the new position
403
- auto existingPosition =
404
- std::find(self->_children.begin(), self->_children.end(), child);
405
- if (existingPosition != self->_children.end()) {
406
- self->_children.erase(existingPosition);
407
- }
408
-
409
- auto position =
410
- std::find(self->_children.begin(), self->_children.end(), before);
411
- self->_children.insert(position, child);
412
- child->setParent(self.get());
413
- }
414
- });
415
- }
416
-
417
- /**
418
- Removes a child. Removing a child will remove the child from the array of
419
- children and call dispose on the child node.
420
- */
421
- virtual void removeChild(std::shared_ptr<JsiDomNode> child) {
422
- #if SKIA_DOM_DEBUG
423
- printDebugInfo("JS:removeChild(childId: " + std::to_string(child->_nodeId) +
424
- ")");
425
- #endif
426
- auto removeChild = [child,
427
- weakSelf = weak_from_this()](bool immediate = false) {
428
- auto self = weakSelf.lock();
429
- if (self) {
430
- // Delete child itself
431
- self->_children.erase(
432
- std::remove_if(self->_children.begin(), self->_children.end(),
433
- [child](const auto &node) { return node == child; }),
434
- self->_children.end());
435
-
436
- child->dispose(immediate);
437
- }
438
- };
439
-
440
- if (_isDisposing) {
441
- removeChild(false);
442
- } else {
443
- enqueAsynOperation(removeChild);
444
- }
445
- }
446
-
447
- #if SKIA_DOM_DEBUG
448
- std::string getLevelIndentation(size_t indentation = 0) {
449
- JsiDomNode *curParent = _parent;
450
- while (curParent != nullptr) {
451
- indentation++;
452
- curParent = curParent->getParent();
453
- }
454
- return std::string(indentation * 2, ' ');
455
- }
456
-
457
- void printDebugInfo(const std::string &message, size_t indentation = 0) {
458
- RNSkLogger::logToConsole("%s%s %lu: %s",
459
- getLevelIndentation(indentation).c_str(),
460
- getType(), getNodeId(), message.c_str());
461
- }
462
- #endif
463
-
464
- /**
465
- Sets the parent node
466
- */
467
- void setParent(JsiDomNode *parent) { _parent = parent; }
468
-
469
- /**
470
- Returns the parent node if set.
471
- */
472
- JsiDomNode *getParent() { return _parent; }
473
-
474
- /**
475
- Loops through all declaration nodes and gives each one of them the
476
- opportunity to decorate the context.
477
- */
478
- void decorateChildren(DeclarationContext *context) {
479
- for (auto &child : getChildren()) {
480
- // All JsiDomNodes has the decorateContext method - but only the
481
- // JsiDomDeclarationNode is actually doing stuff inside this method.
482
- child->decorateContext(context);
483
- }
484
- }
485
-
486
- private:
487
- /**
488
- Invalidates the node - meaning removing and clearing children and properties
489
- **/
490
- void invalidate() {
491
- if (_isDisposing && !_isDisposed) {
492
- #if SKIA_DOM_DEBUG
493
- printDebugInfo("JsiDomNode::invalidate: nodeid: " +
494
- std::to_string(_nodeId));
495
- #endif
496
-
497
- _isDisposed = true;
498
-
499
- // Clear parent
500
- this->setParent(nullptr);
501
-
502
- // Clear any async operations
503
- _queuedNodeOps.clear();
504
-
505
- // Callback signaling that we're done
506
- if (_disposeCallback != nullptr) {
507
- _disposeCallback();
508
- _disposeCallback = nullptr;
509
- }
510
-
511
- // Clear props
512
- if (_propsContainer != nullptr) {
513
- _propsContainer->dispose();
514
- }
515
-
516
- // Remove children
517
- std::vector<std::shared_ptr<JsiDomNode>> tmp;
518
- {
519
- std::lock_guard<std::mutex> lock(_childrenLock);
520
- tmp.reserve(_children.size());
521
- for (auto &child : _children) {
522
- tmp.push_back(child);
523
- }
524
- _children.clear();
525
- }
526
- for (auto &child : tmp) {
527
- child->dispose(true);
528
- }
529
- }
530
- }
531
-
532
- /**
533
- Creates and sets up the property container
534
- */
535
- void ensurePropertyContainer() {
536
- if (_propsContainer == nullptr) {
537
- _propsContainer = std::make_shared<NodePropsContainer>(
538
- getType(), [weakSelf = weak_from_this()](BaseNodeProp *p) {
539
- auto self = weakSelf.lock();
540
- if (self) {
541
- self->onPropertyChanged(p);
542
- }
543
- });
544
-
545
- // Ask sub classes to define their properties
546
- defineProperties(_propsContainer.get());
547
- }
548
- }
549
-
550
- const char *_type;
551
- std::shared_ptr<RNSkPlatformContext> _context;
552
-
553
- std::shared_ptr<NodePropsContainer> _propsContainer;
554
-
555
- std::function<void()> _disposeCallback;
556
-
557
- std::vector<std::shared_ptr<JsiDomNode>> _children;
558
- std::mutex _childrenLock;
559
-
560
- std::atomic<bool> _isDisposing = {false};
561
- bool _isDisposed = false;
562
-
563
- size_t _nodeId;
564
-
565
- std::vector<std::function<void()>> _queuedNodeOps;
566
-
567
- JsiDomNode *_parent = nullptr;
568
-
569
- NodeClass _nodeClass;
570
- };
571
-
572
- } // namespace RNSkia