@shopify/react-native-skia 0.1.131 → 0.1.134

Sign up to get free protection for your applications and to get access to all the features.
Files changed (167) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/build.gradle +17 -2
  3. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +5 -0
  4. package/cpp/api/JsiSkFont.h +6 -2
  5. package/cpp/api/JsiSkImage.h +2 -19
  6. package/cpp/api/JsiSkPaint.h +5 -32
  7. package/cpp/api/JsiSkPath.h +4 -4
  8. package/cpp/rnskia/RNSkValueApi.h +6 -6
  9. package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
  10. package/cpp/utils/RNSkLog.h +5 -0
  11. package/ios/RNSkia-iOS/SkiaManager.mm +1 -1
  12. package/lib/commonjs/mock/index.js +190 -0
  13. package/lib/commonjs/mock/index.js.map +1 -0
  14. package/lib/commonjs/skia/core/Data.js +33 -43
  15. package/lib/commonjs/skia/core/Data.js.map +1 -1
  16. package/lib/commonjs/skia/core/Typeface.js +1 -1
  17. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  18. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  19. package/lib/commonjs/skia/types/Image/Image.js +5 -5
  20. package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
  21. package/lib/commonjs/skia/types/Paint/Paint.js +3 -3
  22. package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
  23. package/lib/commonjs/skia/types/Path/Path.js +0 -1
  24. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  25. package/lib/commonjs/skia/types/Shader/Shader.js +1 -7
  26. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  27. package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -1
  28. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  29. package/lib/commonjs/skia/web/JsiSkFont.js +4 -2
  30. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  31. package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -2
  32. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkImage.js +10 -6
  34. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  35. package/lib/commonjs/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
  36. package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -0
  37. package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
  38. package/lib/commonjs/skia/web/JsiSkPath.js +65 -52
  39. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  40. package/lib/commonjs/skia/web/JsiSkShaderFactory.js +1 -1
  41. package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
  42. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +23 -1
  43. package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
  44. package/lib/commonjs/skia/web/JsiSkia.js +2 -2
  45. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  46. package/lib/commonjs/values/api.js +3 -3
  47. package/lib/commonjs/values/api.js.map +1 -1
  48. package/lib/commonjs/values/api.web.js +3 -3
  49. package/lib/commonjs/values/api.web.js.map +1 -1
  50. package/lib/commonjs/values/hooks/index.js +4 -4
  51. package/lib/commonjs/values/hooks/index.js.map +1 -1
  52. package/lib/commonjs/values/hooks/useComputedValue.js +32 -0
  53. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -0
  54. package/lib/commonjs/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +4 -4
  55. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -0
  56. package/lib/commonjs/values/web/api.js +3 -3
  57. package/lib/commonjs/values/web/api.js.map +1 -1
  58. package/lib/commonjs/views/SkiaView.web.js +4 -4
  59. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  60. package/lib/commonjs/web/index.js +4 -2
  61. package/lib/commonjs/web/index.js.map +1 -1
  62. package/lib/module/mock/index.js +152 -0
  63. package/lib/module/mock/index.js.map +1 -0
  64. package/lib/module/skia/core/Data.js +32 -41
  65. package/lib/module/skia/core/Data.js.map +1 -1
  66. package/lib/module/skia/core/Typeface.js +1 -1
  67. package/lib/module/skia/core/Typeface.js.map +1 -1
  68. package/lib/module/skia/types/Font/Font.js.map +1 -1
  69. package/lib/module/skia/types/Image/Image.js +5 -5
  70. package/lib/module/skia/types/Image/Image.js.map +1 -1
  71. package/lib/module/skia/types/Paint/Paint.js +3 -3
  72. package/lib/module/skia/types/Paint/Paint.js.map +1 -1
  73. package/lib/module/skia/types/Path/Path.js +0 -1
  74. package/lib/module/skia/types/Path/Path.js.map +1 -1
  75. package/lib/module/skia/types/Shader/Shader.js +1 -7
  76. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  77. package/lib/module/skia/web/JsiSkCanvas.js +1 -1
  78. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkFont.js +5 -3
  80. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  81. package/lib/module/skia/web/JsiSkFontMgr.js +0 -2
  82. package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -1
  83. package/lib/module/skia/web/JsiSkImage.js +10 -7
  84. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  85. package/lib/module/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
  86. package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -0
  87. package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
  88. package/lib/module/skia/web/JsiSkPath.js +65 -52
  89. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  90. package/lib/module/skia/web/JsiSkShaderFactory.js +1 -1
  91. package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
  92. package/lib/module/skia/web/JsiSkVerticesFactory.js +24 -1
  93. package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
  94. package/lib/module/skia/web/JsiSkia.js +1 -1
  95. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  96. package/lib/module/values/api.js +1 -1
  97. package/lib/module/values/api.js.map +1 -1
  98. package/lib/module/values/api.web.js +1 -1
  99. package/lib/module/values/api.web.js.map +1 -1
  100. package/lib/module/values/hooks/index.js +1 -1
  101. package/lib/module/values/hooks/index.js.map +1 -1
  102. package/lib/module/values/hooks/useComputedValue.js +18 -0
  103. package/lib/module/values/hooks/useComputedValue.js.map +1 -0
  104. package/lib/module/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +2 -2
  105. package/lib/module/values/web/RNSkComputedValue.js.map +1 -0
  106. package/lib/module/values/web/api.js +3 -3
  107. package/lib/module/values/web/api.js.map +1 -1
  108. package/lib/module/views/SkiaView.web.js +4 -4
  109. package/lib/module/views/SkiaView.web.js.map +1 -1
  110. package/lib/module/web/index.js +3 -1
  111. package/lib/module/web/index.js.map +1 -1
  112. package/lib/typescript/src/mock/index.d.ts +47 -0
  113. package/lib/typescript/src/skia/core/Data.d.ts +3 -3
  114. package/lib/typescript/src/skia/types/Font/Font.d.ts +8 -9
  115. package/lib/typescript/src/skia/types/Image/Image.d.ts +5 -5
  116. package/lib/typescript/src/skia/types/Paint/Paint.d.ts +3 -3
  117. package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -2
  118. package/lib/typescript/src/skia/types/RuntimeEffect/RuntimeEffect.d.ts +1 -0
  119. package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
  120. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -1
  121. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +3 -3
  122. package/lib/typescript/src/skia/web/{JsiImageFilterFactory.d.ts → JsiSkImageFilterFactory.d.ts} +0 -0
  123. package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -1
  124. package/lib/typescript/src/values/api.d.ts +1 -1
  125. package/lib/typescript/src/values/api.web.d.ts +1 -1
  126. package/lib/typescript/src/values/hooks/index.d.ts +1 -1
  127. package/lib/typescript/src/values/hooks/{useDerivedValue.d.ts → useComputedValue.d.ts} +2 -1
  128. package/lib/typescript/src/values/types.d.ts +2 -2
  129. package/lib/typescript/src/values/web/{RNSkDerivedValue.d.ts → RNSkComputedValue.d.ts} +1 -1
  130. package/package.json +2 -1
  131. package/src/mock/index.ts +156 -0
  132. package/src/skia/core/Data.ts +67 -50
  133. package/src/skia/core/Typeface.ts +6 -1
  134. package/src/skia/types/Font/Font.ts +9 -14
  135. package/src/skia/types/Image/Image.ts +4 -4
  136. package/src/skia/types/Paint/Paint.ts +1 -1
  137. package/src/skia/types/Path/Path.ts +0 -1
  138. package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +1 -0
  139. package/src/skia/types/Shader/Shader.ts +3 -5
  140. package/src/skia/types/Skia.ts +1 -1
  141. package/src/skia/web/JsiSkCanvas.ts +2 -2
  142. package/src/skia/web/JsiSkFont.ts +7 -3
  143. package/src/skia/web/JsiSkFontMgr.ts +0 -4
  144. package/src/skia/web/JsiSkImage.ts +37 -16
  145. package/src/skia/web/{JsiImageFilterFactory.ts → JsiSkImageFilterFactory.ts} +0 -0
  146. package/src/skia/web/JsiSkPaint.ts +1 -1
  147. package/src/skia/web/JsiSkPath.ts +64 -47
  148. package/src/skia/web/JsiSkShaderFactory.ts +4 -1
  149. package/src/skia/web/JsiSkVerticesFactory.ts +15 -1
  150. package/src/skia/web/JsiSkia.ts +2 -2
  151. package/src/values/api.ts +1 -1
  152. package/src/values/api.web.ts +1 -1
  153. package/src/values/hooks/index.ts +1 -1
  154. package/src/values/hooks/{useDerivedValue.ts → useComputedValue.ts} +8 -3
  155. package/src/values/types.ts +2 -2
  156. package/src/values/web/{RNSkDerivedValue.ts → RNSkComputedValue.ts} +1 -1
  157. package/src/values/web/api.ts +3 -3
  158. package/src/views/SkiaView.web.tsx +9 -11
  159. package/src/web/index.ts +3 -1
  160. package/lib/commonjs/skia/web/JsiImageFilterFactory.js.map +0 -1
  161. package/lib/commonjs/values/hooks/useDerivedValue.js +0 -25
  162. package/lib/commonjs/values/hooks/useDerivedValue.js.map +0 -1
  163. package/lib/commonjs/values/web/RNSkDerivedValue.js.map +0 -1
  164. package/lib/module/skia/web/JsiImageFilterFactory.js.map +0 -1
  165. package/lib/module/values/hooks/useDerivedValue.js +0 -14
  166. package/lib/module/values/hooks/useDerivedValue.js.map +0 -1
  167. package/lib/module/values/web/RNSkDerivedValue.js.map +0 -1
@@ -16,9 +16,9 @@ export declare enum StrokeCap {
16
16
  Square = 2
17
17
  }
18
18
  export declare enum StrokeJoin {
19
- Bevel = 0,
20
- Miter = 1,
21
- Round = 2
19
+ Miter = 0,
20
+ Round = 1,
21
+ Bevel = 2
22
22
  }
23
23
  export declare const isPaint: (obj: SkJSIInstance<string> | null) => obj is SkPaint;
24
24
  export interface SkPaint extends SkJSIInstance<"Paint"> {
@@ -38,8 +38,7 @@ export declare enum PathVerb {
38
38
  Quad = 2,
39
39
  Conic = 3,
40
40
  Cubic = 4,
41
- Close = 5,
42
- Done = 6
41
+ Close = 5
43
42
  }
44
43
  export declare type PathCommand = number[];
45
44
  export declare const isPath: (obj: SkJSIInstance<string> | null) => obj is SkPath;
@@ -6,6 +6,7 @@ export interface SkSLUniform {
6
6
  rows: number;
7
7
  /** The index into the uniforms array that this uniform begins. */
8
8
  slot: number;
9
+ isInteger: boolean;
9
10
  }
10
11
  export interface SkRuntimeShaderBuilder extends SkJSIInstance<"RuntimeShaderBuilder"> {
11
12
  setUniform(name: string, value: readonly number[]): void;
@@ -39,7 +39,7 @@ export interface Skia {
39
39
  PictureRecorder: () => SkPictureRecorder;
40
40
  Picture: PictureFactory;
41
41
  Path: PathFactory;
42
- Matrix: (matrix?: number[]) => SkMatrix;
42
+ Matrix: (matrix?: readonly number[]) => SkMatrix;
43
43
  ColorFilter: ColorFilterFactory;
44
44
  Font: (typeface?: SkTypeface, size?: number) => SkFont;
45
45
  Typeface: TypefaceFactory;
@@ -13,7 +13,7 @@ export declare class JsiSkFont extends HostObject<Font, "Font"> implements SkFon
13
13
  bounds: JsiSkRect | undefined;
14
14
  };
15
15
  getGlyphIDs(str: string, numCodePoints?: number): number[];
16
- getGlyphWidths(glyphs: number[], paint?: SkPaint | null): Float32Array;
16
+ getGlyphWidths(glyphs: number[], paint?: SkPaint | null): number[];
17
17
  getGlyphIntercepts(glyphs: number[], positions: SkPoint[], top: number, bottom: number): number[];
18
18
  getScaleX(): number;
19
19
  getSize(): number;
@@ -5,8 +5,8 @@ export declare class JsiSkImage extends HostObject<Image, "Image"> implements Sk
5
5
  constructor(CanvasKit: CanvasKit, ref: Image);
6
6
  height(): number;
7
7
  width(): number;
8
- makeShaderOptions(_tx: TileMode, _ty: TileMode, _fm: FilterMode, _mm: MipmapMode, _localMatrix?: SkMatrix): SkShader;
9
- makeShaderCubic(_tx: TileMode, _ty: TileMode, _B: number, _C: number, _localMatrix?: SkMatrix): SkShader;
8
+ makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode, localMatrix?: SkMatrix): SkShader;
9
+ makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number, localMatrix?: SkMatrix): SkShader;
10
10
  encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;
11
- encodeToBase64(_fmt?: ImageFormat, _quality?: number): string;
11
+ encodeToBase64(fmt?: ImageFormat, quality?: number): string;
12
12
  }
@@ -1,5 +1,5 @@
1
1
  import type { CanvasKit, Paint } from "canvaskit-wasm";
2
- import type { BlendMode, SkColor, SkColorFilter, SkImageFilter, SkPaint, SkShader, StrokeCap, StrokeJoin, PaintStyle, SkMaskFilter, SkPathEffect } from "../types";
2
+ import type { StrokeJoin, BlendMode, SkColor, SkColorFilter, SkImageFilter, SkPaint, SkShader, StrokeCap, PaintStyle, SkMaskFilter, SkPathEffect } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  export declare class JsiSkPaint extends HostObject<Paint, "Paint"> implements SkPaint {
5
5
  constructor(CanvasKit: CanvasKit, ref: Paint);
@@ -3,4 +3,4 @@ declare global {
3
3
  var SkiaValueApi: ISkiaValueApi;
4
4
  }
5
5
  export declare const ValueApi: ISkiaValueApi;
6
- export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>, createDerivedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
6
+ export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>, createComputedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
@@ -1,2 +1,2 @@
1
1
  export declare const ValueApi: import("./types").ISkiaValueApi;
2
- export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>, createDerivedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
2
+ export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>, createComputedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
@@ -1,4 +1,4 @@
1
1
  export * from "./useClockValue";
2
- export * from "./useDerivedValue";
2
+ export * from "./useComputedValue";
3
3
  export * from "./useValue";
4
4
  export * from "./useValueEffect";
@@ -1,8 +1,9 @@
1
1
  /**
2
- * Creates a new derived value - a value that will calculate its value depending
2
+ * Creates a new computed value - a value that will calculate its value depending
3
3
  * on other values.
4
4
  * @param cb Callback to calculate new value
5
5
  * @param values Dependant values
6
6
  * @returns A readonly value
7
7
  */
8
+ export declare const useComputedValue: <R>(cb: () => R, values: unknown[]) => import("..").SkiaValue<R>;
8
9
  export declare const useDerivedValue: <R>(cb: () => R, values: unknown[]) => import("..").SkiaValue<R>;
@@ -41,10 +41,10 @@ export interface ISkiaValueApi {
41
41
  */
42
42
  createValue: <T>(initialValue: T) => SkiaMutableValue<T>;
43
43
  /**
44
- * Creates a derived value. This is a calculated value that returns the result of
44
+ * Creates a computed value. This is a calculated value that returns the result of
45
45
  * a function that is called with the values of the dependencies.
46
46
  */
47
- createDerivedValue: <R>(cb: () => R, values: Array<SkiaValue<unknown>>) => SkiaValue<R>;
47
+ createComputedValue: <R>(cb: () => R, values: Array<SkiaValue<unknown>>) => SkiaValue<R>;
48
48
  /**
49
49
  * Creates a clock value where the value is the number of milliseconds elapsed
50
50
  * since the clock was created
@@ -1,6 +1,6 @@
1
1
  import type { DependencyList } from "react";
2
2
  import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
3
- export declare class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {
3
+ export declare class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {
4
4
  constructor(callback: () => T, dependencies: DependencyList);
5
5
  private dependecyUpdated;
6
6
  private _callback;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "React Native Skia",
7
- "version": "0.1.131",
7
+ "version": "0.1.134",
8
8
  "description": "High-performance React Native Graphics using Skia",
9
9
  "main": "lib/module/index.js",
10
10
  "files": [
@@ -70,6 +70,7 @@
70
70
  "@types/react-reconciler": "^0.26.4",
71
71
  "eslint": "7.32.0",
72
72
  "eslint-config-react-native-wcandillon": "^3.7.2",
73
+ "eslint-plugin-reanimated": "^1.2.6",
73
74
  "jest": "^27.4.3",
74
75
  "patch-package": "^6.4.7",
75
76
  "react": "17.0.2",
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Mock implementation for test runners.
3
+ *
4
+ * Example:
5
+ *
6
+ * ```js
7
+ * jest.mock('@shopify/react-native-skia', () => require('@shopify/react-native-skia/lib/commonjs/mock'));
8
+ * ```
9
+ */
10
+
11
+ import type { Skia as SkiaApi, SkRect } from "../skia/types";
12
+
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const MockJSIInstance: any = {};
15
+ const Noop = () => MockJSIInstance;
16
+
17
+ export const Skia: SkiaApi = {
18
+ Point: Noop,
19
+ XYWHRect: Noop,
20
+ RuntimeShaderBuilder: Noop,
21
+ RRectXY: Noop,
22
+ RSXform: Noop,
23
+ Color: Noop,
24
+ ContourMeasureIter: Noop,
25
+ Paint: Noop,
26
+ PictureRecorder: Noop,
27
+ Picture: {
28
+ MakePicture: Noop,
29
+ },
30
+ Path: {
31
+ Make: Noop,
32
+ MakeFromSVGString: Noop,
33
+ MakeFromOp: Noop,
34
+ MakeFromCmds: Noop,
35
+ MakeFromText: Noop,
36
+ },
37
+ Matrix: Noop,
38
+ ColorFilter: {
39
+ MakeMatrix: Noop,
40
+ MakeBlend: Noop,
41
+ MakeCompose: Noop,
42
+ MakeLerp: Noop,
43
+ MakeLinearToSRGBGamma: Noop,
44
+ MakeSRGBToLinearGamma: Noop,
45
+ MakeLumaColorFilter: Noop,
46
+ },
47
+ Font: Noop,
48
+ Typeface: {
49
+ MakeFreeTypeFaceFromData: Noop,
50
+ },
51
+ MaskFilter: {
52
+ MakeBlur: Noop,
53
+ },
54
+ RuntimeEffect: {
55
+ Make: Noop,
56
+ },
57
+ ImageFilter: {
58
+ MakeOffset: Noop,
59
+ MakeDisplacementMap: Noop,
60
+ MakeShader: Noop,
61
+ MakeBlur: Noop,
62
+ MakeColorFilter: Noop,
63
+ MakeCompose: Noop,
64
+ MakeDropShadow: Noop,
65
+ MakeDropShadowOnly: Noop,
66
+ MakeErode: Noop,
67
+ MakeDilate: Noop,
68
+ MakeBlend: Noop,
69
+ MakeRuntimeShader: Noop,
70
+ },
71
+ Shader: {
72
+ MakeLinearGradient: Noop,
73
+ MakeRadialGradient: Noop,
74
+ MakeTwoPointConicalGradient: Noop,
75
+ MakeSweepGradient: Noop,
76
+ MakeTurbulence: Noop,
77
+ MakeFractalNoise: Noop,
78
+ MakeBlend: Noop,
79
+ MakeColor: Noop,
80
+ },
81
+ PathEffect: {
82
+ MakeCorner: Noop,
83
+ MakeDash: Noop,
84
+ MakeDiscrete: Noop,
85
+ MakeCompose: Noop,
86
+ MakeSum: Noop,
87
+ MakeLine2D: Noop,
88
+ MakePath1D: Noop,
89
+ MakePath2D: Noop,
90
+ },
91
+ MakeVertices: Noop,
92
+ Data: {
93
+ fromURI: Noop,
94
+ fromBytes: Noop,
95
+ fromBase64: Noop,
96
+ },
97
+ Image: {
98
+ MakeImageFromEncoded: Noop,
99
+ MakeImage: Noop,
100
+ },
101
+ SVG: {
102
+ MakeFromData: Noop,
103
+ MakeFromString: Noop,
104
+ },
105
+ FontMgr: {
106
+ RefDefault: Noop,
107
+ },
108
+ TextBlob: {
109
+ MakeFromText: Noop,
110
+ MakeFromGlyphs: Noop,
111
+ MakeFromRSXform: Noop,
112
+ MakeFromRSXformGlyphs: Noop,
113
+ },
114
+ Surface: {
115
+ Make: Noop,
116
+ },
117
+ };
118
+
119
+ export const vec = (x: number, y: number) => ({ x, y });
120
+
121
+ export const rect = (x: number, y: number, width: number, height: number) => ({
122
+ x,
123
+ y,
124
+ width,
125
+ height,
126
+ });
127
+
128
+ export const rrect = (r: SkRect, rx: number, ry: number) => ({
129
+ rect: r,
130
+ rx,
131
+ ry,
132
+ });
133
+
134
+ export const useTouchHandler = Noop;
135
+ export const useComputedValue = Noop;
136
+ export const useValue = Noop;
137
+ export const useClockValue = Noop;
138
+ export const useValueEffect = Noop;
139
+ export const useTiming = Noop;
140
+ export const runTiming = Noop;
141
+ export const timing = Noop;
142
+ export const useSpring = Noop;
143
+ export const runSpring = Noop;
144
+ export const spring = Noop;
145
+ export const runDecay = Noop;
146
+ export const decay = Noop;
147
+
148
+ export const useSharedValueEffect = Noop;
149
+
150
+ export const useData = Noop;
151
+ export const useDataCollection = Noop;
152
+ export const useFont = Noop;
153
+ export const useImage = Noop;
154
+ export const usePicture = Noop;
155
+ export const useSVG = Noop;
156
+ export const useTypeface = Noop;
@@ -11,71 +11,88 @@ const resolveAsset = (source: ReturnType<typeof require>) => {
11
11
  : Image.resolveAssetSource(source).uri;
12
12
  };
13
13
 
14
- export const useDataCollection = <T>(
15
- sources: DataSource[],
16
- factory: (data: SkData[]) => T,
17
- deps: DependencyList = []
14
+ const factoryWrapper = <T>(
15
+ data2: SkData,
16
+ factory: (data: SkData) => T,
17
+ onError?: (err: Error) => void
18
18
  ) => {
19
- const [data, setData] = useState<T | null>(null);
20
- useEffect(() => {
21
- const bytesOrURIs = sources.map((source) => {
22
- if (source instanceof Uint8Array) {
23
- return source;
24
- }
25
- return typeof source === "string" ? source : resolveAsset(source);
26
- });
27
- Promise.all(
28
- bytesOrURIs.map((bytesOrURI) =>
29
- bytesOrURI instanceof Uint8Array
30
- ? Skia.Data.fromBytes(bytesOrURI)
31
- : Skia.Data.fromURI(bytesOrURI)
32
- )
33
- ).then((d) => setData(factory(d)));
34
- // eslint-disable-next-line react-hooks/exhaustive-deps
35
- }, deps);
36
- return data;
19
+ const factoryResult = factory(data2);
20
+ if (factoryResult === null) {
21
+ onError && onError(new Error("Could not load data"));
22
+ return null;
23
+ } else {
24
+ return factoryResult;
25
+ }
37
26
  };
38
27
 
39
- export const useRawData = <T>(
40
- source: DataSource | null | undefined,
28
+ const loadDataCollection = <T>(
29
+ sources: DataSource[],
30
+ factory: (data: SkData) => T,
31
+ onError?: (err: Error) => void
32
+ ): Promise<(T | null)[]> =>
33
+ Promise.all(sources.map((source) => loadData(source, factory, onError)));
34
+
35
+ const loadData = <T>(
36
+ source: DataSource,
41
37
  factory: (data: SkData) => T,
42
38
  onError?: (err: Error) => void
39
+ ): Promise<T | null> => {
40
+ if (source instanceof Uint8Array) {
41
+ return new Promise((resolve) =>
42
+ resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))
43
+ );
44
+ } else {
45
+ const uri = typeof source === "string" ? source : resolveAsset(source);
46
+ return Skia.Data.fromURI(uri).then((d) =>
47
+ factoryWrapper(d, factory, onError)
48
+ );
49
+ }
50
+ };
51
+
52
+ type Source = DataSource | null | undefined;
53
+
54
+ const useLoading = <T>(
55
+ source: Source,
56
+ loader: () => Promise<T | null>,
57
+ deps: DependencyList = []
43
58
  ) => {
44
59
  const [data, setData] = useState<T | null>(null);
45
- const prevSourceRef = useRef<DataSource | null | undefined>();
60
+ const prevSourceRef = useRef<Source>();
46
61
  useEffect(() => {
47
- // Track to avoid re-fetching the same data
48
62
  if (prevSourceRef.current !== source) {
49
63
  prevSourceRef.current = source;
50
- if (source !== null && source !== undefined) {
51
- const factoryWrapper = (data2: SkData) => {
52
- const factoryResult = factory(data2);
53
- if (factoryResult === null) {
54
- onError && onError(new Error("Could not load data"));
55
- setData(null);
56
- } else {
57
- setData(factoryResult);
58
- }
59
- };
60
- if (source instanceof Uint8Array) {
61
- factoryWrapper(Skia.Data.fromBytes(source));
62
- } else {
63
- const uri =
64
- typeof source === "string" ? source : resolveAsset(source);
65
- Skia.Data.fromURI(uri).then((d) => factoryWrapper(d));
66
- }
67
- } else {
68
- // new source is null or undefined -> remove cached data
69
- setData(null);
70
- }
64
+ loader().then(setData);
65
+ } else {
66
+ setData(null);
71
67
  }
72
- }, [factory, onError, source]);
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, deps);
73
70
  return data;
74
71
  };
75
72
 
73
+ export const useDataCollection = <T>(
74
+ sources: DataSource[],
75
+ factory: (data: SkData) => T,
76
+ onError?: (err: Error) => void,
77
+ deps?: DependencyList
78
+ ) =>
79
+ useLoading(
80
+ sources,
81
+ () => loadDataCollection(sources, factory, onError),
82
+ deps
83
+ );
84
+
85
+ export const useRawData = <T>(
86
+ source: DataSource | null | undefined,
87
+ factory: (data: SkData) => T,
88
+ onError?: (err: Error) => void,
89
+ deps?: DependencyList
90
+ ) => useLoading(source, () => loadData(source, factory, onError), deps);
91
+
76
92
  const identity = (data: SkData) => data;
77
93
 
78
94
  export const useData = (
79
95
  source: DataSource | null | undefined,
80
- onError?: (err: Error) => void
81
- ) => useRawData(source, identity, onError);
96
+ onError?: (err: Error) => void,
97
+ deps?: DependencyList
98
+ ) => useRawData(source, identity, onError, deps);
@@ -8,4 +8,9 @@ import { useRawData } from "./Data";
8
8
  export const useTypeface = (
9
9
  source: DataSource | null | undefined,
10
10
  onError?: (err: Error) => void
11
- ) => useRawData(source, Skia.Typeface.MakeFreeTypeFaceFromData, onError);
11
+ ) =>
12
+ useRawData(
13
+ source,
14
+ Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface),
15
+ onError
16
+ );
@@ -12,6 +12,15 @@ export interface FontMetrics {
12
12
  }
13
13
 
14
14
  export interface SkFont extends SkJSIInstance<"Font"> {
15
+ /**
16
+ * Retrieves the advanceX measurements for each glyph.
17
+ * If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
18
+ * One width per glyph is returned in the returned array.
19
+ * @param glyphs
20
+ * @param paint
21
+ */
22
+ getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
23
+
15
24
  /** Returns the advance width of text.
16
25
  The advance is the normal distance to move before drawing additional text.
17
26
  Returns the bounding box of text if bounds is not nullptr. The paint
@@ -39,20 +48,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
39
48
  */
40
49
  getGlyphIDs(str: string, numCodePoints?: number): number[];
41
50
 
42
- /**
43
- * Retrieves the advanceX measurements for each glyph.
44
- * If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
45
- * One width per glyph is returned in the returned array.
46
- * @param glyphs
47
- * @param paint
48
- * @param output - if provided, the results will be copied into this array.
49
- */
50
- getGlyphWidths(
51
- glyphs: number[],
52
- paint?: SkPaint | null,
53
- output?: Float32Array
54
- ): Float32Array;
55
-
56
51
  /**
57
52
  * Computes any intersections of a thick "line" and a run of positionsed glyphs.
58
53
  * The thick line is represented as a top and bottom coordinate (positive for
@@ -4,8 +4,8 @@ import type { TileMode } from "../ImageFilter";
4
4
  import type { SkShader } from "../Shader";
5
5
 
6
6
  export enum FilterMode {
7
- Linear,
8
7
  Nearest,
8
+ Linear,
9
9
  }
10
10
 
11
11
  export enum MipmapMode {
@@ -15,9 +15,9 @@ export enum MipmapMode {
15
15
  }
16
16
 
17
17
  export enum ImageFormat {
18
- PNG,
19
- JPEG,
20
- WEBP,
18
+ JPEG = 3,
19
+ PNG = 4,
20
+ WEBP = 6,
21
21
  }
22
22
 
23
23
  export interface SkImage extends SkJSIInstance<"Image"> {
@@ -20,9 +20,9 @@ export enum StrokeCap {
20
20
  }
21
21
 
22
22
  export enum StrokeJoin {
23
- Bevel,
24
23
  Miter,
25
24
  Round,
25
+ Bevel,
26
26
  }
27
27
 
28
28
  export const isPaint = (obj: SkJSIInstance<string> | null): obj is SkPaint =>
@@ -44,7 +44,6 @@ export enum PathVerb {
44
44
  Conic,
45
45
  Cubic,
46
46
  Close,
47
- Done,
48
47
  }
49
48
 
50
49
  export type PathCommand = number[];
@@ -7,6 +7,7 @@ export interface SkSLUniform {
7
7
  rows: number;
8
8
  /** The index into the uniforms array that this uniform begins. */
9
9
  slot: number;
10
+ isInteger: boolean;
10
11
  }
11
12
 
12
13
  export interface SkRuntimeShaderBuilder
@@ -40,11 +40,9 @@ export const processUniforms = (
40
40
  if (value === undefined) {
41
41
  throw new Error(`No value specified for uniform ${name}`);
42
42
  }
43
- let result: number | readonly number[];
44
- if (Array.isArray(value)) {
45
- result = value.flatMap(processValue);
46
- }
47
- result = processValue(value as UniformValue);
43
+ const result = Array.isArray(value)
44
+ ? value.flatMap(processValue)
45
+ : processValue(value as UniformValue);
48
46
  builder?.setUniform(name, typeof result === "number" ? [result] : result);
49
47
  return result;
50
48
  });
@@ -48,7 +48,7 @@ export interface Skia {
48
48
  PictureRecorder: () => SkPictureRecorder;
49
49
  Picture: PictureFactory;
50
50
  Path: PathFactory;
51
- Matrix: (matrix?: number[]) => SkMatrix;
51
+ Matrix: (matrix?: readonly number[]) => SkMatrix;
52
52
  ColorFilter: ColorFilterFactory;
53
53
  Font: (typeface?: SkTypeface, size?: number) => SkFont;
54
54
  Typeface: TypefaceFactory;
@@ -1,4 +1,4 @@
1
- import type { Canvas, Image, Paint, CanvasKit } from "canvaskit-wasm";
1
+ import type { Canvas, Image, CanvasKit, Paint } from "canvaskit-wasm";
2
2
 
3
3
  import type {
4
4
  BlendMode,
@@ -250,7 +250,7 @@ export class JsiSkCanvas
250
250
  ) {
251
251
  this.ref.drawGlyphs(
252
252
  glyphs,
253
- toValue(positions),
253
+ positions.map((p) => [p.x, p.y]).flat(),
254
254
  x,
255
255
  y,
256
256
  toValue(font),
@@ -10,7 +10,7 @@ import type {
10
10
  SkTypeface,
11
11
  } from "../types";
12
12
 
13
- import { HostObject, NotImplementedOnRNWeb, toValue, ckEnum } from "./Host";
13
+ import { HostObject, toValue, ckEnum } from "./Host";
14
14
  import { JsiSkRect } from "./JsiSkRect";
15
15
  import { JsiSkTypeface } from "./JsiSkTypeface";
16
16
 
@@ -20,7 +20,11 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
20
20
  }
21
21
 
22
22
  measureText(_text: string, _paint?: SkPaint): SkRect {
23
- throw new NotImplementedOnRNWeb();
23
+ console.warn(
24
+ `measureText() is deprecated an returns an empty rectangle on React Native Web.
25
+ Clients should use "Font.getGlyphWidths" instead (the latter does no shaping)`
26
+ );
27
+ return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
24
28
  }
25
29
 
26
30
  getMetrics() {
@@ -42,7 +46,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
42
46
 
43
47
  // TODO: Fix return value in the C++ implementation, it return float32
44
48
  getGlyphWidths(glyphs: number[], paint?: SkPaint | null) {
45
- return this.ref.getGlyphWidths(glyphs, paint ? toValue(paint) : null);
49
+ return [...this.ref.getGlyphWidths(glyphs, paint ? toValue(paint) : null)];
46
50
  }
47
51
 
48
52
  getGlyphIntercepts(
@@ -9,10 +9,6 @@ export class JsiSkFontMgr
9
9
  implements SkFontMgr
10
10
  {
11
11
  constructor(CanvasKit: CanvasKit) {
12
- console.warn(
13
- // eslint-disable-next-line max-len
14
- "Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts"
15
- );
16
12
  super(CanvasKit, null, "FontMgr");
17
13
  }
18
14