@shopify/react-native-skia 0.1.156 → 0.1.158

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. package/android/build.gradle +10 -5
  2. package/cpp/api/JsiSkContourMeasure.h +7 -5
  3. package/lib/commonjs/dom/nodes/DrawingNode.js +1 -5
  4. package/lib/commonjs/dom/nodes/DrawingNode.js.map +1 -1
  5. package/lib/commonjs/dom/nodes/RenderNode.js +2 -8
  6. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  7. package/lib/commonjs/dom/nodes/drawings/Text.js +4 -9
  8. package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
  9. package/lib/commonjs/dom/types/Common.js.map +1 -1
  10. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  11. package/lib/commonjs/mock/index.js +0 -1
  12. package/lib/commonjs/mock/index.js.map +1 -1
  13. package/lib/commonjs/renderer/Canvas.js +10 -2
  14. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  15. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  16. package/lib/commonjs/renderer/HostConfig.js +10 -1
  17. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  18. package/lib/commonjs/renderer/components/Mask.js +1 -3
  19. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  20. package/lib/commonjs/renderer/components/Paint.js +5 -18
  21. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  22. package/lib/commonjs/renderer/useCanvas.js +18 -2
  23. package/lib/commonjs/renderer/useCanvas.js.map +1 -1
  24. package/lib/commonjs/skia/core/Picture.js +1 -24
  25. package/lib/commonjs/skia/core/Picture.js.map +1 -1
  26. package/lib/commonjs/skia/core/Rect.js +1 -1
  27. package/lib/commonjs/skia/core/Rect.js.map +1 -1
  28. package/lib/commonjs/skia/types/ContourMeasure.js.map +1 -1
  29. package/lib/commonjs/skia/types/Size.js +2 -0
  30. package/lib/commonjs/skia/types/Size.js.map +1 -0
  31. package/lib/commonjs/skia/types/index.js +13 -0
  32. package/lib/commonjs/skia/types/index.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkColor.js +8 -0
  34. package/lib/commonjs/skia/web/JsiSkColor.js.map +1 -1
  35. package/lib/commonjs/skia/web/JsiSkContourMeasure.js +4 -7
  36. package/lib/commonjs/skia/web/JsiSkContourMeasure.js.map +1 -1
  37. package/lib/commonjs/values/web/RNSkReadonlyValue.js +4 -2
  38. package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -1
  39. package/lib/commonjs/views/SkiaBaseWebView.js +2 -2
  40. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  41. package/lib/module/animation/spring/runSpring.js +1 -1
  42. package/lib/module/animation/spring/runSpring.js.map +1 -1
  43. package/lib/module/animation/spring/useSpring.js +1 -1
  44. package/lib/module/animation/spring/useSpring.js.map +1 -1
  45. package/lib/module/animation/timing/createTiming.js +6 -2
  46. package/lib/module/animation/timing/createTiming.js.map +1 -1
  47. package/lib/module/animation/timing/functions/getResolvedParams.js +10 -6
  48. package/lib/module/animation/timing/functions/getResolvedParams.js.map +1 -1
  49. package/lib/module/animation/timing/useTiming.js +3 -1
  50. package/lib/module/animation/timing/useTiming.js.map +1 -1
  51. package/lib/module/dom/nodes/DrawingNode.js +2 -6
  52. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  53. package/lib/module/dom/nodes/JsiSkDOM.js +2 -2
  54. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  55. package/lib/module/dom/nodes/RenderNode.js +1 -4
  56. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  57. package/lib/module/dom/nodes/datatypes/Gradient.js +2 -2
  58. package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
  59. package/lib/module/dom/nodes/drawings/Text.js +4 -9
  60. package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
  61. package/lib/module/dom/nodes/paint/Shaders.js +4 -2
  62. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  63. package/lib/module/dom/types/Common.js.map +1 -1
  64. package/lib/module/dom/types/Drawings.js.map +1 -1
  65. package/lib/module/mock/index.js +10 -7
  66. package/lib/module/mock/index.js.map +1 -1
  67. package/lib/module/renderer/Canvas.js +10 -2
  68. package/lib/module/renderer/Canvas.js.map +1 -1
  69. package/lib/module/renderer/HostComponents.js.map +1 -1
  70. package/lib/module/renderer/HostConfig.js +9 -1
  71. package/lib/module/renderer/HostConfig.js.map +1 -1
  72. package/lib/module/renderer/components/Mask.js +2 -4
  73. package/lib/module/renderer/components/Mask.js.map +1 -1
  74. package/lib/module/renderer/components/Paint.js +3 -14
  75. package/lib/module/renderer/components/Paint.js.map +1 -1
  76. package/lib/module/renderer/useCanvas.js +13 -0
  77. package/lib/module/renderer/useCanvas.js.map +1 -1
  78. package/lib/module/skia/core/Picture.js +0 -18
  79. package/lib/module/skia/core/Picture.js.map +1 -1
  80. package/lib/module/skia/core/Rect.js +1 -1
  81. package/lib/module/skia/core/Rect.js.map +1 -1
  82. package/lib/module/skia/core/Vector.js +1 -1
  83. package/lib/module/skia/core/Vector.js.map +1 -1
  84. package/lib/module/skia/types/ContourMeasure.js.map +1 -1
  85. package/lib/module/skia/types/Size.js +2 -0
  86. package/lib/module/skia/types/Size.js.map +1 -0
  87. package/lib/module/skia/types/index.js +1 -0
  88. package/lib/module/skia/types/index.js.map +1 -1
  89. package/lib/module/skia/web/Host.js +1 -1
  90. package/lib/module/skia/web/Host.js.map +1 -1
  91. package/lib/module/skia/web/JsiSkColor.js +8 -0
  92. package/lib/module/skia/web/JsiSkColor.js.map +1 -1
  93. package/lib/module/skia/web/JsiSkContourMeasure.js +3 -7
  94. package/lib/module/skia/web/JsiSkContourMeasure.js.map +1 -1
  95. package/lib/module/skia/web/JsiSkMatrix.js +1 -1
  96. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  97. package/lib/module/values/web/RNSkAnimation.js +2 -2
  98. package/lib/module/values/web/RNSkAnimation.js.map +1 -1
  99. package/lib/module/values/web/RNSkReadonlyValue.js +4 -2
  100. package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -1
  101. package/lib/module/views/SkiaBaseWebView.js +5 -3
  102. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  103. package/lib/module/views/useTouchHandler.js +6 -6
  104. package/lib/module/views/useTouchHandler.js.map +1 -1
  105. package/lib/module/web/WithSkiaWeb.js +1 -1
  106. package/lib/module/web/WithSkiaWeb.js.map +1 -1
  107. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +1 -3
  108. package/lib/typescript/src/dom/types/Common.d.ts +2 -3
  109. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -3
  110. package/lib/typescript/src/renderer/Canvas.d.ts +4 -1
  111. package/lib/typescript/src/renderer/HostComponents.d.ts +1 -5
  112. package/lib/typescript/src/renderer/components/Paint.d.ts +3 -4
  113. package/lib/typescript/src/renderer/useCanvas.d.ts +1 -0
  114. package/lib/typescript/src/skia/core/Picture.d.ts +0 -8
  115. package/lib/typescript/src/skia/types/ContourMeasure.d.ts +3 -2
  116. package/lib/typescript/src/skia/types/Size.d.ts +4 -0
  117. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  118. package/lib/typescript/src/skia/web/JsiSkContourMeasure.d.ts +2 -6
  119. package/package.json +12 -6
  120. package/src/dom/nodes/DrawingNode.ts +2 -4
  121. package/src/dom/nodes/RenderNode.ts +1 -13
  122. package/src/dom/nodes/drawings/Text.ts +4 -4
  123. package/src/dom/types/Common.ts +2 -4
  124. package/src/dom/types/Drawings.ts +1 -4
  125. package/src/mock/index.ts +0 -1
  126. package/src/renderer/Canvas.tsx +18 -3
  127. package/src/renderer/HostComponents.ts +1 -4
  128. package/src/renderer/HostConfig.ts +8 -1
  129. package/src/renderer/components/Mask.tsx +2 -2
  130. package/src/renderer/components/Paint.tsx +3 -14
  131. package/src/renderer/useCanvas.ts +14 -0
  132. package/src/skia/core/Picture.ts +0 -24
  133. package/src/skia/core/Rect.ts +1 -1
  134. package/src/skia/types/ContourMeasure.tsx +3 -2
  135. package/src/skia/types/Size.ts +4 -0
  136. package/src/skia/types/index.ts +1 -0
  137. package/src/skia/web/JsiSkColor.ts +11 -0
  138. package/src/skia/web/JsiSkContourMeasure.ts +7 -3
  139. package/src/values/web/RNSkReadonlyValue.ts +4 -2
  140. package/src/views/SkiaBaseWebView.tsx +2 -2
@@ -1,30 +1,6 @@
1
- import type { DependencyList } from "react";
2
- import { useMemo } from "react";
3
-
4
1
  import { Skia } from "../Skia";
5
2
  import type { SkCanvas, SkRect } from "../types";
6
3
 
7
- /**
8
- * Memoizes and returns an SkPicture that can be drawn to another canvas.
9
- * @param rect Picture bounds
10
- * @param cb Callback for drawing to the canvas
11
- * @returns SkPicture
12
- */
13
- export const usePicture = (
14
- rect: SkRect,
15
- cb: (canvas: SkCanvas) => void,
16
- deps: DependencyList = []
17
- ) => {
18
- console.warn("usePicture() is deprecated. Use createPicture() instead.");
19
- return useMemo(() => {
20
- const recorder = Skia.PictureRecorder();
21
- const canvas = recorder.beginRecording(rect);
22
- cb(canvas);
23
- return recorder.finishRecordingAsPicture();
24
- // eslint-disable-next-line react-hooks/exhaustive-deps
25
- }, deps);
26
- };
27
-
28
4
  /**
29
5
  * Memoizes and returns an SkPicture that can be drawn to another canvas.
30
6
  * @param rect Picture bounds
@@ -12,7 +12,7 @@ export const bounds = (rects: SkRect[]) => {
12
12
  const y = Math.min(...rects.map((r) => r.y));
13
13
  const width = Math.max(...rects.map((r) => r.x + r.width));
14
14
  const height = Math.max(...rects.map((r) => r.y + r.height));
15
- return rect(x, y, width, height);
15
+ return rect(x, y, width - x, height - y);
16
16
  };
17
17
 
18
18
  export const topLeft = (r: SkRect | SkRRect) =>
@@ -1,5 +1,6 @@
1
1
  import type { SkJSIInstance } from "./JsiInstance";
2
2
  import type { SkPath } from "./Path/Path";
3
+ import type { SkPoint } from "./Point";
3
4
 
4
5
  export interface PosTan {
5
6
  px: number;
@@ -11,10 +12,10 @@ export interface PosTan {
11
12
  export interface SkContourMeasure extends SkJSIInstance<"ContourMeasure"> {
12
13
  /**
13
14
  * Returns the given position and tangent line for the distance on the given contour.
14
- * The return value is 4 floats in this order: posX, posY, vecX, vecY.
15
+ * The return value an array of 2 vectors: [position, tangent]
15
16
  * @param distance - will be pinned between 0 and length().
16
17
  */
17
- getPosTan(distance: number): PosTan;
18
+ getPosTan(distance: number): [position: SkPoint, tangent: SkPoint];
18
19
 
19
20
  /**
20
21
  * Returns an Path representing the segment of this contour.
@@ -0,0 +1,4 @@
1
+ export interface SkSize {
2
+ width: number;
3
+ height: number;
4
+ }
@@ -25,3 +25,4 @@ export * from "./RSXform";
25
25
  export * from "./JsiInstance";
26
26
  export * from "./Skia";
27
27
  export * from "./TextBlob";
28
+ export * from "./Size";
@@ -241,6 +241,17 @@ const parseCSSColor = (cssStr: string) => {
241
241
  return null;
242
242
  } // Covers NaN.
243
243
  return [(iv & 0xff0000) >> 16, (iv & 0xff00) >> 8, iv & 0xff, 1];
244
+ } else if (str.length === 9) {
245
+ var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
246
+ if (!(iv >= 0 && iv <= 0xffffffff)) {
247
+ return null; // Covers NaN.
248
+ }
249
+ return [
250
+ ((iv & 0xff000000) >> 24) & 0xff,
251
+ (iv & 0xff0000) >> 16,
252
+ (iv & 0xff00) >> 8,
253
+ (iv & 0xff) / 255,
254
+ ];
244
255
  }
245
256
 
246
257
  return null;
@@ -4,6 +4,7 @@ import type { SkContourMeasure } from "../types";
4
4
 
5
5
  import { HostObject } from "./Host";
6
6
  import { JsiSkPath } from "./JsiSkPath";
7
+ import { JsiSkPoint } from "./JsiSkPoint";
7
8
 
8
9
  export class JsiSkContourMeasure
9
10
  extends HostObject<ContourMeasure, "ContourMeasure">
@@ -13,9 +14,12 @@ export class JsiSkContourMeasure
13
14
  super(CanvasKit, ref, "ContourMeasure");
14
15
  }
15
16
 
16
- getPosTan(distance: number) {
17
- const [px, py, tx, ty] = this.ref.getPosTan(distance);
18
- return { px, py, tx, ty };
17
+ getPosTan(distance: number): [position: JsiSkPoint, tangent: JsiSkPoint] {
18
+ const posTan = this.ref.getPosTan(distance);
19
+ return [
20
+ new JsiSkPoint(this.CanvasKit, posTan.slice(0, 2)),
21
+ new JsiSkPoint(this.CanvasKit, posTan.slice(2)),
22
+ ];
19
23
  }
20
24
 
21
25
  getSegment(startD: number, stopD: number, startWithMoveTo: boolean) {
@@ -13,8 +13,10 @@ export class RNSkReadonlyValue<T> implements SkiaValue<T> {
13
13
  }
14
14
 
15
15
  protected update(nextValue: T): void {
16
- this._current = nextValue;
17
- this.notifyListeners();
16
+ if (this._current !== nextValue) {
17
+ this._current = nextValue;
18
+ this.notifyListeners();
19
+ }
18
20
  }
19
21
 
20
22
  public readonly __typename__ = "RNSkValue";
@@ -46,8 +46,8 @@ export abstract class SkiaBaseWebView<
46
46
  // Reset canvas / surface on layout change
47
47
  if (this._canvasRef.current) {
48
48
  const canvas = this._canvasRef.current;
49
- canvas.width = canvas.clientWidth * pd;
50
- canvas.height = canvas.clientHeight * pd;
49
+ canvas.width = width * pd;
50
+ canvas.height = height * pd;
51
51
  const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
52
52
  if (!surface) {
53
53
  throw new Error("Could not create surface");