@shopify/react-native-skia 0.1.225 → 0.1.227

Sign up to get free protection for your applications and to get access to all the features.
Files changed (243) hide show
  1. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +3 -3
  2. package/cpp/api/JsiSkMatrix.h +8 -2
  3. package/cpp/api/JsiSkPictureRecorder.h +10 -3
  4. package/cpp/rnskia/dom/props/MatrixProp.h +8 -0
  5. package/cpp/rnskia/dom/props/TransformProp.h +76 -9
  6. package/lib/commonjs/animation/spring/runSpring.d.ts +3 -0
  7. package/lib/commonjs/animation/spring/runSpring.js +3 -0
  8. package/lib/commonjs/animation/spring/runSpring.js.map +1 -1
  9. package/lib/commonjs/animation/spring/useSpring.d.ts +3 -0
  10. package/lib/commonjs/animation/spring/useSpring.js +3 -0
  11. package/lib/commonjs/animation/spring/useSpring.js.map +1 -1
  12. package/lib/commonjs/animation/timing/runTiming.d.ts +3 -0
  13. package/lib/commonjs/animation/timing/runTiming.js +3 -0
  14. package/lib/commonjs/animation/timing/runTiming.js.map +1 -1
  15. package/lib/commonjs/animation/timing/useLoop.d.ts +3 -0
  16. package/lib/commonjs/animation/timing/useLoop.js +3 -0
  17. package/lib/commonjs/animation/timing/useLoop.js.map +1 -1
  18. package/lib/commonjs/animation/timing/useTiming.d.ts +3 -0
  19. package/lib/commonjs/animation/timing/useTiming.js +3 -0
  20. package/lib/commonjs/animation/timing/useTiming.js.map +1 -1
  21. package/lib/commonjs/dom/nodes/JsiSkDOM.js +2 -0
  22. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  23. package/lib/commonjs/dom/nodes/datatypes/Fitting.d.ts +5 -5
  24. package/lib/commonjs/dom/nodes/datatypes/Fitting.js.map +1 -1
  25. package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +235 -75
  26. package/lib/commonjs/dom/nodes/datatypes/Gradient.js.map +1 -1
  27. package/lib/commonjs/dom/types/Common.d.ts +3 -3
  28. package/lib/commonjs/dom/types/Common.js.map +1 -1
  29. package/lib/commonjs/external/reanimated/interpolators.js +10 -4
  30. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  31. package/lib/commonjs/renderer/Canvas.js +34 -28
  32. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  33. package/lib/commonjs/renderer/components/Drawing.d.ts +5 -0
  34. package/lib/commonjs/renderer/components/Drawing.js +5 -0
  35. package/lib/commonjs/renderer/components/Drawing.js.map +1 -1
  36. package/lib/commonjs/renderer/components/shapes/FitBox.d.ts +5 -5
  37. package/lib/commonjs/skia/core/Matrix.d.ts +2 -2
  38. package/lib/commonjs/skia/core/Matrix.js.map +1 -1
  39. package/lib/commonjs/skia/core/Picture.d.ts +2 -2
  40. package/lib/commonjs/skia/core/Picture.js +12 -2
  41. package/lib/commonjs/skia/core/Picture.js.map +1 -1
  42. package/lib/commonjs/skia/core/Vector.d.ts +3 -3
  43. package/lib/commonjs/skia/core/Vector.js.map +1 -1
  44. package/lib/commonjs/skia/types/Canvas.d.ts +1 -1
  45. package/lib/commonjs/skia/types/Canvas.js.map +1 -1
  46. package/lib/commonjs/skia/types/Matrix.d.ts +4 -9
  47. package/lib/commonjs/skia/types/Matrix.js +5 -56
  48. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  49. package/lib/commonjs/skia/types/Matrix4.d.ts +39 -0
  50. package/lib/commonjs/skia/types/Matrix4.js +213 -0
  51. package/lib/commonjs/skia/types/Matrix4.js.map +1 -0
  52. package/lib/commonjs/skia/types/Path/Path.d.ts +1 -1
  53. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  54. package/lib/commonjs/skia/types/Picture/PictureRecorder.d.ts +1 -1
  55. package/lib/commonjs/skia/types/Picture/PictureRecorder.js.map +1 -1
  56. package/lib/commonjs/skia/types/Rect.d.ts +1 -0
  57. package/lib/commonjs/skia/types/Rect.js +18 -0
  58. package/lib/commonjs/skia/types/Rect.js.map +1 -1
  59. package/lib/commonjs/skia/types/index.d.ts +1 -0
  60. package/lib/commonjs/skia/types/index.js +13 -0
  61. package/lib/commonjs/skia/types/index.js.map +1 -1
  62. package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
  63. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -1
  64. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  65. package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +1 -1
  66. package/lib/commonjs/skia/web/JsiSkMatrix.js +1 -1
  67. package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
  68. package/lib/commonjs/skia/web/JsiSkPath.js +1 -1
  69. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  70. package/lib/commonjs/skia/web/JsiSkPictureRecorder.d.ts +1 -1
  71. package/lib/commonjs/skia/web/JsiSkPictureRecorder.js +1 -1
  72. package/lib/commonjs/skia/web/JsiSkPictureRecorder.js.map +1 -1
  73. package/lib/commonjs/values/api.d.ts +23 -2
  74. package/lib/commonjs/values/api.js +44 -1
  75. package/lib/commonjs/values/api.js.map +1 -1
  76. package/lib/commonjs/values/hooks/useClockValue.d.ts +3 -0
  77. package/lib/commonjs/values/hooks/useClockValue.js +3 -0
  78. package/lib/commonjs/values/hooks/useClockValue.js.map +1 -1
  79. package/lib/commonjs/values/hooks/useComputedValue.d.ts +3 -0
  80. package/lib/commonjs/values/hooks/useComputedValue.js +3 -0
  81. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  82. package/lib/commonjs/values/hooks/useValue.d.ts +3 -0
  83. package/lib/commonjs/values/hooks/useValue.js +3 -0
  84. package/lib/commonjs/values/hooks/useValue.js.map +1 -1
  85. package/lib/commonjs/values/hooks/useValueEffect.d.ts +3 -0
  86. package/lib/commonjs/values/hooks/useValueEffect.js +3 -0
  87. package/lib/commonjs/values/hooks/useValueEffect.js.map +1 -1
  88. package/lib/commonjs/values/types.d.ts +4 -4
  89. package/lib/commonjs/values/types.js.map +1 -1
  90. package/lib/commonjs/views/SkiaView.d.ts +5 -0
  91. package/lib/commonjs/views/SkiaView.js +9 -0
  92. package/lib/commonjs/views/SkiaView.js.map +1 -1
  93. package/lib/module/animation/spring/runSpring.d.ts +3 -0
  94. package/lib/module/animation/spring/runSpring.js +3 -0
  95. package/lib/module/animation/spring/runSpring.js.map +1 -1
  96. package/lib/module/animation/spring/useSpring.d.ts +3 -0
  97. package/lib/module/animation/spring/useSpring.js +3 -0
  98. package/lib/module/animation/spring/useSpring.js.map +1 -1
  99. package/lib/module/animation/timing/runTiming.d.ts +3 -0
  100. package/lib/module/animation/timing/runTiming.js +3 -0
  101. package/lib/module/animation/timing/runTiming.js.map +1 -1
  102. package/lib/module/animation/timing/useLoop.d.ts +3 -0
  103. package/lib/module/animation/timing/useLoop.js +3 -0
  104. package/lib/module/animation/timing/useLoop.js.map +1 -1
  105. package/lib/module/animation/timing/useTiming.d.ts +3 -0
  106. package/lib/module/animation/timing/useTiming.js +3 -0
  107. package/lib/module/animation/timing/useTiming.js.map +1 -1
  108. package/lib/module/dom/nodes/JsiSkDOM.js +2 -0
  109. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  110. package/lib/module/dom/nodes/datatypes/Fitting.d.ts +5 -5
  111. package/lib/module/dom/nodes/datatypes/Fitting.js.map +1 -1
  112. package/lib/module/dom/nodes/datatypes/Gradient.d.ts +235 -75
  113. package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
  114. package/lib/module/dom/types/Common.d.ts +3 -3
  115. package/lib/module/dom/types/Common.js.map +1 -1
  116. package/lib/module/external/reanimated/interpolators.js +11 -5
  117. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  118. package/lib/module/renderer/Canvas.js +35 -29
  119. package/lib/module/renderer/Canvas.js.map +1 -1
  120. package/lib/module/renderer/components/Drawing.d.ts +5 -0
  121. package/lib/module/renderer/components/Drawing.js +6 -0
  122. package/lib/module/renderer/components/Drawing.js.map +1 -1
  123. package/lib/module/renderer/components/shapes/FitBox.d.ts +5 -5
  124. package/lib/module/skia/core/Matrix.d.ts +2 -2
  125. package/lib/module/skia/core/Matrix.js.map +1 -1
  126. package/lib/module/skia/core/Picture.d.ts +2 -2
  127. package/lib/module/skia/core/Picture.js +12 -3
  128. package/lib/module/skia/core/Picture.js.map +1 -1
  129. package/lib/module/skia/core/Vector.d.ts +3 -3
  130. package/lib/module/skia/core/Vector.js.map +1 -1
  131. package/lib/module/skia/types/Canvas.d.ts +1 -1
  132. package/lib/module/skia/types/Canvas.js.map +1 -1
  133. package/lib/module/skia/types/Matrix.d.ts +4 -9
  134. package/lib/module/skia/types/Matrix.js +3 -57
  135. package/lib/module/skia/types/Matrix.js.map +1 -1
  136. package/lib/module/skia/types/Matrix4.d.ts +39 -0
  137. package/lib/module/skia/types/Matrix4.js +200 -0
  138. package/lib/module/skia/types/Matrix4.js.map +1 -0
  139. package/lib/module/skia/types/Path/Path.d.ts +1 -1
  140. package/lib/module/skia/types/Path/Path.js.map +1 -1
  141. package/lib/module/skia/types/Picture/PictureRecorder.d.ts +1 -1
  142. package/lib/module/skia/types/Picture/PictureRecorder.js.map +1 -1
  143. package/lib/module/skia/types/Rect.d.ts +1 -0
  144. package/lib/module/skia/types/Rect.js +9 -0
  145. package/lib/module/skia/types/Rect.js.map +1 -1
  146. package/lib/module/skia/types/index.d.ts +1 -0
  147. package/lib/module/skia/types/index.js +1 -0
  148. package/lib/module/skia/types/index.js.map +1 -1
  149. package/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
  150. package/lib/module/skia/web/JsiSkCanvas.js +1 -1
  151. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  152. package/lib/module/skia/web/JsiSkMatrix.d.ts +1 -1
  153. package/lib/module/skia/web/JsiSkMatrix.js +1 -1
  154. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  155. package/lib/module/skia/web/JsiSkPath.js +1 -1
  156. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  157. package/lib/module/skia/web/JsiSkPictureRecorder.d.ts +1 -1
  158. package/lib/module/skia/web/JsiSkPictureRecorder.js +1 -1
  159. package/lib/module/skia/web/JsiSkPictureRecorder.js.map +1 -1
  160. package/lib/module/values/api.d.ts +23 -2
  161. package/lib/module/values/api.js +44 -1
  162. package/lib/module/values/api.js.map +1 -1
  163. package/lib/module/values/hooks/useClockValue.d.ts +3 -0
  164. package/lib/module/values/hooks/useClockValue.js +3 -0
  165. package/lib/module/values/hooks/useClockValue.js.map +1 -1
  166. package/lib/module/values/hooks/useComputedValue.d.ts +3 -0
  167. package/lib/module/values/hooks/useComputedValue.js +3 -0
  168. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  169. package/lib/module/values/hooks/useValue.d.ts +3 -0
  170. package/lib/module/values/hooks/useValue.js +3 -0
  171. package/lib/module/values/hooks/useValue.js.map +1 -1
  172. package/lib/module/values/hooks/useValueEffect.d.ts +3 -0
  173. package/lib/module/values/hooks/useValueEffect.js +3 -0
  174. package/lib/module/values/hooks/useValueEffect.js.map +1 -1
  175. package/lib/module/values/types.d.ts +4 -4
  176. package/lib/module/values/types.js.map +1 -1
  177. package/lib/module/views/SkiaView.d.ts +5 -0
  178. package/lib/module/views/SkiaView.js +10 -0
  179. package/lib/module/views/SkiaView.js.map +1 -1
  180. package/lib/typescript/src/animation/spring/runSpring.d.ts +3 -0
  181. package/lib/typescript/src/animation/spring/useSpring.d.ts +3 -0
  182. package/lib/typescript/src/animation/timing/runTiming.d.ts +3 -0
  183. package/lib/typescript/src/animation/timing/useLoop.d.ts +3 -0
  184. package/lib/typescript/src/animation/timing/useTiming.d.ts +3 -0
  185. package/lib/typescript/src/dom/nodes/datatypes/Fitting.d.ts +5 -5
  186. package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +235 -75
  187. package/lib/typescript/src/dom/types/Common.d.ts +3 -3
  188. package/lib/typescript/src/renderer/components/Drawing.d.ts +5 -0
  189. package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +5 -5
  190. package/lib/typescript/src/skia/core/Matrix.d.ts +2 -2
  191. package/lib/typescript/src/skia/core/Picture.d.ts +2 -2
  192. package/lib/typescript/src/skia/core/Vector.d.ts +3 -3
  193. package/lib/typescript/src/skia/types/Canvas.d.ts +1 -1
  194. package/lib/typescript/src/skia/types/Matrix.d.ts +4 -9
  195. package/lib/typescript/src/skia/types/Matrix4.d.ts +39 -0
  196. package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -1
  197. package/lib/typescript/src/skia/types/Picture/PictureRecorder.d.ts +1 -1
  198. package/lib/typescript/src/skia/types/Rect.d.ts +1 -0
  199. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  200. package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +1 -1
  201. package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -1
  202. package/lib/typescript/src/skia/web/JsiSkPictureRecorder.d.ts +1 -1
  203. package/lib/typescript/src/values/api.d.ts +23 -2
  204. package/lib/typescript/src/values/hooks/useClockValue.d.ts +3 -0
  205. package/lib/typescript/src/values/hooks/useComputedValue.d.ts +3 -0
  206. package/lib/typescript/src/values/hooks/useValue.d.ts +3 -0
  207. package/lib/typescript/src/values/hooks/useValueEffect.d.ts +3 -0
  208. package/lib/typescript/src/values/types.d.ts +4 -4
  209. package/lib/typescript/src/views/SkiaView.d.ts +5 -0
  210. package/package.json +1 -1
  211. package/src/animation/spring/runSpring.ts +3 -0
  212. package/src/animation/spring/useSpring.ts +3 -0
  213. package/src/animation/timing/runTiming.ts +3 -0
  214. package/src/animation/timing/useLoop.ts +3 -0
  215. package/src/animation/timing/useTiming.ts +3 -0
  216. package/src/dom/nodes/JsiSkDOM.ts +4 -0
  217. package/src/dom/nodes/datatypes/Fitting.ts +10 -2
  218. package/src/dom/nodes/datatypes/Gradient.ts +2 -2
  219. package/src/dom/types/Common.ts +3 -3
  220. package/src/external/reanimated/interpolators.ts +14 -6
  221. package/src/renderer/Canvas.tsx +41 -30
  222. package/src/renderer/components/Drawing.tsx +5 -0
  223. package/src/skia/core/Matrix.ts +2 -2
  224. package/src/skia/core/Picture.ts +11 -3
  225. package/src/skia/core/Vector.ts +5 -2
  226. package/src/skia/types/Canvas.ts +1 -1
  227. package/src/skia/types/Matrix.ts +7 -74
  228. package/src/skia/types/Matrix4.ts +266 -0
  229. package/src/skia/types/Path/Path.ts +1 -1
  230. package/src/skia/types/Picture/PictureRecorder.ts +1 -1
  231. package/src/skia/types/Rect.ts +14 -0
  232. package/src/skia/types/index.ts +1 -0
  233. package/src/skia/web/JsiSkCanvas.ts +2 -2
  234. package/src/skia/web/JsiSkMatrix.ts +4 -2
  235. package/src/skia/web/JsiSkPath.ts +1 -1
  236. package/src/skia/web/JsiSkPictureRecorder.ts +6 -2
  237. package/src/values/api.ts +55 -2
  238. package/src/values/hooks/useClockValue.ts +3 -0
  239. package/src/values/hooks/useComputedValue.ts +3 -0
  240. package/src/values/hooks/useValue.ts +3 -0
  241. package/src/values/hooks/useValueEffect.ts +3 -0
  242. package/src/values/types.ts +6 -6
  243. package/src/views/SkiaView.tsx +11 -0
@@ -485,7 +485,7 @@ export interface SkCanvas {
485
485
  * Replaces current matrix with m premultiplied with the existing matrix.
486
486
  * @param m
487
487
  */
488
- concat(m: SkMatrix): void;
488
+ concat(m: SkMatrix | number[]): void;
489
489
 
490
490
  /**
491
491
  * Draws the given picture using the current clip, current matrix, and the provided paint.
@@ -1,5 +1,7 @@
1
1
  import type { SkJSIInstance } from "./JsiInstance";
2
2
  import type { SkCanvas } from "./Canvas";
3
+ import type { Transforms3d } from "./Matrix4";
4
+ import { processTransform3d } from "./Matrix4";
3
5
  export enum MatrixIndex {
4
6
  ScaleX = 0,
5
7
  SkewX = 1,
@@ -16,7 +18,7 @@ export const isMatrix = (obj: unknown): obj is SkMatrix =>
16
18
  obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
17
19
 
18
20
  export interface SkMatrix extends SkJSIInstance<"Matrix"> {
19
- concat: (matrix: SkMatrix) => SkMatrix;
21
+ concat: (matrix: SkMatrix | number[]) => SkMatrix;
20
22
  translate: (x: number, y: number) => SkMatrix;
21
23
  scale: (x: number, y?: number) => SkMatrix;
22
24
  skew: (x: number, y: number) => SkMatrix;
@@ -29,88 +31,19 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
29
31
  get: () => number[];
30
32
  }
31
33
 
32
- type Transform2dName =
33
- | "translateX"
34
- | "translateY"
35
- | "scale"
36
- | "skewX"
37
- | "skewY"
38
- | "scaleX"
39
- | "scaleY"
40
- | "rotateZ"
41
- | "rotate";
42
-
43
- type Transformations = {
44
- readonly [Name in Transform2dName]: number;
45
- };
46
-
47
- export type Transforms2d = readonly (
48
- | Pick<Transformations, "translateX">
49
- | Pick<Transformations, "translateY">
50
- | Pick<Transformations, "scale">
51
- | Pick<Transformations, "scaleX">
52
- | Pick<Transformations, "scaleY">
53
- | Pick<Transformations, "skewX">
54
- | Pick<Transformations, "skewY">
55
- | Pick<Transformations, "rotate">
56
- )[];
57
-
58
34
  export interface TransformProp {
59
- transform?: Transforms2d;
35
+ transform?: Transforms3d;
60
36
  }
61
37
 
62
38
  export const processTransform = <T extends SkMatrix | SkCanvas>(
63
39
  m: T,
64
- transforms: Transforms2d
40
+ transforms: Transforms3d
65
41
  ) => {
66
- for (const transform of transforms) {
67
- const key = Object.keys(transform)[0] as Transform2dName;
68
- const value = (transform as Pick<Transformations, typeof key>)[key];
69
- if (key === "translateX") {
70
- m.translate(value, 0);
71
- continue;
72
- }
73
- if (key === "translateY") {
74
- m.translate(0, value);
75
- continue;
76
- }
77
- if (key === "scale") {
78
- m.scale(value, value);
79
- continue;
80
- }
81
- if (key === "scaleX") {
82
- m.scale(value, 1);
83
- continue;
84
- }
85
- if (key === "scaleY") {
86
- m.scale(1, value);
87
- continue;
88
- }
89
- if (key === "skewX") {
90
- m.skew(value, 0);
91
- continue;
92
- }
93
- if (key === "skewY") {
94
- m.skew(0, value);
95
- continue;
96
- }
97
- if (key === "rotate" || key === "rotateZ") {
98
- if (isMatrix(m)) {
99
- m.rotate(value);
100
- } else {
101
- m.rotate(toDegrees(value), 0, 0);
102
- }
103
- continue;
104
- }
105
- exhaustiveCheck(key);
106
- }
42
+ const m3 = processTransform3d(transforms);
43
+ m.concat(m3);
107
44
  return m;
108
45
  };
109
46
 
110
- const exhaustiveCheck = (a: never): never => {
111
- throw new Error(`Unknown transformation: ${a}`);
112
- };
113
-
114
47
  export const toDegrees = (rad: number) => {
115
48
  return (rad * 180) / Math.PI;
116
49
  };
@@ -0,0 +1,266 @@
1
+ type Vec2 = readonly [number, number];
2
+ type Vec3 = readonly [number, number, number];
3
+ type Vec4 = readonly [number, number, number, number];
4
+
5
+ export type Matrix4 = readonly [
6
+ number,
7
+ number,
8
+ number,
9
+ number,
10
+ number,
11
+ number,
12
+ number,
13
+ number,
14
+ number,
15
+ number,
16
+ number,
17
+ number,
18
+ number,
19
+ number,
20
+ number,
21
+ number
22
+ ];
23
+
24
+ type Transform3dName =
25
+ | "translateX"
26
+ | "translateY"
27
+ | "translateZ"
28
+ | "translate"
29
+ | "scale"
30
+ | "scaleX"
31
+ | "scaleY"
32
+ | "skewX"
33
+ | "skewY"
34
+ | "rotateZ"
35
+ | "rotate"
36
+ | "perspective"
37
+ | "rotateX"
38
+ | "rotateY"
39
+ | "matrix";
40
+
41
+ type Transformations = {
42
+ [Name in Transform3dName]: Name extends "matrix"
43
+ ? Matrix4
44
+ : Name extends "translate"
45
+ ? Vec3 | Vec2
46
+ : number;
47
+ };
48
+
49
+ type Transform3d =
50
+ | Pick<Transformations, "translateX">
51
+ | Pick<Transformations, "translateY">
52
+ | Pick<Transformations, "translateZ">
53
+ | Pick<Transformations, "translate">
54
+ | Pick<Transformations, "scale">
55
+ | Pick<Transformations, "scaleX">
56
+ | Pick<Transformations, "scaleY">
57
+ | Pick<Transformations, "skewX">
58
+ | Pick<Transformations, "skewY">
59
+ | Pick<Transformations, "perspective">
60
+ | Pick<Transformations, "rotateX">
61
+ | Pick<Transformations, "rotateY">
62
+ | Pick<Transformations, "rotateZ">
63
+ | Pick<Transformations, "rotate">
64
+ | Pick<Transformations, "matrix">;
65
+
66
+ export type Transforms3d = Transform3d[];
67
+
68
+ const exhaustiveCheck = (a: never): never => {
69
+ "worklet";
70
+ throw new Error(`Unexhaustive handling for ${a}`);
71
+ };
72
+
73
+ /**
74
+ * @worklet
75
+ */
76
+ export const Matrix4 = (): Matrix4 => {
77
+ "worklet";
78
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
79
+ };
80
+
81
+ const translate = (x: number, y: number, z: number): Matrix4 => {
82
+ "worklet";
83
+ return [1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1];
84
+ };
85
+
86
+ const scale = (sx: number, sy: number, sz: number): Matrix4 => {
87
+ "worklet";
88
+ return [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];
89
+ };
90
+
91
+ const perspective = (p: number): Matrix4 => {
92
+ "worklet";
93
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1 / p, 1];
94
+ };
95
+
96
+ const normalizeVec = (vec: Vec3): Vec3 => {
97
+ "worklet";
98
+ const [x, y, z] = vec;
99
+ const length = Math.sqrt(x * x + y * y + z * z);
100
+ // Check for zero length to avoid division by zero
101
+ if (length === 0) {
102
+ return [0, 0, 0];
103
+ }
104
+ return [x / length, y / length, z / length];
105
+ };
106
+
107
+ const rotatedUnitSinCos = (
108
+ axisVec: Vec3,
109
+ sinAngle: number,
110
+ cosAngle: number
111
+ ): Matrix4 => {
112
+ "worklet";
113
+ const x = axisVec[0];
114
+ const y = axisVec[1];
115
+ const z = axisVec[2];
116
+ const c = cosAngle;
117
+ const s = sinAngle;
118
+ const t = 1 - c;
119
+ return [
120
+ t * x * x + c,
121
+ t * x * y - s * z,
122
+ t * x * z + s * y,
123
+ 0,
124
+ t * x * y + s * z,
125
+ t * y * y + c,
126
+ t * y * z - s * x,
127
+ 0,
128
+ t * x * z - s * y,
129
+ t * y * z + s * x,
130
+ t * z * z + c,
131
+ 0,
132
+ 0,
133
+ 0,
134
+ 0,
135
+ 1,
136
+ ];
137
+ };
138
+
139
+ const rotate = (axis: Vec3, value: number) => {
140
+ "worklet";
141
+ return rotatedUnitSinCos(
142
+ normalizeVec(axis),
143
+ Math.sin(value),
144
+ Math.cos(value)
145
+ );
146
+ };
147
+
148
+ const matrixVecMul4 = (m: Matrix4, v: Vec4) => {
149
+ "worklet";
150
+ const [vx, vy, vz, vw] = v;
151
+ return [
152
+ vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12],
153
+ vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13],
154
+ vx * m[2] + vy * m[6] + vz * m[10] + vw * m[14],
155
+ vx * m[3] + vy * m[7] + vz * m[11] + vw * m[15],
156
+ ];
157
+ };
158
+
159
+ /**
160
+ * @worklet
161
+ */
162
+ export const mapPoint3d = (m: Matrix4, v: Vec3) => {
163
+ "worklet";
164
+ const r = matrixVecMul4(m, [...v, 1]);
165
+ return [r[0] / r[3], r[1] / r[3], r[2] / r[3]] as const;
166
+ };
167
+
168
+ const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
169
+ "worklet";
170
+ const result = new Array(16).fill(0);
171
+ for (let i = 0; i < 4; i++) {
172
+ for (let j = 0; j < 4; j++) {
173
+ result[i * 4 + j] =
174
+ a[i * 4] * b[j] +
175
+ a[i * 4 + 1] * b[j + 4] +
176
+ a[i * 4 + 2] * b[j + 8] +
177
+ a[i * 4 + 3] * b[j + 12];
178
+ }
179
+ }
180
+ return result as unknown as Matrix4;
181
+ };
182
+
183
+ const skewY = (angle: number): Matrix4 => {
184
+ "worklet";
185
+ return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
186
+ };
187
+
188
+ const skewX = (angle: number): Matrix4 => {
189
+ "worklet";
190
+ return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
191
+ };
192
+
193
+ const toMatrix3 = (m: Matrix4) => {
194
+ "worklet";
195
+ return [m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]];
196
+ };
197
+
198
+ /**
199
+ * @worklet
200
+ */
201
+ export const processTransform3d = (transforms: Transforms3d) => {
202
+ "worklet";
203
+ return toMatrix3(
204
+ transforms.reduce((acc, val) => {
205
+ const key = Object.keys(val)[0] as Transform3dName;
206
+ const transform = val as Pick<Transformations, typeof key>;
207
+ if (key === "translateX") {
208
+ const value = transform[key];
209
+ return multiply4(acc, translate(value, 0, 0));
210
+ }
211
+ if (key === "translate") {
212
+ const [x, y, z = 0] = transform[key];
213
+ return multiply4(acc, translate(x, y, z));
214
+ }
215
+ if (key === "translateY") {
216
+ const value = transform[key];
217
+ return multiply4(acc, translate(0, value, 0));
218
+ }
219
+ if (key === "translateZ") {
220
+ const value = transform[key];
221
+ return multiply4(acc, translate(0, 0, value));
222
+ }
223
+ if (key === "scale") {
224
+ const value = transform[key];
225
+ return multiply4(acc, scale(value, value, 1));
226
+ }
227
+ if (key === "scaleX") {
228
+ const value = transform[key];
229
+ return multiply4(acc, scale(value, 1, 1));
230
+ }
231
+ if (key === "scaleY") {
232
+ const value = transform[key];
233
+ return multiply4(acc, scale(1, value, 1));
234
+ }
235
+ if (key === "skewX") {
236
+ const value = transform[key];
237
+ return multiply4(acc, skewX(value));
238
+ }
239
+ if (key === "skewY") {
240
+ const value = transform[key];
241
+ return multiply4(acc, skewY(value));
242
+ }
243
+ if (key === "rotateX") {
244
+ const value = transform[key];
245
+ return multiply4(acc, rotate([1, 0, 0], value));
246
+ }
247
+ if (key === "rotateY") {
248
+ const value = transform[key];
249
+ return multiply4(acc, rotate([0, 1, 0], value));
250
+ }
251
+ if (key === "perspective") {
252
+ const value = transform[key];
253
+ return multiply4(acc, perspective(value));
254
+ }
255
+ if (key === "rotate" || key === "rotateZ") {
256
+ const value = transform[key];
257
+ return multiply4(acc, rotate([0, 0, 1], value));
258
+ }
259
+ if (key === "matrix") {
260
+ const value = transform[key];
261
+ return multiply4(acc, value);
262
+ }
263
+ return exhaustiveCheck(key);
264
+ }, Matrix4())
265
+ );
266
+ };
@@ -540,7 +540,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
540
540
  /**
541
541
  * Transforms the path by the specified matrix.
542
542
  */
543
- transform(m3: SkMatrix): SkPath;
543
+ transform(m3: SkMatrix | number[]): SkPath;
544
544
 
545
545
  /**
546
546
  * Interpolates between Path with point array of equal size.
@@ -9,7 +9,7 @@ export interface SkPictureRecorder {
9
9
  *
10
10
  * @param bounds - a rect to cull the results.
11
11
  */
12
- beginRecording(bounds: SkRect): SkCanvas;
12
+ beginRecording(bounds?: SkRect): SkCanvas;
13
13
 
14
14
  /**
15
15
  * Returns the captured draw commands as a picture and invalidates the canvas returned earlier.
@@ -4,3 +4,17 @@ export interface SkRect {
4
4
  readonly width: number;
5
5
  readonly height: number;
6
6
  }
7
+
8
+ export const isRect = (def: unknown): def is SkRect => {
9
+ "worklet";
10
+ if (typeof def === "object" && def !== null) {
11
+ const rect = def as SkRect;
12
+ return (
13
+ typeof rect.x === "number" &&
14
+ typeof rect.y === "number" &&
15
+ typeof rect.width === "number" &&
16
+ typeof rect.height === "number"
17
+ );
18
+ }
19
+ return false;
20
+ };
@@ -28,3 +28,4 @@ export * from "./Skia";
28
28
  export * from "./TextBlob";
29
29
  export * from "./Size";
30
30
  export * from "./Paragraph";
31
+ export * from "./Matrix4";
@@ -368,8 +368,8 @@ export class JsiSkCanvas
368
368
  );
369
369
  }
370
370
 
371
- concat(m: SkMatrix) {
372
- this.ref.concat(JsiSkMatrix.fromValue(m));
371
+ concat(m: SkMatrix | number[]) {
372
+ this.ref.concat(Array.isArray(m) ? m : JsiSkMatrix.fromValue(m));
373
373
  }
374
374
 
375
375
  drawPicture(skp: SkPicture) {
@@ -24,8 +24,10 @@ export class JsiSkMatrix
24
24
  // Do nothing - the matrix is represenetd by a Float32Array
25
25
  };
26
26
 
27
- concat(matrix: SkMatrix) {
28
- this.preMultiply(JsiSkMatrix.fromValue(matrix));
27
+ concat(matrix: SkMatrix | number[]) {
28
+ this.preMultiply(
29
+ Array.isArray(matrix) ? matrix : JsiSkMatrix.fromValue(matrix)
30
+ );
29
31
  return this;
30
32
  }
31
33
 
@@ -337,7 +337,7 @@ export class JsiSkPath extends HostObject<Path, "Path"> implements SkPath {
337
337
  }
338
338
 
339
339
  transform(m3: SkMatrix) {
340
- this.ref.transform(JsiSkMatrix.fromValue(m3));
340
+ this.ref.transform(Array.isArray(m3) ? m3 : JsiSkMatrix.fromValue(m3));
341
341
  return this;
342
342
  }
343
343
 
@@ -20,10 +20,14 @@ export class JsiSkPictureRecorder
20
20
  this.ref.delete();
21
21
  };
22
22
 
23
- beginRecording(bounds: SkRect) {
23
+ beginRecording(bounds?: SkRect) {
24
24
  return new JsiSkCanvas(
25
25
  this.CanvasKit,
26
- this.ref.beginRecording(JsiSkRect.fromValue(this.CanvasKit, bounds))
26
+ this.ref.beginRecording(
27
+ bounds
28
+ ? JsiSkRect.fromValue(this.CanvasKit, bounds)
29
+ : Float32Array.of(0, 0, 2_000_000, 2_000_000)
30
+ )
27
31
  );
28
32
  }
29
33
 
package/src/values/api.ts CHANGED
@@ -1,8 +1,61 @@
1
- import type { ISkiaValueApi } from "./types";
1
+ import type {
2
+ AnimationState,
3
+ ISkiaValueApi,
4
+ SkiaAnimation,
5
+ SkiaClockValue,
6
+ SkiaMutableValue,
7
+ SkiaValue,
8
+ } from "./types";
2
9
 
3
10
  declare global {
4
11
  var SkiaValueApi: ISkiaValueApi;
5
12
  }
6
13
 
7
14
  const { SkiaValueApi } = global;
8
- export const ValueApi = SkiaValueApi;
15
+
16
+ const deprecatedWarning = () => {
17
+ console.warn(
18
+ `Skia values are deprecated and will be removed in the next Skia release.
19
+ Please use Reanimated instead: https://shopify.github.io/react-native-skia/docs/animations/animations`
20
+ );
21
+ };
22
+
23
+ export const ValueApi = {
24
+ /**
25
+ * @deprecated Use Reanimated 3
26
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
27
+ */
28
+ createValue<T>(initialValue: T): SkiaMutableValue<T> {
29
+ deprecatedWarning();
30
+ return SkiaValueApi.createValue(initialValue);
31
+ },
32
+ /**
33
+ * @deprecated Use Reanimated 3
34
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
35
+ */
36
+ createComputedValue<R>(
37
+ cb: () => R,
38
+ values: SkiaValue<unknown>[]
39
+ ): SkiaValue<R> {
40
+ deprecatedWarning();
41
+ return SkiaValueApi.createComputedValue(cb, values);
42
+ },
43
+ /**
44
+ * @deprecated Use Reanimated 3
45
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
46
+ */
47
+ createClockValue(): SkiaClockValue {
48
+ deprecatedWarning();
49
+ return SkiaValueApi.createClockValue();
50
+ },
51
+ /**
52
+ * @deprecated Use Reanimated 3
53
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
54
+ */
55
+ createAnimation<S extends AnimationState = AnimationState>(
56
+ cb: (t: number, state: S | undefined) => S
57
+ ): SkiaAnimation {
58
+ deprecatedWarning();
59
+ return SkiaValueApi.createAnimation(cb);
60
+ },
61
+ };
@@ -3,6 +3,9 @@ import { useEffect, useMemo } from "react";
3
3
  import { ValueApi } from "../api";
4
4
 
5
5
  /**
6
+ * @deprecated Use Reanimated 3
7
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
8
+ *
6
9
  * @returns A new value that will be updated on every frame redraw with the
7
10
  * number of milliseconds elapsed since the value was started.
8
11
  * The clock is created in the stopped state.
@@ -4,6 +4,9 @@ import { ValueApi } from "../api";
4
4
  import { isValue } from "../../renderer/processors/Animations";
5
5
 
6
6
  /**
7
+ * @deprecated Use Reanimated 3
8
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
9
+ *
7
10
  * Creates a new computed value - a value that will calculate its value depending
8
11
  * on other values.
9
12
  * @param cb Callback to calculate new value
@@ -4,6 +4,9 @@ import { ValueApi } from "../api";
4
4
  import type { SkiaMutableValue } from "../types";
5
5
 
6
6
  /**
7
+ * @deprecated Use Reanimated 3
8
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
9
+ *
7
10
  * Creates a new value that holds some data.
8
11
  * @param v Value to hold
9
12
  * @returns A Value of type of v
@@ -3,6 +3,9 @@ import { useEffect } from "react";
3
3
  import type { SkiaValue } from "../types";
4
4
 
5
5
  /**
6
+ * @deprecated Use Reanimated 3
7
+ * for animating Skia: https://shopify.github.io/react-native-skia/docs/animations/animations
8
+ *
6
9
  * Sets up an effect that will be run whenever the value changes
7
10
  * @param value Value to subscribe to changes on
8
11
  * @param cb Callback to run when value changes
@@ -48,26 +48,26 @@ export interface ISkiaValueApi {
48
48
  * Creates a new value that holds the initial value and that
49
49
  * can be changed.
50
50
  */
51
- createValue: <T>(initialValue: T) => SkiaMutableValue<T>;
51
+ createValue<T>(initialValue: T): SkiaMutableValue<T>;
52
52
  /**
53
53
  * Creates a computed value. This is a calculated value that returns the result of
54
54
  * a function that is called with the values of the dependencies.
55
55
  */
56
- createComputedValue: <R>(
56
+ createComputedValue<R>(
57
57
  cb: () => R,
58
58
  values: Array<SkiaValue<unknown>>
59
- ) => SkiaValue<R>;
59
+ ): SkiaValue<R>;
60
60
  /**
61
61
  * Creates a clock value where the value is the number of milliseconds elapsed
62
62
  * since the clock was created
63
63
  */
64
- createClockValue: () => SkiaClockValue;
64
+ createClockValue(): SkiaClockValue;
65
65
  /**
66
66
  * Creates an animation that is driven from a clock and updated every frame.
67
67
  * @param cb Callback to calculate next value from time.
68
68
  * @returns An animation object that can control a value.
69
69
  */
70
- createAnimation: <S extends AnimationState = AnimationState>(
70
+ createAnimation<S extends AnimationState = AnimationState>(
71
71
  cb: (t: number, state: S | undefined) => S
72
- ) => SkiaAnimation;
72
+ ): SkiaAnimation;
73
73
  }
@@ -11,9 +11,20 @@ export const SkiaViewNativeId = { current: 1000 };
11
11
 
12
12
  const NativeSkiaView = SkiaDrawViewNativeComponent;
13
13
 
14
+ /**
15
+ * @deprecated If you are looking to use the Skia imperative API, you can use:
16
+ * The picture API: https://shopify.github.io/react-native-skia/docs/shapes/pictures/
17
+ * The offscreen API: https://shopify.github.io/react-native-skia/docs/animations/textures
18
+ */
14
19
  export class SkiaView extends React.Component<SkiaDrawViewProps> {
15
20
  constructor(props: SkiaDrawViewProps) {
16
21
  super(props);
22
+ console.warn(
23
+ `The SkiaView component is deprecated and will be removed in the next release.
24
+ If you are looking to use the Skia imperative API, you can use:
25
+ * The picture API: https://shopify.github.io/react-native-skia/docs/shapes/pictures/
26
+ * The offscreen API: https://shopify.github.io/react-native-skia/docs/animations/textures`
27
+ );
17
28
  this._nativeId = SkiaViewNativeId.current++;
18
29
  const { onDraw, onSize } = props;
19
30
  if (onDraw) {