@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
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
2
 
3
3
  import type { BlurMaskFilterProps } from "../../../dom/types";
4
- import type { SkiaProps } from "../../processors/Animations/Animations";
4
+ import type { SkiaDefaultProps } from "../../processors/Animations/Animations";
5
5
 
6
- export const BlurMask = (props: SkiaProps<BlurMaskFilterProps>) => {
7
- return <skBlurMaskFilter {...props} />;
8
- };
9
-
10
- BlurMask.defaultProps = {
11
- style: "normal",
12
- respectCTM: true,
6
+ export const BlurMask = ({
7
+ style = "normal",
8
+ respectCTM = true,
9
+ ...props
10
+ }: SkiaDefaultProps<BlurMaskFilterProps, "style" | "respectCTM">) => {
11
+ return <skBlurMaskFilter style={style} respectCTM={respectCTM} {...props} />;
13
12
  };
@@ -1,14 +1,11 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors/Animations/Animations";
3
+ import type { SkiaDefaultProps } from "../../processors/Animations/Animations";
4
4
  import type { DiscretePathEffectProps } from "../../../dom/types";
5
5
 
6
- export const DiscretePathEffect = (
7
- props: SkiaProps<DiscretePathEffectProps>
8
- ) => {
9
- return <skDiscretePathEffect {...props} />;
10
- };
11
-
12
- DiscretePathEffect.defaultProps = {
13
- seed: 0,
6
+ export const DiscretePathEffect = ({
7
+ seed = 0,
8
+ ...props
9
+ }: SkiaDefaultProps<DiscretePathEffectProps, "seed">) => {
10
+ return <skDiscretePathEffect seed={seed} {...props} />;
14
11
  };
@@ -1,14 +1,23 @@
1
1
  import React from "react";
2
2
 
3
3
  import type { FractalNoiseProps } from "../../../dom/types";
4
- import type { SkiaProps } from "../../processors/Animations/Animations";
4
+ import type { SkiaDefaultProps } from "../../processors/Animations/Animations";
5
5
 
6
- export const FractalNoise = (props: SkiaProps<FractalNoiseProps>) => {
7
- return <skFractalNoise {...props} />;
8
- };
9
-
10
- FractalNoise.defaultProps = {
11
- seed: 0,
12
- tileWidth: 0,
13
- tileHeight: 0,
6
+ export const FractalNoise = ({
7
+ seed = 0,
8
+ tileWidth = 0,
9
+ tileHeight = 0,
10
+ ...props
11
+ }: SkiaDefaultProps<
12
+ FractalNoiseProps,
13
+ "seed" | "tileHeight" | "tileWidth"
14
+ >) => {
15
+ return (
16
+ <skFractalNoise
17
+ seed={seed}
18
+ tileWidth={tileWidth}
19
+ tileHeight={tileHeight}
20
+ {...props}
21
+ />
22
+ );
14
23
  };
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors";
3
+ import type { SkiaDefaultProps } from "../../processors";
4
4
  import type { ShaderProps } from "../../../dom/types";
5
5
 
6
- export const Shader = (props: SkiaProps<ShaderProps>) => {
7
- return <skShader {...props} />;
8
- };
9
-
10
- Shader.defaultProps = {
11
- uniforms: [],
6
+ export const Shader = ({
7
+ uniforms = {},
8
+ ...props
9
+ }: SkiaDefaultProps<ShaderProps, "uniforms">) => {
10
+ return <skShader uniforms={uniforms} {...props} />;
12
11
  };
@@ -1,14 +1,20 @@
1
1
  import React from "react";
2
2
 
3
3
  import type { TurbulenceProps } from "../../../dom/types";
4
- import type { SkiaProps } from "../../processors/Animations/Animations";
4
+ import type { SkiaDefaultProps } from "../../processors/Animations/Animations";
5
5
 
6
- export const Turbulence = (props: SkiaProps<TurbulenceProps>) => {
7
- return <skTurbulence {...props} />;
8
- };
9
-
10
- Turbulence.defaultProps = {
11
- seed: 0,
12
- tileWidth: 0,
13
- tileHeight: 0,
6
+ export const Turbulence = ({
7
+ seed = 0,
8
+ tileWidth = 0,
9
+ tileHeight = 0,
10
+ ...props
11
+ }: SkiaDefaultProps<TurbulenceProps, "seed" | "tileWidth" | "tileHeight">) => {
12
+ return (
13
+ <skTurbulence
14
+ seed={seed}
15
+ tileWidth={tileWidth}
16
+ tileHeight={tileHeight}
17
+ {...props}
18
+ />
19
+ );
14
20
  };
@@ -6,7 +6,3 @@ import type { CircleProps } from "../../../dom/types";
6
6
  export const Circle = (props: SkiaProps<CircleProps>) => {
7
7
  return <skCircle {...props} />;
8
8
  };
9
-
10
- Circle.defaultProps = {
11
- c: { x: 0, y: 0 },
12
- };
@@ -7,7 +7,7 @@ import type { SkRect } from "../../../skia/types";
7
7
  import { Group } from "../Group";
8
8
 
9
9
  interface FitProps {
10
- fit: Fit;
10
+ fit?: Fit;
11
11
  src: SkRect;
12
12
  dst: SkRect;
13
13
  children: ReactNode | ReactNode[];
@@ -18,11 +18,7 @@ export const fitbox = (fit: Fit, src: SkRect, dst: SkRect) => {
18
18
  return rect2rect(rects.src, rects.dst);
19
19
  };
20
20
 
21
- export const FitBox = ({ fit, src, dst, children }: FitProps) => {
21
+ export const FitBox = ({ fit = "contain", src, dst, children }: FitProps) => {
22
22
  const transform = useMemo(() => fitbox(fit, src, dst), [dst, fit, src]);
23
23
  return <Group transform={transform}>{children}</Group>;
24
24
  };
25
-
26
- FitBox.defaultProps = {
27
- fit: "contain",
28
- };
@@ -6,8 +6,3 @@ import type { SkiaProps } from "../../processors";
6
6
  export const Oval = (props: SkiaProps<OvalProps>) => {
7
7
  return <skOval {...props} />;
8
8
  };
9
-
10
- Oval.defaultProps = {
11
- x: 0,
12
- y: 0,
13
- };
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors";
3
+ import type { SkiaDefaultProps } from "../../processors";
4
4
  import type { PathProps } from "../../../dom/types";
5
5
 
6
- export const Path = (props: SkiaProps<PathProps>) => {
7
- return <skPath {...props} />;
8
- };
9
-
10
- Path.defaultProps = {
11
- start: 0,
12
- end: 1,
6
+ export const Path = ({
7
+ start = 0,
8
+ end = 1,
9
+ ...props
10
+ }: SkiaDefaultProps<PathProps, "start" | "end">) => {
11
+ return <skPath start={start} end={end} {...props} />;
13
12
  };
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors/Animations/Animations";
3
+ import type { SkiaDefaultProps } from "../../processors/Animations/Animations";
4
4
  import type { PointsProps } from "../../../dom/types";
5
5
 
6
- export const Points = (props: SkiaProps<PointsProps>) => {
7
- return <skPoints {...props} />;
8
- };
9
-
10
- Points.defaultProps = {
11
- mode: "points",
6
+ export const Points = ({
7
+ mode = "points",
8
+ ...props
9
+ }: SkiaDefaultProps<PointsProps, "mode">) => {
10
+ return <skPoints mode={mode} {...props} />;
12
11
  };
@@ -6,7 +6,3 @@ import type { SkiaProps } from "../../processors";
6
6
  export const RoundedRect = (props: SkiaProps<RoundedRectProps>) => {
7
7
  return <skRRect {...props} />;
8
8
  };
9
-
10
- RoundedRect.defaultProps = {
11
- r: 0,
12
- };
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors";
3
+ import type { SkiaDefaultProps } from "../../processors";
4
4
  import type { VerticesProps } from "../../../dom/types";
5
5
 
6
- export const Vertices = (props: SkiaProps<VerticesProps>) => {
7
- return <skVertices {...props} />;
8
- };
9
-
10
- Vertices.defaultProps = {
11
- mode: "triangles",
6
+ export const Vertices = ({
7
+ mode = "triangles",
8
+ ...props
9
+ }: SkiaDefaultProps<VerticesProps, "mode">) => {
10
+ return <skVertices mode={mode} {...props} />;
12
11
  };
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
2
 
3
3
  import type { GlyphsProps } from "../../../dom/types";
4
- import type { SkiaProps } from "../../processors/Animations/Animations";
4
+ import type { SkiaDefaultProps } from "../../processors/Animations/Animations";
5
5
 
6
- export const Glyphs = (props: SkiaProps<GlyphsProps>) => {
7
- return <skGlyphs {...props} />;
8
- };
9
-
10
- Glyphs.defaultProps = {
11
- x: 0,
12
- y: 0,
6
+ export const Glyphs = ({
7
+ x = 0,
8
+ y = 0,
9
+ ...props
10
+ }: SkiaDefaultProps<GlyphsProps, "x" | "y">) => {
11
+ return <skGlyphs x={x} y={y} {...props} />;
13
12
  };
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors";
3
+ import type { SkiaDefaultProps } from "../../processors";
4
4
  import type { TextProps } from "../../../dom/types";
5
5
 
6
- export const Text = (props: SkiaProps<TextProps>) => {
7
- return <skText {...props} />;
8
- };
9
-
10
- Text.defaultProps = {
11
- x: 0,
12
- y: 0,
6
+ export const Text = ({
7
+ x = 0,
8
+ y = 0,
9
+ ...props
10
+ }: SkiaDefaultProps<TextProps, "x" | "y">) => {
11
+ return <skText x={x} y={y} {...props} />;
13
12
  };
@@ -1,13 +1,12 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors";
3
+ import type { SkiaDefaultProps } from "../../processors";
4
4
  import type { TextBlobProps } from "../../../dom/types";
5
5
 
6
- export const TextBlob = (props: SkiaProps<TextBlobProps>) => {
7
- return <skTextBlob {...props} />;
8
- };
9
-
10
- TextBlob.defaultProps = {
11
- x: 0,
12
- y: 0,
6
+ export const TextBlob = ({
7
+ x = 0,
8
+ y = 0,
9
+ ...props
10
+ }: SkiaDefaultProps<TextBlobProps, "x" | "y">) => {
11
+ return <skTextBlob x={x} y={y} {...props} />;
13
12
  };
@@ -1,12 +1,11 @@
1
1
  import React from "react";
2
2
 
3
- import type { SkiaProps } from "../../processors";
3
+ import type { SkiaDefaultProps } from "../../processors";
4
4
  import type { TextPathProps } from "../../../dom/types";
5
5
 
6
- export const TextPath = (props: SkiaProps<TextPathProps>) => {
7
- return <skTextPath {...props} />;
8
- };
9
-
10
- TextPath.defaultProps = {
11
- initialOffset: 0,
6
+ export const TextPath = ({
7
+ initialOffset = 0,
8
+ ...props
9
+ }: SkiaDefaultProps<TextPathProps, "initialOffset">) => {
10
+ return <skTextPath initialOffset={initialOffset} {...props} />;
12
11
  };
@@ -54,10 +54,16 @@ export type AnimatedProps<T, O extends keyof T | never = never> = {
54
54
  : AnimatedProp<T[K]>;
55
55
  };
56
56
 
57
- // TODO: switch to AnimatedProps<GroupProps> and remove duplicate properties.
58
- // For instance matrix in color filter becomes colorMatrix
59
-
60
57
  export type SkiaProps<
61
58
  P = object,
62
59
  O extends keyof P | never = never
63
60
  > = AnimatedProps<P, O>;
61
+
62
+ type WithOptional<T extends object, N extends keyof T> = Omit<T, N> & {
63
+ [K in N]?: T[K];
64
+ };
65
+
66
+ export type SkiaDefaultProps<
67
+ T extends object,
68
+ N extends keyof T
69
+ > = WithOptional<SkiaProps<T>, N>;
@@ -58,4 +58,9 @@ export interface SkRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
58
58
  * @param index
59
59
  */
60
60
  getUniformName(index: number): string;
61
+
62
+ /**
63
+ * Returns the SkSL source of the runtime effect shader.
64
+ */
65
+ source(): string;
61
66
  }
@@ -7,9 +7,7 @@ export const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>
7
7
 
8
8
  export type SkShader = SkJSIInstance<"Shader">;
9
9
 
10
- export type UniformValue = number | Vector | readonly number[];
11
-
12
- export type Uniform = UniformValue | readonly UniformValue[];
10
+ export type Uniform = number | Vector | Float32Array | Uniform[];
13
11
 
14
12
  export interface Uniforms {
15
13
  [name: string]: Uniform;
@@ -20,11 +18,16 @@ const isVector = (obj: unknown): obj is Vector =>
20
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
19
  (obj as any).x !== undefined && (obj as any).y !== undefined;
22
20
 
23
- const processValue = (value: UniformValue): number | readonly number[] => {
24
- if (isVector(value)) {
25
- return [value.x, value.y];
21
+ const processValue = (values: number[], value: Uniform) => {
22
+ if (typeof value === "number") {
23
+ values.push(value);
24
+ } else if (Array.isArray(value)) {
25
+ value.forEach((v) => processValue(values, v));
26
+ } else if (isVector(value)) {
27
+ values.push(value.x, value.y);
28
+ } else if (value instanceof Float32Array) {
29
+ values.push(...value);
26
30
  }
27
- return value;
28
31
  };
29
32
 
30
33
  export const processUniforms = (
@@ -32,34 +35,25 @@ export const processUniforms = (
32
35
  uniforms: Uniforms,
33
36
  builder?: SkRuntimeShaderBuilder
34
37
  ) => {
35
- const processed = new Array(source.getUniformCount())
36
- .fill(0)
37
- .flatMap((_, i) => {
38
- const name = source.getUniformName(i);
39
- const value = uniforms[name];
40
- if (value === undefined) {
41
- throw new Error(`No value specified for uniform ${name}`);
42
- }
43
- const result = Array.isArray(value)
44
- ? value.flatMap(processValue)
45
- : processValue(value as UniformValue);
46
- builder?.setUniform(name, typeof result === "number" ? [result] : result);
47
- return result;
48
- });
49
- const names = Object.keys(uniforms);
50
- if (names.length > source.getUniformCount()) {
51
- const usedUniforms = new Array(source.getUniformCount())
52
- .fill(0)
53
- .map((_, i) => source.getUniformName(i));
54
- const unusedUniform = names
55
- .map((name) => {
56
- if (usedUniforms.indexOf(name) === -1) {
57
- return name;
58
- }
59
- return null;
60
- })
61
- .filter((n) => n !== null);
62
- console.warn("Unused uniforms were provided: " + unusedUniform.join(", "));
38
+ const result: number[] = [];
39
+ const uniformsCount = source.getUniformCount();
40
+ for (let i = 0; i < uniformsCount; i++) {
41
+ const name = source.getUniformName(i);
42
+ const value = uniforms[name];
43
+ if (!value === undefined) {
44
+ throw new Error(
45
+ // eslint-disable-next-line max-len
46
+ `The runtime effect has the uniform value "${name}" declared, but it is missing from the uniforms property of the Runtime effect.`
47
+ );
48
+ }
49
+ if (builder === undefined) {
50
+ processValue(result, value);
51
+ } else {
52
+ const uniformValue: number[] = [];
53
+ processValue(uniformValue, value);
54
+ builder.setUniform(name, uniformValue);
55
+ result.push(...uniformValue);
56
+ }
63
57
  }
64
- return processed;
58
+ return result;
65
59
  };
@@ -11,10 +11,14 @@ export class JsiSkRuntimeEffect
11
11
  extends HostObject<RuntimeEffect, "RuntimeEffect">
12
12
  implements SkRuntimeEffect
13
13
  {
14
- constructor(CanvasKit: CanvasKit, ref: RuntimeEffect) {
14
+ constructor(CanvasKit: CanvasKit, ref: RuntimeEffect, private sksl: string) {
15
15
  super(CanvasKit, ref, "RuntimeEffect");
16
16
  }
17
17
 
18
+ source() {
19
+ return this.sksl;
20
+ }
21
+
18
22
  makeShader(uniforms: number[], localMatrix?: SkMatrix) {
19
23
  return new JsiSkShader(
20
24
  this.CanvasKit,
@@ -18,6 +18,6 @@ export class JsiSkRuntimeEffectFactory
18
18
  if (re === null) {
19
19
  return null;
20
20
  }
21
- return new JsiSkRuntimeEffect(this.CanvasKit, re);
21
+ return new JsiSkRuntimeEffect(this.CanvasKit, re, sksl);
22
22
  }
23
23
  }