@shopify/react-native-skia 0.1.164 → 0.1.166

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +16 -5
  2. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +34 -0
  3. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDomViewManager.java +2 -47
  4. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawViewManager.java +2 -44
  5. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +2 -47
  6. package/cpp/api/JsiSkRuntimeEffect.h +7 -2
  7. package/cpp/rnskia/RNSkDomView.cpp +1 -1
  8. package/cpp/rnskia/RNSkPlatformContext.h +2 -6
  9. package/cpp/rnskia/dom/base/DerivedNodeProp.h +4 -4
  10. package/cpp/rnskia/dom/base/DrawingContext.cpp +5 -38
  11. package/cpp/rnskia/dom/base/DrawingContext.h +3 -17
  12. package/cpp/rnskia/dom/nodes/JsiBoxNode.h +4 -4
  13. package/cpp/rnskia/dom/nodes/JsiCircleNode.h +0 -2
  14. package/cpp/rnskia/dom/nodes/JsiCustomDrawingNode.h +1 -3
  15. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +2 -2
  16. package/cpp/rnskia/dom/nodes/JsiPathNode.h +12 -5
  17. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +17 -7
  18. package/cpp/rnskia/dom/props/CircleProp.h +2 -0
  19. package/cpp/rnskia/dom/props/ClipProp.h +6 -6
  20. package/cpp/rnskia/dom/props/ColorProp.h +9 -4
  21. package/cpp/rnskia/dom/props/ImageProps.h +6 -3
  22. package/cpp/rnskia/dom/props/PaintProps.h +15 -22
  23. package/cpp/rnskia/dom/props/RectProp.h +11 -4
  24. package/cpp/rnskia/dom/props/UniformsProp.h +86 -123
  25. package/cpp/rnskia/dom/props/VerticesProps.h +2 -2
  26. package/cpp/rnskia/values/RNSkReadonlyValue.h +2 -6
  27. package/lib/commonjs/dom/nodes/datatypes/Circle.js +6 -1
  28. package/lib/commonjs/dom/nodes/datatypes/Circle.js.map +1 -1
  29. package/lib/commonjs/dom/nodes/datatypes/Rect.js +3 -3
  30. package/lib/commonjs/dom/nodes/datatypes/Rect.js.map +1 -1
  31. package/lib/commonjs/dom/nodes/drawings/Box.js +1 -1
  32. package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
  33. package/lib/commonjs/dom/nodes/drawings/ImageNode.js +2 -2
  34. package/lib/commonjs/dom/nodes/drawings/ImageNode.js.map +1 -1
  35. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +1 -1
  36. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  37. package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -2
  38. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  39. package/lib/commonjs/dom/types/Common.js.map +1 -1
  40. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  41. package/lib/commonjs/renderer/components/Mask.js +2 -6
  42. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  43. package/lib/commonjs/renderer/components/image/Image.js +0 -5
  44. package/lib/commonjs/renderer/components/image/Image.js.map +1 -1
  45. package/lib/commonjs/renderer/components/image/ImageShader.js +20 -10
  46. package/lib/commonjs/renderer/components/image/ImageShader.js.map +1 -1
  47. package/lib/commonjs/renderer/components/imageFilters/Blur.js +10 -5
  48. package/lib/commonjs/renderer/components/imageFilters/Blur.js.map +1 -1
  49. package/lib/commonjs/renderer/components/imageFilters/Morphology.js +10 -5
  50. package/lib/commonjs/renderer/components/imageFilters/Morphology.js.map +1 -1
  51. package/lib/commonjs/renderer/components/imageFilters/Offset.js +12 -6
  52. package/lib/commonjs/renderer/components/imageFilters/Offset.js.map +1 -1
  53. package/lib/commonjs/renderer/components/maskFilters/Blur.js +12 -6
  54. package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
  55. package/lib/commonjs/renderer/components/pathEffects/Discrete.js +10 -5
  56. package/lib/commonjs/renderer/components/pathEffects/Discrete.js.map +1 -1
  57. package/lib/commonjs/renderer/components/shaders/FractalNoise.js +14 -7
  58. package/lib/commonjs/renderer/components/shaders/FractalNoise.js.map +1 -1
  59. package/lib/commonjs/renderer/components/shaders/Shader.js +10 -5
  60. package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
  61. package/lib/commonjs/renderer/components/shaders/Turbulence.js +14 -7
  62. package/lib/commonjs/renderer/components/shaders/Turbulence.js.map +1 -1
  63. package/lib/commonjs/renderer/components/shapes/Circle.js +0 -6
  64. package/lib/commonjs/renderer/components/shapes/Circle.js.map +1 -1
  65. package/lib/commonjs/renderer/components/shapes/FitBox.js +1 -4
  66. package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
  67. package/lib/commonjs/renderer/components/shapes/Oval.js +0 -4
  68. package/lib/commonjs/renderer/components/shapes/Oval.js.map +1 -1
  69. package/lib/commonjs/renderer/components/shapes/Path.js +12 -6
  70. package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
  71. package/lib/commonjs/renderer/components/shapes/Points.js +10 -5
  72. package/lib/commonjs/renderer/components/shapes/Points.js.map +1 -1
  73. package/lib/commonjs/renderer/components/shapes/RoundedRect.js +0 -3
  74. package/lib/commonjs/renderer/components/shapes/RoundedRect.js.map +1 -1
  75. package/lib/commonjs/renderer/components/shapes/Vertices.js +10 -5
  76. package/lib/commonjs/renderer/components/shapes/Vertices.js.map +1 -1
  77. package/lib/commonjs/renderer/components/text/Glyphs.js +12 -6
  78. package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
  79. package/lib/commonjs/renderer/components/text/Text.js +12 -6
  80. package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
  81. package/lib/commonjs/renderer/components/text/TextBlob.js +12 -6
  82. package/lib/commonjs/renderer/components/text/TextBlob.js.map +1 -1
  83. package/lib/commonjs/renderer/components/text/TextPath.js +10 -5
  84. package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
  85. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  86. package/lib/commonjs/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
  87. package/lib/commonjs/skia/types/Shader/Shader.js +25 -25
  88. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  89. package/lib/commonjs/skia/web/JsiSkRuntimeEffect.js +6 -1
  90. package/lib/commonjs/skia/web/JsiSkRuntimeEffect.js.map +1 -1
  91. package/lib/commonjs/skia/web/JsiSkRuntimeEffectFactory.js +1 -1
  92. package/lib/commonjs/skia/web/JsiSkRuntimeEffectFactory.js.map +1 -1
  93. package/lib/module/dom/nodes/datatypes/Circle.js +8 -1
  94. package/lib/module/dom/nodes/datatypes/Circle.js.map +1 -1
  95. package/lib/module/dom/nodes/datatypes/Rect.js +7 -3
  96. package/lib/module/dom/nodes/datatypes/Rect.js.map +1 -1
  97. package/lib/module/dom/nodes/drawings/Box.js +1 -1
  98. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  99. package/lib/module/dom/nodes/drawings/ImageNode.js +4 -2
  100. package/lib/module/dom/nodes/drawings/ImageNode.js.map +1 -1
  101. package/lib/module/dom/nodes/paint/ImageFilters.js +1 -1
  102. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  103. package/lib/module/dom/nodes/paint/Shaders.js +5 -4
  104. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  105. package/lib/module/dom/types/Common.js.map +1 -1
  106. package/lib/module/dom/types/Drawings.js.map +1 -1
  107. package/lib/module/renderer/components/Mask.js +2 -6
  108. package/lib/module/renderer/components/Mask.js.map +1 -1
  109. package/lib/module/renderer/components/image/Image.js +0 -5
  110. package/lib/module/renderer/components/image/Image.js.map +1 -1
  111. package/lib/module/renderer/components/image/ImageShader.js +20 -10
  112. package/lib/module/renderer/components/image/ImageShader.js.map +1 -1
  113. package/lib/module/renderer/components/imageFilters/Blur.js +10 -5
  114. package/lib/module/renderer/components/imageFilters/Blur.js.map +1 -1
  115. package/lib/module/renderer/components/imageFilters/Morphology.js +10 -5
  116. package/lib/module/renderer/components/imageFilters/Morphology.js.map +1 -1
  117. package/lib/module/renderer/components/imageFilters/Offset.js +12 -6
  118. package/lib/module/renderer/components/imageFilters/Offset.js.map +1 -1
  119. package/lib/module/renderer/components/maskFilters/Blur.js +12 -6
  120. package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
  121. package/lib/module/renderer/components/pathEffects/Discrete.js +10 -5
  122. package/lib/module/renderer/components/pathEffects/Discrete.js.map +1 -1
  123. package/lib/module/renderer/components/shaders/FractalNoise.js +14 -7
  124. package/lib/module/renderer/components/shaders/FractalNoise.js.map +1 -1
  125. package/lib/module/renderer/components/shaders/Shader.js +10 -5
  126. package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
  127. package/lib/module/renderer/components/shaders/Turbulence.js +14 -7
  128. package/lib/module/renderer/components/shaders/Turbulence.js.map +1 -1
  129. package/lib/module/renderer/components/shapes/Circle.js +0 -6
  130. package/lib/module/renderer/components/shapes/Circle.js.map +1 -1
  131. package/lib/module/renderer/components/shapes/FitBox.js +1 -4
  132. package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
  133. package/lib/module/renderer/components/shapes/Oval.js +0 -4
  134. package/lib/module/renderer/components/shapes/Oval.js.map +1 -1
  135. package/lib/module/renderer/components/shapes/Path.js +12 -6
  136. package/lib/module/renderer/components/shapes/Path.js.map +1 -1
  137. package/lib/module/renderer/components/shapes/Points.js +10 -5
  138. package/lib/module/renderer/components/shapes/Points.js.map +1 -1
  139. package/lib/module/renderer/components/shapes/RoundedRect.js +0 -3
  140. package/lib/module/renderer/components/shapes/RoundedRect.js.map +1 -1
  141. package/lib/module/renderer/components/shapes/Vertices.js +10 -5
  142. package/lib/module/renderer/components/shapes/Vertices.js.map +1 -1
  143. package/lib/module/renderer/components/text/Glyphs.js +12 -6
  144. package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
  145. package/lib/module/renderer/components/text/Text.js +12 -6
  146. package/lib/module/renderer/components/text/Text.js.map +1 -1
  147. package/lib/module/renderer/components/text/TextBlob.js +12 -6
  148. package/lib/module/renderer/components/text/TextBlob.js.map +1 -1
  149. package/lib/module/renderer/components/text/TextPath.js +10 -5
  150. package/lib/module/renderer/components/text/TextPath.js.map +1 -1
  151. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  152. package/lib/module/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
  153. package/lib/module/skia/types/Shader/Shader.js +25 -25
  154. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  155. package/lib/module/skia/web/JsiSkRuntimeEffect.js +6 -1
  156. package/lib/module/skia/web/JsiSkRuntimeEffect.js.map +1 -1
  157. package/lib/module/skia/web/JsiSkRuntimeEffectFactory.js +1 -1
  158. package/lib/module/skia/web/JsiSkRuntimeEffectFactory.js.map +1 -1
  159. package/lib/typescript/src/dom/nodes/datatypes/Circle.d.ts +4 -1
  160. package/lib/typescript/src/dom/types/Common.d.ts +4 -4
  161. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
  162. package/lib/typescript/src/renderer/components/Mask.d.ts +3 -9
  163. package/lib/typescript/src/renderer/components/image/Image.d.ts +1 -8
  164. package/lib/typescript/src/renderer/components/image/ImageShader.d.ts +2 -12
  165. package/lib/typescript/src/renderer/components/imageFilters/Blur.d.ts +2 -7
  166. package/lib/typescript/src/renderer/components/imageFilters/Morphology.d.ts +2 -7
  167. package/lib/typescript/src/renderer/components/imageFilters/Offset.d.ts +2 -8
  168. package/lib/typescript/src/renderer/components/maskFilters/Blur.d.ts +2 -8
  169. package/lib/typescript/src/renderer/components/pathEffects/Discrete.d.ts +2 -7
  170. package/lib/typescript/src/renderer/components/shaders/FractalNoise.d.ts +2 -9
  171. package/lib/typescript/src/renderer/components/shaders/Shader.d.ts +2 -7
  172. package/lib/typescript/src/renderer/components/shaders/Turbulence.d.ts +2 -9
  173. package/lib/typescript/src/renderer/components/shapes/Circle.d.ts +1 -9
  174. package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +2 -7
  175. package/lib/typescript/src/renderer/components/shapes/Oval.d.ts +1 -7
  176. package/lib/typescript/src/renderer/components/shapes/Path.d.ts +2 -8
  177. package/lib/typescript/src/renderer/components/shapes/Points.d.ts +2 -7
  178. package/lib/typescript/src/renderer/components/shapes/RoundedRect.d.ts +1 -6
  179. package/lib/typescript/src/renderer/components/shapes/Vertices.d.ts +2 -7
  180. package/lib/typescript/src/renderer/components/text/Glyphs.d.ts +2 -8
  181. package/lib/typescript/src/renderer/components/text/Text.d.ts +2 -8
  182. package/lib/typescript/src/renderer/components/text/TextBlob.d.ts +2 -8
  183. package/lib/typescript/src/renderer/components/text/TextPath.d.ts +2 -7
  184. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +5 -0
  185. package/lib/typescript/src/skia/types/RuntimeEffect/RuntimeEffect.d.ts +4 -0
  186. package/lib/typescript/src/skia/types/Shader/Shader.d.ts +1 -2
  187. package/lib/typescript/src/skia/web/JsiSkRuntimeEffect.d.ts +3 -1
  188. package/package.json +1 -1
  189. package/src/dom/nodes/datatypes/Circle.ts +1 -1
  190. package/src/dom/nodes/datatypes/Rect.ts +3 -3
  191. package/src/dom/nodes/drawings/Box.ts +1 -1
  192. package/src/dom/nodes/drawings/ImageNode.ts +2 -1
  193. package/src/dom/nodes/paint/ImageFilters.ts +1 -1
  194. package/src/dom/nodes/paint/Shaders.ts +5 -5
  195. package/src/dom/types/Common.ts +4 -4
  196. package/src/dom/types/Drawings.ts +1 -1
  197. package/src/renderer/components/Mask.tsx +8 -8
  198. package/src/renderer/components/image/Image.tsx +0 -6
  199. package/src/renderer/components/image/ImageShader.tsx +24 -12
  200. package/src/renderer/components/imageFilters/Blur.tsx +6 -7
  201. package/src/renderer/components/imageFilters/Morphology.tsx +6 -7
  202. package/src/renderer/components/imageFilters/Offset.tsx +7 -8
  203. package/src/renderer/components/maskFilters/Blur.tsx +7 -8
  204. package/src/renderer/components/pathEffects/Discrete.tsx +6 -9
  205. package/src/renderer/components/shaders/FractalNoise.tsx +18 -9
  206. package/src/renderer/components/shaders/Shader.tsx +6 -7
  207. package/src/renderer/components/shaders/Turbulence.tsx +15 -9
  208. package/src/renderer/components/shapes/Circle.tsx +0 -4
  209. package/src/renderer/components/shapes/FitBox.tsx +2 -6
  210. package/src/renderer/components/shapes/Oval.tsx +0 -5
  211. package/src/renderer/components/shapes/Path.tsx +7 -8
  212. package/src/renderer/components/shapes/Points.tsx +6 -7
  213. package/src/renderer/components/shapes/RoundedRect.tsx +0 -4
  214. package/src/renderer/components/shapes/Vertices.tsx +6 -7
  215. package/src/renderer/components/text/Glyphs.tsx +7 -8
  216. package/src/renderer/components/text/Text.tsx +7 -8
  217. package/src/renderer/components/text/TextBlob.tsx +7 -8
  218. package/src/renderer/components/text/TextPath.tsx +6 -7
  219. package/src/renderer/processors/Animations/Animations.ts +9 -3
  220. package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +5 -0
  221. package/src/skia/types/Shader/Shader.ts +30 -36
  222. package/src/skia/web/JsiSkRuntimeEffect.ts +5 -1
  223. package/src/skia/web/JsiSkRuntimeEffectFactory.ts +1 -1
@@ -7,25 +7,36 @@ import android.view.Surface;
7
7
  import android.view.TextureView;
8
8
 
9
9
  import com.facebook.jni.annotations.DoNotStrip;
10
+ import com.facebook.react.uimanager.PointerEvents;
11
+ import com.facebook.react.views.view.ReactViewGroup;
10
12
 
11
- public abstract class SkiaBaseView extends TextureView implements TextureView.SurfaceTextureListener {
13
+ public abstract class SkiaBaseView extends ReactViewGroup implements TextureView.SurfaceTextureListener {
12
14
 
13
15
  @DoNotStrip
14
16
  private Surface mSurface;
17
+ private TextureView mTexture;
15
18
 
16
19
  public SkiaBaseView(Context context) {
17
20
  super(context);
18
- setSurfaceTextureListener(this);
19
- setOpaque(false);
21
+ mTexture = new TextureView(context);
22
+ mTexture.setSurfaceTextureListener(this);
23
+ mTexture.setOpaque(false);
24
+ addView(mTexture);
20
25
  }
21
26
 
22
27
  @Override
23
- public void setBackgroundColor(int color) {
24
- // Texture view does not support setting the background color.
28
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
29
+ super.onLayout(changed, left, top, right, bottom);
30
+ mTexture.layout(0, 0, this.getMeasuredWidth(), this.getMeasuredHeight());
25
31
  }
26
32
 
27
33
  @Override
28
34
  public boolean onTouchEvent(MotionEvent ev) {
35
+ // We do not accept the touch event if this view is not supposed to receive it.
36
+ if (!PointerEvents.canBeTouchTarget(getPointerEvents())) {
37
+ return false;
38
+ }
39
+
29
40
  // https://developer.android.com/training/gestures/multi
30
41
  int action = ev.getActionMasked();
31
42
 
@@ -0,0 +1,34 @@
1
+ package com.shopify.reactnative.skia;
2
+
3
+ import com.facebook.react.uimanager.annotations.ReactProp;
4
+ import com.facebook.react.views.view.ReactViewGroup;
5
+ import com.facebook.react.views.view.ReactViewManager;
6
+
7
+ import androidx.annotation.NonNull;
8
+ import androidx.annotation.Nullable;
9
+
10
+ public abstract class SkiaBaseViewManager extends ReactViewManager {
11
+
12
+ @Override
13
+ public void setNativeId(@NonNull ReactViewGroup view, @Nullable String nativeId) {
14
+ super.setNativeId(view, nativeId);
15
+ int nativeIdResolved = Integer.parseInt(nativeId);
16
+ ((SkiaBaseView)view).registerView(nativeIdResolved);
17
+ }
18
+
19
+ @ReactProp(name = "mode")
20
+ public void setMode(ReactViewGroup view, String mode) {
21
+ ((SkiaBaseView)view).setMode(mode);
22
+ }
23
+
24
+ @ReactProp(name = "debug")
25
+ public void setDebug(ReactViewGroup view, boolean show) {
26
+ ((SkiaBaseView)view).setDebugMode(show);
27
+ }
28
+
29
+ @Override
30
+ public void onDropViewInstance(@NonNull ReactViewGroup view) {
31
+ super.onDropViewInstance(view);
32
+ ((SkiaBaseView)view).unregisterView();
33
+ }
34
+ }
@@ -1,17 +1,9 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.bridge.ReactContext;
4
- import com.facebook.react.uimanager.BaseViewManager;
5
- import com.facebook.react.uimanager.LayoutShadowNode;
6
3
  import com.facebook.react.uimanager.ThemedReactContext;
7
- import com.facebook.react.uimanager.annotations.ReactProp;
8
-
9
4
  import androidx.annotation.NonNull;
10
- import androidx.annotation.Nullable;
11
-
12
- import java.util.HashMap;
13
5
 
14
- public class SkiaDomViewManager extends BaseViewManager<SkiaDomView, LayoutShadowNode> {
6
+ public class SkiaDomViewManager extends SkiaBaseViewManager {
15
7
 
16
8
  @NonNull
17
9
  @Override
@@ -19,46 +11,9 @@ public class SkiaDomViewManager extends BaseViewManager<SkiaDomView, LayoutShado
19
11
  return "SkiaDomView";
20
12
  }
21
13
 
22
- @Override
23
- public LayoutShadowNode createShadowNodeInstance() {
24
- return new LayoutShadowNode();
25
- }
26
-
27
- @Override
28
- public Class<? extends LayoutShadowNode> getShadowNodeClass() {
29
- return LayoutShadowNode.class;
30
- }
31
-
32
- @Override
33
- public void updateExtraData(SkiaDomView root, Object extraData) {
34
- }
35
-
36
- @Override
37
- public void setNativeId(@NonNull SkiaDomView view, @Nullable String nativeId) {
38
- super.setNativeId(view, nativeId);
39
- int nativeIdResolved = Integer.parseInt(nativeId);
40
- view.registerView(nativeIdResolved);
41
- }
42
-
43
- @ReactProp(name = "mode")
44
- public void setMode(SkiaDomView view, String mode) {
45
- view.setMode(mode);
46
- }
47
-
48
- @ReactProp(name = "debug")
49
- public void setDebug(SkiaDomView view, boolean show) {
50
- view.setDebugMode(show);
51
- }
52
-
53
- @Override
54
- public void onDropViewInstance(@NonNull SkiaDomView view) {
55
- super.onDropViewInstance(view);
56
- view.unregisterView();
57
- }
58
-
59
14
  @NonNull
60
15
  @Override
61
- protected SkiaDomView createViewInstance(@NonNull ThemedReactContext reactContext) {
16
+ public SkiaDomView createViewInstance(@NonNull ThemedReactContext reactContext) {
62
17
  return new SkiaDomView(reactContext);
63
18
  }
64
19
  }
@@ -1,14 +1,9 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.uimanager.BaseViewManager;
4
- import com.facebook.react.uimanager.LayoutShadowNode;
5
3
  import com.facebook.react.uimanager.ThemedReactContext;
6
- import com.facebook.react.uimanager.annotations.ReactProp;
7
-
8
4
  import androidx.annotation.NonNull;
9
- import androidx.annotation.Nullable;
10
5
 
11
- public class SkiaDrawViewManager extends BaseViewManager<SkiaDrawView, LayoutShadowNode> {
6
+ public class SkiaDrawViewManager extends SkiaBaseViewManager {
12
7
 
13
8
  @NonNull
14
9
  @Override
@@ -16,46 +11,9 @@ public class SkiaDrawViewManager extends BaseViewManager<SkiaDrawView, LayoutSha
16
11
  return "SkiaDrawView";
17
12
  }
18
13
 
19
- @Override
20
- public LayoutShadowNode createShadowNodeInstance() {
21
- return new LayoutShadowNode();
22
- }
23
-
24
- @Override
25
- public Class<? extends LayoutShadowNode> getShadowNodeClass() {
26
- return LayoutShadowNode.class;
27
- }
28
-
29
- @Override
30
- public void updateExtraData(SkiaDrawView root, Object extraData) {
31
- }
32
-
33
- @Override
34
- public void setNativeId(@NonNull SkiaDrawView view, @Nullable String nativeId) {
35
- super.setNativeId(view, nativeId);
36
- int nativeIdResolved = Integer.parseInt(nativeId);
37
- view.registerView(nativeIdResolved);
38
- }
39
-
40
- @ReactProp(name = "mode")
41
- public void setMode(SkiaDrawView view, String mode) {
42
- view.setMode(mode);
43
- }
44
-
45
- @ReactProp(name = "debug")
46
- public void setDebug(SkiaDrawView view, boolean show) {
47
- view.setDebugMode(show);
48
- }
49
-
50
- @Override
51
- public void onDropViewInstance(@NonNull SkiaDrawView view) {
52
- super.onDropViewInstance(view);
53
- view.unregisterView();
54
- }
55
-
56
14
  @NonNull
57
15
  @Override
58
- protected SkiaDrawView createViewInstance(@NonNull ThemedReactContext reactContext) {
16
+ public SkiaDrawView createViewInstance(@NonNull ThemedReactContext reactContext) {
59
17
  return new SkiaDrawView(reactContext);
60
18
  }
61
19
  }
@@ -1,17 +1,9 @@
1
1
  package com.shopify.reactnative.skia;
2
2
 
3
- import com.facebook.react.bridge.ReactContext;
4
- import com.facebook.react.uimanager.BaseViewManager;
5
- import com.facebook.react.uimanager.LayoutShadowNode;
6
3
  import com.facebook.react.uimanager.ThemedReactContext;
7
- import com.facebook.react.uimanager.annotations.ReactProp;
8
-
9
4
  import androidx.annotation.NonNull;
10
- import androidx.annotation.Nullable;
11
-
12
- import java.util.HashMap;
13
5
 
14
- public class SkiaPictureViewManager extends BaseViewManager<SkiaPictureView, LayoutShadowNode> {
6
+ public class SkiaPictureViewManager extends SkiaBaseViewManager {
15
7
 
16
8
  @NonNull
17
9
  @Override
@@ -19,46 +11,9 @@ public class SkiaPictureViewManager extends BaseViewManager<SkiaPictureView, Lay
19
11
  return "SkiaPictureView";
20
12
  }
21
13
 
22
- @Override
23
- public LayoutShadowNode createShadowNodeInstance() {
24
- return new LayoutShadowNode();
25
- }
26
-
27
- @Override
28
- public Class<? extends LayoutShadowNode> getShadowNodeClass() {
29
- return LayoutShadowNode.class;
30
- }
31
-
32
- @Override
33
- public void updateExtraData(SkiaPictureView root, Object extraData) {
34
- }
35
-
36
- @Override
37
- public void setNativeId(@NonNull SkiaPictureView view, @Nullable String nativeId) {
38
- super.setNativeId(view, nativeId);
39
- int nativeIdResolved = Integer.parseInt(nativeId);
40
- view.registerView(nativeIdResolved);
41
- }
42
-
43
- @ReactProp(name = "mode")
44
- public void setMode(SkiaPictureView view, String mode) {
45
- view.setMode(mode);
46
- }
47
-
48
- @ReactProp(name = "debug")
49
- public void setDebug(SkiaPictureView view, boolean show) {
50
- view.setDebugMode(show);
51
- }
52
-
53
- @Override
54
- public void onDropViewInstance(@NonNull SkiaPictureView view) {
55
- super.onDropViewInstance(view);
56
- view.unregisterView();
57
- }
58
-
59
14
  @NonNull
60
15
  @Override
61
- protected SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
16
+ public SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
62
17
  return new SkiaPictureView(reactContext);
63
18
  }
64
19
  }
@@ -117,6 +117,10 @@ public:
117
117
  return result;
118
118
  }
119
119
 
120
+ JSI_HOST_FUNCTION(source) {
121
+ return jsi::String::createFromAscii(runtime, getObject()->source());
122
+ }
123
+
120
124
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkRuntimeEffect, makeShader),
121
125
  JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
122
126
  makeShaderWithChildren),
@@ -124,7 +128,8 @@ public:
124
128
  JSI_EXPORT_FUNC(JsiSkRuntimeEffect,
125
129
  getUniformFloatCount),
126
130
  JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniformName),
127
- JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform))
131
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, getUniform),
132
+ JSI_EXPORT_FUNC(JsiSkRuntimeEffect, source))
128
133
 
129
134
  JsiSkRuntimeEffect(std::shared_ptr<RNSkPlatformContext> context,
130
135
  sk_sp<SkRuntimeEffect> rt)
@@ -206,7 +211,7 @@ private:
206
211
  const std::size_t offset = reu.slot + j;
207
212
  float fValue = jsiUniforms.getValueAtIndex(runtime, offset).asNumber();
208
213
  int iValue = static_cast<int>(fValue);
209
- auto value = reu.isInteger ? iValue : fValue;
214
+ auto value = reu.isInteger ? SkBits2Float(iValue) : fValue;
210
215
  memcpy(SkTAddOffset<void>(uniforms->writable_data(),
211
216
  offset * sizeof(value)),
212
217
  &value, sizeof(value));
@@ -86,7 +86,7 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
86
86
  if (_drawingContext == nullptr) {
87
87
  auto paint = std::make_shared<SkPaint>();
88
88
  paint->setAntiAlias(true);
89
- _drawingContext = std::make_shared<DrawingContext>(paint, 1.0f);
89
+ _drawingContext = std::make_shared<DrawingContext>(paint);
90
90
 
91
91
  _drawingContext->setRequestRedraw([weakSelf = weak_from_this()]() {
92
92
  auto self = weakSelf.lock();
@@ -178,12 +178,8 @@ public:
178
178
  if (!_isValid) {
179
179
  return;
180
180
  }
181
- std::unordered_map<size_t, std::function<void(bool)>> tmp;
182
- {
183
- std::lock_guard<std::mutex> lock(_drawCallbacksLock);
184
- tmp.insert(_drawCallbacks.cbegin(), _drawCallbacks.cend());
185
- }
186
- for (auto it = tmp.begin(); it != tmp.end(); it++) {
181
+ std::lock_guard<std::mutex> lock(_drawCallbacksLock);
182
+ for (auto it = _drawCallbacks.begin(); it != _drawCallbacks.end(); it++) {
187
183
  it->second(invalidated);
188
184
  }
189
185
  }
@@ -116,7 +116,7 @@ public:
116
116
  /**
117
117
  Returns the derived value
118
118
  */
119
- std::shared_ptr<T> getDerivedValue() { return _derivedValue; }
119
+ std::shared_ptr<const T> getDerivedValue() { return _derivedValue; }
120
120
 
121
121
  /**
122
122
  Returns true if is optional and one of the child props has a value, or all
@@ -128,7 +128,7 @@ protected:
128
128
  /**
129
129
  Set derived value from sub classes
130
130
  */
131
- void setDerivedValue(std::shared_ptr<T> value) {
131
+ void setDerivedValue(std::shared_ptr<const T> value) {
132
132
  setIsChanged(_derivedValue != value);
133
133
  _derivedValue = value;
134
134
  }
@@ -138,11 +138,11 @@ protected:
138
138
  */
139
139
  void setDerivedValue(const T &&value) {
140
140
  setIsChanged(true);
141
- _derivedValue = std::make_shared<T>(std::move(value));
141
+ _derivedValue = std::make_shared<const T>(std::move(value));
142
142
  }
143
143
 
144
144
  private:
145
- std::shared_ptr<T> _derivedValue;
145
+ std::shared_ptr<const T> _derivedValue;
146
146
  };
147
147
 
148
148
  /**
@@ -2,10 +2,9 @@
2
2
 
3
3
  namespace RNSkia {
4
4
 
5
- DrawingContext::DrawingContext(std::shared_ptr<SkPaint> paint, double opacity)
5
+ DrawingContext::DrawingContext(std::shared_ptr<SkPaint> paint)
6
6
  : DrawingContext("root") {
7
7
  _paint = paint;
8
- _opacity = opacity;
9
8
  }
10
9
 
11
10
  DrawingContext::DrawingContext(DrawingContext *parent, const char *source)
@@ -43,7 +42,8 @@ std::string DrawingContext::getDebugDescription() {
43
42
  v += " blendMode:" + std::to_string(static_cast<size_t>(blendMode));
44
43
  }
45
44
 
46
- v += " opacity:" + std::to_string(_opacity);
45
+ auto opacity = _paint->getAlphaf();
46
+ v += " opacity:" + std::to_string(opacity);
47
47
 
48
48
  if (_paint->getPathEffect() != nullptr) {
49
49
  v += " [PathEffect]";
@@ -148,7 +148,6 @@ std::shared_ptr<SkPaint> DrawingContext::getMutablePaint() {
148
148
  if (_paint == nullptr) {
149
149
  auto parentPaint = _parent->getPaint();
150
150
  _paint = std::make_shared<SkPaint>(*parentPaint);
151
- _opacity = _parent->getOpacity();
152
151
  }
153
152
  // Calling the getMutablePaint accessor implies that the paint
154
153
  // is about to be mutatet and will therefore invalidate
@@ -165,40 +164,6 @@ void DrawingContext::setMutablePaint(std::shared_ptr<SkPaint> paint) {
165
164
  _paint = paint;
166
165
  }
167
166
 
168
- /**
169
- Getd the opacity value
170
- */
171
- double DrawingContext::getOpacity() {
172
- if (_paint == nullptr) {
173
- return _parent->getOpacity();
174
- }
175
- return _opacity;
176
- }
177
-
178
- /**
179
- Sets the opacity value
180
- */
181
- void DrawingContext::setOpacity(double opacity) {
182
- auto currentOpacity = opacity;
183
- if (_parent != nullptr) {
184
- currentOpacity *= _parent->getOpacity();
185
- }
186
- getMutablePaint()->setAlphaf(currentOpacity);
187
- _opacity = currentOpacity;
188
- }
189
-
190
- /**
191
- Clears the opacity value
192
- */
193
- void DrawingContext::clearOpacity() {
194
- if (_parent != nullptr) {
195
- _opacity = _parent->getOpacity();
196
- } else {
197
- _opacity = 1.0;
198
- }
199
- markChildrenAsChanged();
200
- }
201
-
202
167
  float DrawingContext::getScaledWidth() {
203
168
  if (_parent != nullptr) {
204
169
  return _parent->getScaledWidth();
@@ -213,6 +178,8 @@ float DrawingContext::getScaledHeight() {
213
178
  return _scaledHeight;
214
179
  }
215
180
 
181
+ DrawingContext *DrawingContext::getParent() { return _parent; }
182
+
216
183
  void DrawingContext::setScaledWidth(float v) { _scaledWidth = v; }
217
184
  void DrawingContext::setScaledHeight(float v) { _scaledHeight = v; }
218
185
 
@@ -22,7 +22,7 @@ public:
22
22
  /**
23
23
  Creates a root drawing context with paint and opacity
24
24
  */
25
- DrawingContext(std::shared_ptr<SkPaint> paint, double opacity);
25
+ explicit DrawingContext(std::shared_ptr<SkPaint> paint);
26
26
 
27
27
  /**
28
28
  Initilalizes a new draw context.
@@ -87,21 +87,6 @@ public:
87
87
  */
88
88
  void setMutablePaint(std::shared_ptr<SkPaint> paint);
89
89
 
90
- /**
91
- Getd the opacity value
92
- */
93
- double getOpacity();
94
-
95
- /**
96
- Sets the opacity value
97
- */
98
- void setOpacity(double opacity);
99
-
100
- /**
101
- Clears the opacity
102
- */
103
- void clearOpacity();
104
-
105
90
  float getScaledWidth();
106
91
 
107
92
  float getScaledHeight();
@@ -112,6 +97,8 @@ public:
112
97
  void setRequestRedraw(std::function<void()> &&requestRedraw);
113
98
  const std::function<void()> &getRequestRedraw();
114
99
 
100
+ DrawingContext *getParent();
101
+
115
102
  private:
116
103
  explicit DrawingContext(const char *source);
117
104
 
@@ -120,7 +107,6 @@ private:
120
107
  bool _isChanged = true;
121
108
 
122
109
  std::shared_ptr<SkPaint> _paint;
123
- double _opacity = 1.0f;
124
110
 
125
111
  SkCanvas *_canvas = nullptr;
126
112
  const char *_source;
@@ -81,8 +81,8 @@ protected:
81
81
  }
82
82
 
83
83
  private:
84
- SkRRect inflate(const SkRRect &box, SkScalar dx, SkScalar dy, size_t tx = 0,
85
- size_t ty = 0) {
84
+ SkRRect inflate(const SkRRect &box, SkScalar dx, SkScalar dy, SkScalar tx = 0,
85
+ SkScalar ty = 0) {
86
86
  return SkRRect::MakeRectXY(
87
87
  SkRect::MakeXYWH(box.rect().x() - dx + tx, box.rect().y() - dy + ty,
88
88
  box.rect().width() + 2 * dx,
@@ -90,8 +90,8 @@ private:
90
90
  box.getSimpleRadii().x() + dx, box.getSimpleRadii().y() + dy);
91
91
  }
92
92
 
93
- SkRRect deflate(const SkRRect &box, SkScalar dx, SkScalar dy, size_t tx = 0,
94
- size_t ty = 0) {
93
+ SkRRect deflate(const SkRRect &box, SkScalar dx, SkScalar dy, SkScalar tx = 0,
94
+ SkScalar ty = 0) {
95
95
  return inflate(box, -dx, -dy, tx, ty);
96
96
  }
97
97
 
@@ -24,8 +24,6 @@ protected:
24
24
  JsiDomDrawingNode::defineProperties(container);
25
25
  _circleProp = container->defineProperty<CircleProp>();
26
26
  _radiusProp = container->defineProperty<NodeProp>("r");
27
-
28
- _circleProp->require();
29
27
  _radiusProp->require();
30
28
  }
31
29
 
@@ -28,7 +28,6 @@ protected:
28
28
  float scaledWidth = context->getScaledWidth();
29
29
  float scaledHeight = context->getScaledHeight();
30
30
  auto paint = context->getPaint();
31
- auto opacity = context->getOpacity();
32
31
  auto platformContext = getContext();
33
32
  auto requestRedraw = context->getRequestRedraw();
34
33
 
@@ -44,7 +43,7 @@ protected:
44
43
  }
45
44
 
46
45
  // Run rendering on the javascript thread
47
- getContext()->runOnJavascriptThread([this, platformContext, opacity,
46
+ getContext()->runOnJavascriptThread([this, platformContext,
48
47
  requestRedraw, scaledWidth,
49
48
  scaledHeight]() {
50
49
  // Get the runtime
@@ -65,7 +64,6 @@ protected:
65
64
  *runtime, "paint",
66
65
  jsi::Object::createFromHostObject(*runtime, this->_jsiPaint));
67
66
 
68
- jsiCtx.setProperty(*runtime, "opacity", opacity);
69
67
  jsiCtx.setProperty(
70
68
  *runtime, "canvas",
71
69
  jsi::Object::createFromHostObject(*runtime, jsiCanvas));
@@ -384,14 +384,14 @@ protected:
384
384
  JsiBaseDomDeclarationNode::defineProperties(container);
385
385
  _sourceProp = container->defineProperty<NodeProp>("source");
386
386
  _uniformsProp =
387
- container->defineProperty<SimpleUniformsProp>("uniforms", _sourceProp);
387
+ container->defineProperty<UniformsProp>("uniforms", _sourceProp);
388
388
 
389
389
  _sourceProp->require();
390
390
  }
391
391
 
392
392
  private:
393
393
  NodeProp *_sourceProp;
394
- SimpleUniformsProp *_uniformsProp;
394
+ UniformsProp *_uniformsProp;
395
395
  };
396
396
 
397
397
  } // namespace RNSkia
@@ -59,20 +59,22 @@ protected:
59
59
  ", end: " + std::to_string(_endProp->value().getAsNumber()));
60
60
  }
61
61
  filteredPath.swap(filteredPath);
62
- _path = std::make_shared<SkPath>(filteredPath);
62
+ _path = std::make_shared<const SkPath>(filteredPath);
63
63
  } else if (hasStartOffset || hasEndOffset) {
64
64
  throw std::runtime_error(
65
65
  "Failed trimming path with parameters start: " +
66
66
  std::to_string(_startProp->value().getAsNumber()) +
67
67
  ", end: " + std::to_string(_endProp->value().getAsNumber()));
68
68
  } else {
69
- _path = std::make_shared<SkPath>(filteredPath);
69
+ _path = std::make_shared<const SkPath>(filteredPath);
70
70
  }
71
71
 
72
72
  // Set fill style
73
73
  if (_fillTypeProp->isSet()) {
74
74
  auto fillType = _fillTypeProp->value().getAsString();
75
- _path->setFillType(getFillTypeFromStringValue(fillType));
75
+ auto p = std::make_shared<SkPath>(*_path.get());
76
+ p->setFillType(getFillTypeFromStringValue(fillType));
77
+ _path = std::const_pointer_cast<const SkPath>(p);
76
78
  }
77
79
 
78
80
  // do we have a special paint here?
@@ -105,9 +107,14 @@ protected:
105
107
  precision = opts.getValue(PropNamePrecision).getAsNumber();
106
108
  }
107
109
 
108
- if (!strokePaint.getFillPath(*_path.get(), _path.get(), nullptr,
110
+ // _path is const so we can't mutate it directly, let's replace the
111
+ // path like this:
112
+ auto p = std::make_shared<SkPath>(*_path.get());
113
+ if (!strokePaint.getFillPath(*_path.get(), p.get(), nullptr,
109
114
  precision)) {
110
115
  _path = nullptr;
116
+ } else {
117
+ _path = std::const_pointer_cast<const SkPath>(p);
111
118
  }
112
119
  }
113
120
 
@@ -157,7 +164,7 @@ private:
157
164
  NodeProp *_fillTypeProp;
158
165
  NodeProp *_strokeOptsProp;
159
166
 
160
- std::shared_ptr<SkPath> _path;
167
+ std::shared_ptr<const SkPath> _path;
161
168
  };
162
169
 
163
170
  class StrokeOptsProps : public BaseDerivedProp {
@@ -121,8 +121,16 @@ protected:
121
121
  if (rect != nullptr && lm != nullptr) {
122
122
  auto rc = _imageProps->getDerivedValue();
123
123
  auto m3 = _imageProps->rect2rect(rc->src, rc->dst);
124
- lm->preTranslate(m3.x(), m3.y());
125
- lm->preScale(m3.width(), m3.height());
124
+ if (_transformProp->isChanged()) {
125
+ // To modify the matrix we need to copy it since we're not allowed to
126
+ // modify values contained in properties - this would have caused the
127
+ // matrix to be translated and scaled more and more for each render
128
+ // even thought the matrix prop did not change.
129
+ _matrix.reset();
130
+ _matrix.preConcat(*lm);
131
+ _matrix.preTranslate(m3.x(), m3.y());
132
+ _matrix.preScale(m3.width(), m3.height());
133
+ }
126
134
  }
127
135
 
128
136
  setShader(
@@ -133,7 +141,7 @@ protected:
133
141
  _filterModeProp->value().getAsString()),
134
142
  getMipmapModeFromString(
135
143
  _mipmapModeProp->value().getAsString())),
136
- lm));
144
+ &_matrix));
137
145
  }
138
146
  }
139
147
 
@@ -185,6 +193,8 @@ private:
185
193
  "\" is not a valid Mipmap Mode.");
186
194
  }
187
195
 
196
+ SkMatrix _matrix;
197
+
188
198
  TileModeProp *_txProp;
189
199
  TileModeProp *_tyProp;
190
200
  NodeProp *_filterModeProp;
@@ -328,12 +338,12 @@ protected:
328
338
  }
329
339
  }
330
340
 
331
- SkColor *_colors;
332
- SkTileMode _mode;
341
+ const SkColor *_colors;
333
342
  double _flags;
334
- SkScalar *_positions;
335
- SkMatrix *_matrix;
336
343
  int _colorCount;
344
+ SkTileMode _mode;
345
+ const SkScalar *_positions;
346
+ const SkMatrix *_matrix;
337
347
 
338
348
  private:
339
349
  TransformsProps *_transformsProps;
@@ -34,6 +34,8 @@ public:
34
34
  _cy->value().getAsNumber()));
35
35
  } else if (_c->isSet()) {
36
36
  setDerivedValue(_c->getDerivedValue());
37
+ } else {
38
+ setDerivedValue(SkPoint::Make(0.0, 0.0));
37
39
  }
38
40
  }
39
41