@shopify/react-native-skia 0.1.185 → 0.1.187

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. package/android/build.gradle +2 -1
  2. package/android/cpp/jni/JniPlatformContext.cpp +92 -3
  3. package/android/cpp/jni/include/JniPlatformContext.h +4 -0
  4. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +8 -0
  5. package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +17 -1
  6. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +180 -0
  7. package/cpp/api/JsiSkFont.h +1 -1
  8. package/cpp/api/JsiSkHostObjects.h +1 -1
  9. package/cpp/api/JsiSkImage.h +1 -1
  10. package/cpp/api/JsiSkImageFactory.h +29 -0
  11. package/cpp/api/JsiSkPaint.h +7 -7
  12. package/cpp/api/JsiSkPathFactory.h +1 -1
  13. package/cpp/api/JsiSkPicture.h +2 -2
  14. package/cpp/api/JsiSkRuntimeEffect.h +3 -3
  15. package/cpp/api/JsiSkSVG.h +12 -2
  16. package/cpp/api/JsiSkShader.h +1 -1
  17. package/cpp/api/JsiSkSurface.h +3 -3
  18. package/cpp/api/JsiSkSurfaceFactory.h +1 -1
  19. package/cpp/api/JsiSkTypeface.h +1 -1
  20. package/cpp/rnskia/RNSkAnimation.h +3 -3
  21. package/cpp/rnskia/RNSkDomView.h +9 -9
  22. package/cpp/rnskia/RNSkInfoParameter.h +2 -2
  23. package/cpp/rnskia/RNSkJsView.h +8 -8
  24. package/cpp/rnskia/RNSkJsiViewApi.h +5 -5
  25. package/cpp/rnskia/RNSkPictureView.h +8 -8
  26. package/cpp/rnskia/RNSkPlatformContext.h +32 -3
  27. package/cpp/rnskia/RNSkValueApi.h +5 -5
  28. package/cpp/rnskia/RNSkView.h +6 -6
  29. package/cpp/rnskia/dom/base/ConcatablePaint.h +6 -6
  30. package/cpp/rnskia/dom/base/Declaration.h +1 -1
  31. package/cpp/rnskia/dom/base/DeclarationContext.h +7 -7
  32. package/cpp/rnskia/dom/base/DrawingContext.h +3 -3
  33. package/cpp/rnskia/dom/base/NodePropsContainer.h +1 -1
  34. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +1 -1
  35. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +1 -1
  36. package/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +8 -7
  37. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +1 -1
  38. package/cpp/rnskia/dom/nodes/JsiImageNode.h +5 -2
  39. package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +9 -9
  40. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +1 -1
  41. package/cpp/rnskia/dom/nodes/JsiPathNode.h +1 -1
  42. package/cpp/rnskia/dom/nodes/JsiPointsNode.h +1 -1
  43. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +7 -3
  44. package/cpp/rnskia/dom/nodes/JsiTextNode.h +5 -4
  45. package/cpp/rnskia/dom/nodes/JsiTextPathNode.h +3 -1
  46. package/cpp/rnskia/dom/props/BlendModeProp.h +1 -1
  47. package/cpp/rnskia/dom/props/CircleProp.h +1 -1
  48. package/cpp/rnskia/dom/props/ClipProp.h +1 -1
  49. package/cpp/rnskia/dom/props/FontProp.h +15 -10
  50. package/cpp/rnskia/dom/props/ImageProps.h +30 -16
  51. package/cpp/rnskia/dom/props/PaintProps.h +1 -1
  52. package/cpp/rnskia/dom/props/PathProp.h +1 -1
  53. package/cpp/rnskia/dom/props/PointProp.h +1 -1
  54. package/cpp/rnskia/dom/props/PointsProp.h +1 -1
  55. package/cpp/rnskia/dom/props/RRectProp.h +2 -2
  56. package/cpp/rnskia/dom/props/RadiusProp.h +1 -1
  57. package/cpp/rnskia/dom/props/RectProp.h +1 -1
  58. package/cpp/rnskia/dom/props/StrokeProps.h +1 -1
  59. package/cpp/rnskia/dom/props/SvgProp.h +18 -12
  60. package/cpp/rnskia/dom/props/TextBlobProp.h +60 -57
  61. package/cpp/rnskia/dom/props/TileModeProp.h +1 -1
  62. package/cpp/rnskia/dom/props/UniformsProp.h +1 -1
  63. package/cpp/rnskia/dom/props/VertexModeProp.h +1 -1
  64. package/cpp/rnskia/dom/props/VerticesProps.h +1 -1
  65. package/cpp/rnskia/values/RNSkClockValue.h +2 -2
  66. package/cpp/rnskia/values/RNSkComputedValue.h +1 -1
  67. package/cpp/rnskia/values/RNSkReadonlyValue.h +3 -3
  68. package/cpp/rnskia/values/RNSkValue.h +4 -4
  69. package/cpp/utils/RNSkMeasureTime.h +1 -1
  70. package/cpp/utils/RNSkTimingInfo.h +1 -1
  71. package/globalJestSetup.js +6 -0
  72. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +16 -13
  73. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +8 -0
  74. package/ios/RNSkia-iOS/SkiaManager.mm +20 -1
  75. package/ios/RNSkia-iOS/ViewScreenshotService.h +21 -0
  76. package/ios/RNSkia-iOS/ViewScreenshotService.mm +79 -0
  77. package/jestSetup.js +2 -3
  78. package/lib/commonjs/dom/nodes/drawings/ImageNode.js +22 -1
  79. package/lib/commonjs/dom/nodes/drawings/ImageNode.js.map +1 -1
  80. package/lib/commonjs/dom/nodes/drawings/ImageSVG.js +5 -0
  81. package/lib/commonjs/dom/nodes/drawings/ImageSVG.js.map +1 -1
  82. package/lib/commonjs/dom/nodes/drawings/Text.d.ts +2 -2
  83. package/lib/commonjs/dom/nodes/drawings/Text.js +13 -2
  84. package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
  85. package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -0
  86. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  87. package/lib/commonjs/dom/types/Drawings.d.ts +5 -5
  88. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  89. package/lib/commonjs/dom/types/Shaders.d.ts +1 -1
  90. package/lib/commonjs/dom/types/Shaders.js.map +1 -1
  91. package/lib/commonjs/mock/index.d.ts +2 -15
  92. package/lib/commonjs/mock/index.js +37 -110
  93. package/lib/commonjs/mock/index.js.map +1 -1
  94. package/lib/commonjs/skia/core/Image.d.ts +14 -2
  95. package/lib/commonjs/skia/core/Image.js +37 -1
  96. package/lib/commonjs/skia/core/Image.js.map +1 -1
  97. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +7 -0
  98. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  99. package/lib/commonjs/skia/types/SVG/SVG.d.ts +4 -1
  100. package/lib/commonjs/skia/types/SVG/SVG.js.map +1 -1
  101. package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -1
  102. package/lib/commonjs/skia/web/JsiSkImageFactory.js +7 -0
  103. package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
  104. package/lib/module/dom/nodes/drawings/ImageNode.js +22 -1
  105. package/lib/module/dom/nodes/drawings/ImageNode.js.map +1 -1
  106. package/lib/module/dom/nodes/drawings/ImageSVG.js +5 -0
  107. package/lib/module/dom/nodes/drawings/ImageSVG.js.map +1 -1
  108. package/lib/module/dom/nodes/drawings/Text.d.ts +2 -2
  109. package/lib/module/dom/nodes/drawings/Text.js +13 -2
  110. package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
  111. package/lib/module/dom/nodes/paint/Shaders.js +5 -0
  112. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  113. package/lib/module/dom/types/Drawings.d.ts +5 -5
  114. package/lib/module/dom/types/Drawings.js.map +1 -1
  115. package/lib/module/dom/types/Shaders.d.ts +1 -1
  116. package/lib/module/dom/types/Shaders.js.map +1 -1
  117. package/lib/module/mock/index.d.ts +2 -15
  118. package/lib/module/mock/index.js +33 -95
  119. package/lib/module/mock/index.js.map +1 -1
  120. package/lib/module/skia/core/Image.d.ts +14 -2
  121. package/lib/module/skia/core/Image.js +32 -0
  122. package/lib/module/skia/core/Image.js.map +1 -1
  123. package/lib/module/skia/types/Image/ImageFactory.d.ts +7 -0
  124. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  125. package/lib/module/skia/types/SVG/SVG.d.ts +4 -1
  126. package/lib/module/skia/types/SVG/SVG.js.map +1 -1
  127. package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -1
  128. package/lib/module/skia/web/JsiSkImageFactory.js +7 -0
  129. package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
  130. package/lib/typescript/globalJestSetup.d.ts +2 -0
  131. package/lib/typescript/src/dom/nodes/drawings/Text.d.ts +2 -2
  132. package/lib/typescript/src/dom/types/Drawings.d.ts +5 -5
  133. package/lib/typescript/src/dom/types/Shaders.d.ts +1 -1
  134. package/lib/typescript/src/mock/index.d.ts +2 -15
  135. package/lib/typescript/src/skia/core/Image.d.ts +14 -2
  136. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +7 -0
  137. package/lib/typescript/src/skia/types/SVG/SVG.d.ts +4 -1
  138. package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -1
  139. package/package.json +3 -2
  140. package/scripts/install-npm.js +3 -2
  141. package/src/dom/nodes/drawings/ImageNode.ts +9 -1
  142. package/src/dom/nodes/drawings/ImageSVG.ts +3 -0
  143. package/src/dom/nodes/drawings/Text.ts +13 -3
  144. package/src/dom/nodes/paint/Shaders.ts +4 -0
  145. package/src/dom/types/Drawings.ts +5 -5
  146. package/src/dom/types/Shaders.ts +1 -1
  147. package/src/mock/index.ts +35 -98
  148. package/src/skia/core/Image.ts +43 -1
  149. package/src/skia/types/Image/ImageFactory.ts +8 -0
  150. package/src/skia/types/SVG/SVG.ts +4 -1
  151. package/src/skia/web/JsiSkImageFactory.ts +8 -1
@@ -7,11 +7,11 @@
7
7
  #include <unordered_map>
8
8
  #include <vector>
9
9
 
10
- #include <JsiHostObject.h>
11
- #include <JsiValueWrapper.h>
12
- #include <RNSkPlatformContext.h>
13
- #include <RNSkValue.h>
14
- #include <RNSkView.h>
10
+ #include "JsiHostObject.h"
11
+ #include "JsiValueWrapper.h"
12
+ #include "RNSkPlatformContext.h"
13
+ #include "RNSkValue.h"
14
+ #include "RNSkView.h"
15
15
  #include <jsi/jsi.h>
16
16
 
17
17
  namespace RNSkia {
@@ -9,14 +9,14 @@
9
9
 
10
10
  #include <jsi/jsi.h>
11
11
 
12
- #include <JsiValueWrapper.h>
13
- #include <RNSkView.h>
14
-
15
- #include <JsiSkPicture.h>
16
- #include <RNSkInfoParameter.h>
17
- #include <RNSkLog.h>
18
- #include <RNSkPlatformContext.h>
19
- #include <RNSkTimingInfo.h>
12
+ #include "JsiValueWrapper.h"
13
+ #include "RNSkView.h"
14
+
15
+ #include "JsiSkPicture.h"
16
+ #include "RNSkInfoParameter.h"
17
+ #include "RNSkLog.h"
18
+ #include "RNSkPlatformContext.h"
19
+ #include "RNSkTimingInfo.h"
20
20
 
21
21
  #pragma clang diagnostic push
22
22
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -9,11 +9,13 @@
9
9
  #include <unordered_map>
10
10
  #include <utility>
11
11
 
12
- #include <RNSkDispatchQueue.h>
12
+ #include "RNSkDispatchQueue.h"
13
13
 
14
14
  #pragma clang diagnostic push
15
15
  #pragma clang diagnostic ignored "-Wdocumentation"
16
16
 
17
+ #include "SkData.h"
18
+ #include "SkImage.h"
17
19
  #include "SkStream.h"
18
20
  #include "SkSurface.h"
19
21
 
@@ -88,6 +90,18 @@ public:
88
90
  _dispatchQueue->dispatch(std::move(func));
89
91
  }
90
92
 
93
+ /**
94
+ * Runs the passed function on the main thread
95
+ * @param func Function to run.
96
+ */
97
+ virtual void runOnMainThread(std::function<void()> func) = 0;
98
+
99
+ /**
100
+ * Takes a screenshot of a given view represented by the view tag
101
+ * @param tag React view tag
102
+ */
103
+ virtual sk_sp<SkImage> takeScreenshotFromViewTag(size_t tag) = 0;
104
+
91
105
  /**
92
106
  Returns the javascript runtime
93
107
  */
@@ -112,12 +126,27 @@ public:
112
126
 
113
127
  /**
114
128
  * Creates an offscreen surface
115
- * @param width width of the surface
116
- * @param height height of the surface
129
+ * @param width Width of the offscreen surface
130
+ * @param height Height of the offscreen surface
117
131
  * @return sk_sp<SkSurface>
118
132
  */
119
133
  virtual sk_sp<SkSurface> makeOffscreenSurface(int width, int height) = 0;
120
134
 
135
+ /**
136
+ * Creates an skImage containing the screenshot of a native view and its
137
+ * children.
138
+ * @param viewTag React viewtag
139
+ * @param callback Called when image is ready or with null if something
140
+ * failed.
141
+ */
142
+ virtual void
143
+ makeViewScreenshot(int viewTag,
144
+ std::function<void(sk_sp<SkImage>)> callback) {
145
+ runOnMainThread([this, callback, viewTag]() {
146
+ callback(takeScreenshotFromViewTag(viewTag));
147
+ });
148
+ }
149
+
121
150
  /**
122
151
  * Raises an exception on the platform. This function does not necessarily
123
152
  * throw an exception and stop execution, so it is important to stop execution
@@ -2,11 +2,11 @@
2
2
 
3
3
  #include <memory>
4
4
 
5
- #include <JsiHostObject.h>
6
- #include <RNSkAnimation.h>
7
- #include <RNSkComputedValue.h>
8
- #include <RNSkPlatformContext.h>
9
- #include <RNSkValue.h>
5
+ #include "JsiHostObject.h"
6
+ #include "RNSkAnimation.h"
7
+ #include "RNSkComputedValue.h"
8
+ #include "RNSkPlatformContext.h"
9
+ #include "RNSkValue.h"
10
10
  #include <jsi/jsi.h>
11
11
 
12
12
  namespace RNSkia {
@@ -6,13 +6,13 @@
6
6
  #include <unordered_map>
7
7
  #include <vector>
8
8
 
9
- #include <JsiValueWrapper.h>
10
- #include <RNSkPlatformContext.h>
11
- #include <RNSkValue.h>
9
+ #include "JsiValueWrapper.h"
10
+ #include "RNSkPlatformContext.h"
11
+ #include "RNSkValue.h"
12
12
 
13
- #include <JsiSkImage.h>
14
- #include <JsiSkPoint.h>
15
- #include <JsiSkRect.h>
13
+ #include "JsiSkImage.h"
14
+ #include "JsiSkPoint.h"
15
+ #include "JsiSkRect.h"
16
16
 
17
17
  #pragma clang diagnostic push
18
18
  #pragma clang diagnostic ignored "-Wdocumentation"
@@ -6,12 +6,12 @@
6
6
  #pragma clang diagnostic push
7
7
  #pragma clang diagnostic ignored "-Wdocumentation"
8
8
 
9
- #include <SkColorFilter.h>
10
- #include <SkImageFilter.h>
11
- #include <SkMaskFilter.h>
12
- #include <SkPaint.h>
13
- #include <SkPathEffect.h>
14
- #include <SkShader.h>
9
+ #include "SkColorFilter.h"
10
+ #include "SkImageFilter.h"
11
+ #include "SkMaskFilter.h"
12
+ #include "SkPaint.h"
13
+ #include "SkPathEffect.h"
14
+ #include "SkShader.h"
15
15
 
16
16
  #pragma clang diagnostic pop
17
17
 
@@ -9,7 +9,7 @@
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
- #include <SkRefCnt.h>
12
+ #include "SkRefCnt.h"
13
13
 
14
14
  #pragma clang diagnostic pop
15
15
 
@@ -9,13 +9,13 @@
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
- #include <SkColorFilter.h>
13
- #include <SkImageFilter.h>
14
- #include <SkImageFilters.h>
15
- #include <SkMaskFilter.h>
16
- #include <SkPaint.h>
17
- #include <SkPathEffect.h>
18
- #include <SkShader.h>
12
+ #include "SkColorFilter.h"
13
+ #include "SkImageFilter.h"
14
+ #include "SkImageFilters.h"
15
+ #include "SkMaskFilter.h"
16
+ #include "SkPaint.h"
17
+ #include "SkPathEffect.h"
18
+ #include "SkShader.h"
19
19
 
20
20
  #pragma clang diagnostic pop
21
21
 
@@ -13,9 +13,9 @@
13
13
  #pragma clang diagnostic push
14
14
  #pragma clang diagnostic ignored "-Wdocumentation"
15
15
 
16
- #include <SkCanvas.h>
17
- #include <SkPaint.h>
18
- #include <SkRefCnt.h>
16
+ #include "SkCanvas.h"
17
+ #include "SkPaint.h"
18
+ #include "SkRefCnt.h"
19
19
 
20
20
  #pragma clang diagnostic pop
21
21
 
@@ -54,7 +54,7 @@ public:
54
54
  void updatePendingValues() {
55
55
  for (auto &prop : _properties) {
56
56
  prop->updatePendingChanges();
57
- if (!prop->isSet() && prop->isRequired()) {
57
+ if (prop->isRequired() && !prop->isSet()) {
58
58
  throw std::runtime_error("Missing one or more required properties " +
59
59
  std::string(prop->getName()) + " in the " +
60
60
  _type + " component.");
@@ -10,7 +10,7 @@
10
10
  #pragma clang diagnostic push
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
12
12
 
13
- #include <SkMaskFilter.h>
13
+ #include "SkMaskFilter.h"
14
14
 
15
15
  #pragma clang diagnostic pop
16
16
 
@@ -11,7 +11,7 @@
11
11
  #pragma clang diagnostic push
12
12
  #pragma clang diagnostic ignored "-Wdocumentation"
13
13
 
14
- #include <SkColorFilter.h>
14
+ #include "SkColorFilter.h"
15
15
 
16
16
  #pragma clang diagnostic pop
17
17
 
@@ -20,12 +20,14 @@ protected:
20
20
  auto x = _xProp->value().getAsNumber();
21
21
  auto y = _yProp->value().getAsNumber();
22
22
  auto font = _fontProp->getDerivedValue();
23
- auto glyphInfo = _glyphsProp->getDerivedValue();
24
-
25
- context->getCanvas()->drawGlyphs(
26
- static_cast<int>(glyphInfo->glyphIds.size()),
27
- glyphInfo->glyphIds.data(), glyphInfo->positions.data(),
28
- SkPoint::Make(x, y), *font, *context->getPaint());
23
+ if (font != nullptr) {
24
+ auto glyphInfo = _glyphsProp->getDerivedValue();
25
+
26
+ context->getCanvas()->drawGlyphs(
27
+ static_cast<int>(glyphInfo->glyphIds.size()),
28
+ glyphInfo->glyphIds.data(), glyphInfo->positions.data(),
29
+ SkPoint::Make(x, y), *font, *context->getPaint());
30
+ }
29
31
  }
30
32
 
31
33
  void defineProperties(NodePropsContainer *container) override {
@@ -36,7 +38,6 @@ protected:
36
38
  _xProp = container->defineProperty<NodeProp>("x");
37
39
  _yProp = container->defineProperty<NodeProp>("y");
38
40
 
39
- _fontProp->require();
40
41
  _glyphsProp->require();
41
42
  _xProp->require();
42
43
  _yProp->require();
@@ -16,7 +16,7 @@
16
16
  #pragma clang diagnostic push
17
17
  #pragma clang diagnostic ignored "-Wdocumentation"
18
18
 
19
- #include <SkImageFilter.h>
19
+ #include "SkImageFilter.h"
20
20
 
21
21
  #pragma clang diagnostic pop
22
22
 
@@ -16,16 +16,19 @@ public:
16
16
  protected:
17
17
  void draw(DrawingContext *context) override {
18
18
  auto rects = _imageProps->getDerivedValue();
19
+ auto image = _imageProps->getImage();
20
+ if (image == nullptr) {
21
+ return;
22
+ }
19
23
 
20
24
  context->getCanvas()->drawImageRect(
21
- _imageProps->getImage(), rects->src, rects->dst, SkSamplingOptions(),
25
+ image, rects->src, rects->dst, SkSamplingOptions(),
22
26
  context->getPaint().get(), SkCanvas::kStrict_SrcRectConstraint);
23
27
  }
24
28
 
25
29
  void defineProperties(NodePropsContainer *container) override {
26
30
  JsiDomDrawingNode::defineProperties(container);
27
31
  _imageProps = container->defineProperty<ImageProps>();
28
- _imageProps->require();
29
32
  }
30
33
 
31
34
  private:
@@ -17,21 +17,21 @@ public:
17
17
  protected:
18
18
  void draw(DrawingContext *context) override {
19
19
  auto svgDom = _svgDomProp->getDerivedValue();
20
- auto rect = _rectProp->getDerivedValue();
21
-
22
- context->getCanvas()->save();
23
- context->getCanvas()->translate(rect->x(), rect->y());
24
- svgDom->setContainerSize(SkSize::Make(rect->width(), rect->height()));
25
- svgDom->render(context->getCanvas());
26
- context->getCanvas()->restore();
20
+ if (svgDom != nullptr) {
21
+ auto rect = _rectProp->getDerivedValue();
22
+
23
+ context->getCanvas()->save();
24
+ context->getCanvas()->translate(rect->x(), rect->y());
25
+ svgDom->setContainerSize(SkSize::Make(rect->width(), rect->height()));
26
+ svgDom->render(context->getCanvas());
27
+ context->getCanvas()->restore();
28
+ }
27
29
  }
28
30
 
29
31
  void defineProperties(NodePropsContainer *container) override {
30
32
  JsiDomDrawingNode::defineProperties(container);
31
33
  _svgDomProp = container->defineProperty<SvgProp>("svg");
32
34
  _rectProp = container->defineProperty<RectProps>("rect");
33
-
34
- _svgDomProp->require();
35
35
  }
36
36
 
37
37
  private:
@@ -11,7 +11,7 @@
11
11
  #pragma clang diagnostic push
12
12
  #pragma clang diagnostic ignored "-Wdocumentation"
13
13
 
14
- #include <SkPathEffect.h>
14
+ #include "SkPathEffect.h"
15
15
 
16
16
  #pragma clang diagnostic pop
17
17
 
@@ -9,7 +9,7 @@
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
- #include <SkTrimPathEffect.h>
12
+ #include "SkTrimPathEffect.h"
13
13
 
14
14
  #pragma clang diagnostic pop
15
15
 
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include <SkCanvas.h>
11
+ #include "SkCanvas.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14
 
@@ -17,7 +17,7 @@
17
17
  #pragma clang diagnostic push
18
18
  #pragma clang diagnostic ignored "-Wdocumentation"
19
19
 
20
- #include <SkShader.h>
20
+ #include "SkShader.h"
21
21
 
22
22
  #pragma clang diagnostic pop
23
23
 
@@ -91,6 +91,10 @@ public:
91
91
  void decorate(DeclarationContext *context) override {
92
92
 
93
93
  auto image = _imageProps->getImage();
94
+ if (image == nullptr) {
95
+ return;
96
+ }
97
+
94
98
  auto rect = _imageProps->getRect();
95
99
  auto lm =
96
100
  _transformProp->isSet() ? _transformProp->getDerivedValue() : nullptr;
@@ -98,7 +102,7 @@ public:
98
102
  if (rect != nullptr && lm != nullptr) {
99
103
  auto rc = _imageProps->getDerivedValue();
100
104
  auto m3 = _imageProps->rect2rect(rc->src, rc->dst);
101
- if (_transformProp->isChanged()) {
105
+ if (_transformProp->isChanged() || _imageProps->isChanged()) {
102
106
  // To modify the matrix we need to copy it since we're not allowed to
103
107
  // modify values contained in properties - this would have caused the
104
108
  // matrix to be translated and scaled more and more for each render
@@ -144,7 +148,7 @@ protected:
144
148
  _transformProp->require();
145
149
 
146
150
  // Add and require the image
147
- container->defineProperty<NodeProp>("image")->require();
151
+ container->defineProperty<NodeProp>("image");
148
152
  }
149
153
 
150
154
  private:
@@ -21,9 +21,11 @@ protected:
21
21
  auto y = _yProp->value().getAsNumber();
22
22
  auto font = _fontProp->getDerivedValue();
23
23
 
24
- context->getCanvas()->drawSimpleText(text, strlen(text),
25
- SkTextEncoding::kUTF8, x, y, *font,
26
- *context->getPaint());
24
+ if (font != nullptr) {
25
+ context->getCanvas()->drawSimpleText(text, strlen(text),
26
+ SkTextEncoding::kUTF8, x, y, *font,
27
+ *context->getPaint());
28
+ }
27
29
  }
28
30
 
29
31
  void defineProperties(NodePropsContainer *container) override {
@@ -34,7 +36,6 @@ protected:
34
36
  _xProp = container->defineProperty<NodeProp>("x");
35
37
  _yProp = container->defineProperty<NodeProp>("y");
36
38
 
37
- _fontProp->require();
38
39
  _textProp->require();
39
40
  _xProp->require();
40
41
  _yProp->require();
@@ -16,7 +16,9 @@ public:
16
16
  protected:
17
17
  void draw(DrawingContext *context) override {
18
18
  auto blob = _textBlobProp->getDerivedValue();
19
- context->getCanvas()->drawTextBlob(blob, 0, 0, *context->getPaint());
19
+ if (blob != nullptr) {
20
+ context->getCanvas()->drawTextBlob(blob, 0, 0, *context->getPaint());
21
+ }
20
22
  }
21
23
 
22
24
  void defineProperties(NodePropsContainer *container) override {
@@ -10,7 +10,7 @@
10
10
  #pragma clang diagnostic push
11
11
  #pragma clang diagnostic ignored "-Wdocumentation"
12
12
 
13
- #include <SkBlendMode.h>
13
+ #include "SkBlendMode.h"
14
14
 
15
15
  #pragma clang diagnostic pop
16
16
 
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include <SkPoint.h>
11
+ #include "SkPoint.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14
 
@@ -11,7 +11,7 @@
11
11
  #pragma clang diagnostic push
12
12
  #pragma clang diagnostic ignored "-Wdocumentation"
13
13
 
14
- #include <SkPath.h>
14
+ #include "SkPath.h"
15
15
 
16
16
  #pragma clang diagnostic pop
17
17
 
@@ -17,17 +17,22 @@ public:
17
17
  }
18
18
 
19
19
  void updateDerivedValue() override {
20
- if (!_fontProp->isSet() ||
21
- _fontProp->value().getType() != PropType::HostObject) {
22
- throw std::runtime_error("Expected SkFont object for the Font property.");
20
+ if (_fontProp->isSet()) {
21
+ if (_fontProp->value().getType() == PropType::HostObject) {
22
+ auto ptr = _fontProp->value().getAs<JsiSkFont>();
23
+ if (ptr == nullptr) {
24
+ throw std::runtime_error(
25
+ "Expected SkFont object for the Font property.");
26
+ }
27
+ setDerivedValue(ptr->getObject());
28
+
29
+ } else {
30
+ throw std::runtime_error(
31
+ "Expected SkFont object or null/undefined for the Font property.");
32
+ }
33
+ } else {
34
+ setDerivedValue(nullptr);
23
35
  }
24
-
25
- auto ptr = _fontProp->value().getAs<JsiSkFont>();
26
- if (ptr == nullptr) {
27
- throw std::runtime_error("Expected SkFont object for the Font property.");
28
- }
29
-
30
- setDerivedValue(ptr->getObject());
31
36
  }
32
37
 
33
38
  private:
@@ -32,20 +32,32 @@ public:
32
32
  }
33
33
 
34
34
  void updateDerivedValue() override {
35
- if (!_imageProp->isSet() ||
36
- _imageProp->value().getType() != PropType::HostObject) {
37
- throw std::runtime_error("Expected SkImage object for the " +
38
- std::string(getName()) + " property.");
39
- }
40
-
41
- auto ptr = std::dynamic_pointer_cast<JsiSkImage>(
42
- _imageProp->value().getAsHostObject());
43
- if (ptr == nullptr) {
44
- throw std::runtime_error("Expected SkImage object for the " +
45
- std::string(getName()) + " property.");
35
+ if (_imageProp->isSet()) {
36
+ // Check for host object
37
+ if (_imageProp->value().getType() == PropType::HostObject) {
38
+ // This should be an SkImage wrapper:
39
+ auto ptr = std::dynamic_pointer_cast<JsiSkImage>(
40
+ _imageProp->value().getAsHostObject());
41
+ if (ptr == nullptr) {
42
+ // If not - throw an exception
43
+ throw std::runtime_error("Expected SkImage object for the " +
44
+ std::string(getName()) +
45
+ " property. Got a " +
46
+ _imageProp->value().getTypeAsString(
47
+ _imageProp->value().getType()) +
48
+ ".");
49
+ }
50
+ setDerivedValue(ptr->getObject());
51
+ } else {
52
+ // Should be a host object if set
53
+ throw std::runtime_error(
54
+ "Expected SkImage object or null/undefined for the " +
55
+ std::string(getName()) + " property.");
56
+ }
57
+ } else {
58
+ // Set to null
59
+ setDerivedValue(nullptr);
46
60
  }
47
-
48
- setDerivedValue(ptr->getObject());
49
61
  }
50
62
 
51
63
  private:
@@ -62,11 +74,12 @@ public:
62
74
  }
63
75
 
64
76
  void updateDerivedValue() override {
65
- if (!_imageProp->isSet()) {
66
- throw std::runtime_error("Image property is not set on the Image node.");
77
+ auto image = _imageProp->getDerivedValue();
78
+ if (image == nullptr) {
79
+ setDerivedValue(nullptr);
80
+ return;
67
81
  }
68
82
 
69
- auto image = _imageProp->getDerivedValue();
70
83
  auto imageRect = SkRect::MakeXYWH(0, 0, image->width(), image->height());
71
84
 
72
85
  auto rect = _rectProp->getDerivedValue() ? *_rectProp->getDerivedValue()
@@ -77,6 +90,7 @@ public:
77
90
  }
78
91
 
79
92
  sk_sp<SkImage> getImage() { return _imageProp->getDerivedValue(); }
93
+
80
94
  std::shared_ptr<const SkRect> getRect() {
81
95
  return _rectProp->getDerivedValue();
82
96
  }
@@ -13,7 +13,7 @@
13
13
  #pragma clang diagnostic push
14
14
  #pragma clang diagnostic ignored "-Wdocumentation"
15
15
 
16
- #include <SkPaint.h>
16
+ #include "SkPaint.h"
17
17
 
18
18
  #pragma clang diagnostic pop
19
19
 
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include <SkPath.h>
11
+ #include "SkPath.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14
 
@@ -9,7 +9,7 @@
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
- #include <SkPoint.h>
12
+ #include "SkPoint.h"
13
13
 
14
14
  #pragma clang diagnostic pop
15
15
 
@@ -11,7 +11,7 @@
11
11
  #pragma clang diagnostic push
12
12
  #pragma clang diagnostic ignored "-Wdocumentation"
13
13
 
14
- #include <SkPoint.h>
14
+ #include "SkPoint.h"
15
15
 
16
16
  #pragma clang diagnostic pop
17
17
 
@@ -9,8 +9,8 @@
9
9
  #pragma clang diagnostic push
10
10
  #pragma clang diagnostic ignored "-Wdocumentation"
11
11
 
12
- #include <SkRRect.h>
13
- #include <SkRect.h>
12
+ #include "SkRRect.h"
13
+ #include "SkRect.h"
14
14
 
15
15
  #pragma clang diagnostic pop
16
16
 
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include <SkPoint.h>
11
+ #include "SkPoint.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14
 
@@ -8,7 +8,7 @@
8
8
  #pragma clang diagnostic push
9
9
  #pragma clang diagnostic ignored "-Wdocumentation"
10
10
 
11
- #include <SkRect.h>
11
+ #include "SkRect.h"
12
12
 
13
13
  #pragma clang diagnostic pop
14
14