@shopify/react-native-skia 1.10.2 → 1.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. package/cpp/api/JsiSkApi.h +3 -0
  2. package/cpp/api/recorder/ColorFilters.h +133 -0
  3. package/cpp/api/recorder/Command.h +58 -0
  4. package/cpp/api/recorder/Convertor.h +1213 -0
  5. package/cpp/api/recorder/DataTypes.h +232 -0
  6. package/cpp/api/recorder/DrawingCtx.h +187 -0
  7. package/cpp/api/recorder/Drawings.h +950 -0
  8. package/cpp/api/recorder/ImageFilters.h +292 -0
  9. package/cpp/api/recorder/ImageFit.h +108 -0
  10. package/cpp/api/recorder/JsiRecorder.h +314 -0
  11. package/cpp/api/recorder/Paint.h +191 -0
  12. package/cpp/api/recorder/PathEffects.h +194 -0
  13. package/cpp/api/recorder/RNRecorder.h +637 -0
  14. package/cpp/api/recorder/Shaders.h +406 -0
  15. package/cpp/rnskia/dom/nodes/JsiAtlasNode.h +3 -2
  16. package/cpp/rnskia/dom/nodes/JsiImageNode.h +3 -2
  17. package/jestSetup.js +8 -0
  18. package/jestSetup.mjs +8 -0
  19. package/lib/commonjs/renderer/components/image/Image.d.ts +1 -1
  20. package/lib/commonjs/renderer/components/image/Image.js +8 -2
  21. package/lib/commonjs/renderer/components/image/Image.js.map +1 -1
  22. package/lib/commonjs/skia/types/Recorder.d.ts +52 -0
  23. package/lib/commonjs/skia/types/Recorder.js +6 -0
  24. package/lib/commonjs/skia/types/Recorder.js.map +1 -0
  25. package/lib/commonjs/skia/types/Skia.d.ts +2 -0
  26. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  27. package/lib/commonjs/skia/types/index.d.ts +1 -0
  28. package/lib/commonjs/skia/types/index.js +11 -0
  29. package/lib/commonjs/skia/types/index.js.map +1 -1
  30. package/lib/commonjs/skia/web/JsiSkia.js +3 -0
  31. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  32. package/lib/commonjs/sksg/Container.d.ts +6 -1
  33. package/lib/commonjs/sksg/Container.js +59 -2
  34. package/lib/commonjs/sksg/Container.js.map +1 -1
  35. package/lib/commonjs/sksg/Recorder/DrawingContext.js +1 -0
  36. package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
  37. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  38. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +189 -0
  39. package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
  40. package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -2
  41. package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
  42. package/lib/commonjs/sksg/Recorder/Visitor.d.ts +2 -2
  43. package/lib/commonjs/sksg/Recorder/Visitor.js +2 -2
  44. package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
  45. package/lib/module/renderer/components/image/Image.d.ts +1 -1
  46. package/lib/module/renderer/components/image/Image.js +8 -2
  47. package/lib/module/renderer/components/image/Image.js.map +1 -1
  48. package/lib/module/skia/types/Recorder.d.ts +52 -0
  49. package/lib/module/skia/types/Recorder.js +2 -0
  50. package/lib/module/skia/types/Recorder.js.map +1 -0
  51. package/lib/module/skia/types/Skia.d.ts +2 -0
  52. package/lib/module/skia/types/Skia.js.map +1 -1
  53. package/lib/module/skia/types/index.d.ts +1 -0
  54. package/lib/module/skia/types/index.js +1 -0
  55. package/lib/module/skia/types/index.js.map +1 -1
  56. package/lib/module/skia/web/JsiSkia.js +3 -0
  57. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  58. package/lib/module/sksg/Container.d.ts +6 -1
  59. package/lib/module/sksg/Container.js +59 -2
  60. package/lib/module/sksg/Container.js.map +1 -1
  61. package/lib/module/sksg/Recorder/DrawingContext.js +1 -0
  62. package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
  63. package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  64. package/lib/module/sksg/Recorder/ReanimatedRecorder.js +182 -0
  65. package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -0
  66. package/lib/module/sksg/Recorder/Recorder.d.ts +2 -2
  67. package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
  68. package/lib/module/sksg/Recorder/Visitor.d.ts +2 -2
  69. package/lib/module/sksg/Recorder/Visitor.js +2 -2
  70. package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
  71. package/lib/typescript/lib/commonjs/renderer/components/image/Image.d.ts +4 -1
  72. package/lib/typescript/lib/commonjs/skia/types/Recorder.d.ts +1 -0
  73. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -0
  74. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +5 -1
  75. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +6 -0
  76. package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +47 -0
  77. package/lib/typescript/lib/module/mock/index.d.ts +4 -1
  78. package/lib/typescript/lib/module/renderer/components/image/Image.d.ts +4 -1
  79. package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
  80. package/lib/typescript/lib/module/skia/types/Recorder.d.ts +1 -0
  81. package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
  82. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -0
  83. package/lib/typescript/lib/module/sksg/Container.d.ts +5 -1
  84. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +6 -0
  85. package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +46 -0
  86. package/lib/typescript/src/renderer/components/image/Image.d.ts +1 -1
  87. package/lib/typescript/src/skia/types/Recorder.d.ts +52 -0
  88. package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
  89. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  90. package/lib/typescript/src/sksg/Container.d.ts +6 -1
  91. package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +53 -0
  92. package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -2
  93. package/lib/typescript/src/sksg/Recorder/Visitor.d.ts +2 -2
  94. package/package.json +3 -2
  95. package/src/renderer/components/image/Image.tsx +2 -2
  96. package/src/skia/types/Recorder.ts +91 -0
  97. package/src/skia/types/Skia.ts +2 -0
  98. package/src/skia/types/index.ts +1 -0
  99. package/src/skia/web/JsiSkia.ts +3 -0
  100. package/src/sksg/Container.ts +63 -4
  101. package/src/sksg/Recorder/DrawingContext.ts +1 -0
  102. package/src/sksg/Recorder/ReanimatedRecorder.ts +271 -0
  103. package/src/sksg/Recorder/Recorder.ts +2 -2
  104. package/src/sksg/Recorder/Visitor.ts +17 -12
@@ -3,6 +3,12 @@ export class SkiaSGRoot {
3
3
  constructor(Skia: any, nativeId?: number);
4
4
  Skia: any;
5
5
  container: {
6
+ redraw(): void;
7
+ mapperId: any;
8
+ Skia: any;
9
+ nativeId: any;
10
+ drawOnCanvas(canvas: any): void;
11
+ } | {
6
12
  redraw(): void;
7
13
  recording: {
8
14
  commands: any;
@@ -0,0 +1,47 @@
1
+ export const __esModule: boolean;
2
+ export class ReanimatedRecorder {
3
+ constructor(Skia: any);
4
+ recorder: any;
5
+ processAnimationValues(props: any): void;
6
+ getRecorder(): any;
7
+ getSharedValues(): any[];
8
+ saveGroup(): void;
9
+ restoreGroup(): void;
10
+ savePaint(props: any): void;
11
+ restorePaint(): void;
12
+ restorePaintDeclaration(): void;
13
+ materializePaint(): void;
14
+ pushPathEffect(pathEffectType: any, props: any): void;
15
+ pushImageFilter(imageFilterType: any, props: any): void;
16
+ pushColorFilter(colorFilterType: any, props: any): void;
17
+ pushShader(shaderType: any, props: any): void;
18
+ pushBlurMaskFilter(props: any): void;
19
+ composePathEffect(): void;
20
+ composeColorFilter(): void;
21
+ composeImageFilter(): void;
22
+ saveCTM(props: any): void;
23
+ restoreCTM(): void;
24
+ drawPaint(): void;
25
+ saveLayer(): void;
26
+ saveBackdropFilter(): void;
27
+ drawBox(boxProps: any, shadows: any): void;
28
+ drawImage(props: any): void;
29
+ drawCircle(props: any): void;
30
+ drawPoints(props: any): void;
31
+ drawPath(props: any): void;
32
+ drawRect(props: any): void;
33
+ drawRRect(props: any): void;
34
+ drawOval(props: any): void;
35
+ drawLine(props: any): void;
36
+ drawPatch(props: any): void;
37
+ drawVertices(props: any): void;
38
+ drawDiffRect(props: any): void;
39
+ drawText(props: any): void;
40
+ drawTextPath(props: any): void;
41
+ drawTextBlob(props: any): void;
42
+ drawGlyphs(props: any): void;
43
+ drawPicture(props: any): void;
44
+ drawImageSVG(props: any): void;
45
+ drawParagraph(props: any): void;
46
+ drawAtlas(props: any): void;
47
+ }
@@ -348,7 +348,10 @@ export function Mock(CanvasKit: any): {
348
348
  filter: any;
349
349
  children: any;
350
350
  }>;
351
- Image: (props: any) => import("react").DOMElement<any, Element>;
351
+ Image: ({ fit, ...props }: {
352
+ [x: string]: any;
353
+ fit?: string | undefined;
354
+ }) => import("react").DOMElement<any, Element>;
352
355
  ImageShader: ({ tx, ty, fit, transform, ...props }: {
353
356
  [x: string]: any;
354
357
  tx?: string | undefined;
@@ -1,2 +1,5 @@
1
- export function Image(props: any): React.DOMElement<any, Element>;
1
+ export function Image({ fit, ...props }: {
2
+ [x: string]: any;
3
+ fit?: string | undefined;
4
+ }): React.DOMElement<any, Element>;
2
5
  import React from "react";
@@ -33,4 +33,5 @@ export const Skia: {
33
33
  NativeBuffer: import("./web/JsiSkNativeBufferFactory").JsiSkNativeBufferFactory;
34
34
  Video: (url?: any) => Promise<any>;
35
35
  Context: (_surface: any, _width: any, _height: any) => never;
36
+ Recorder: () => never;
36
37
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -27,4 +27,5 @@ export * from "./TextBlob";
27
27
  export * from "./Paragraph";
28
28
  export * from "./Matrix4";
29
29
  export * from "./NativeBuffer";
30
+ export * from "./Recorder";
30
31
  export * from "./Video";
@@ -33,6 +33,7 @@ export function JsiSkApi(CanvasKit: any): {
33
33
  NativeBuffer: JsiSkNativeBufferFactory;
34
34
  Video: (url?: any) => Promise<any>;
35
35
  Context: (_surface: any, _width: any, _height: any) => never;
36
+ Recorder: () => never;
36
37
  };
37
38
  import { JsiSkPoint } from "./JsiSkPoint";
38
39
  import { JsiSkRRect } from "./JsiSkRRect";
@@ -4,7 +4,7 @@ export class Container {
4
4
  nativeId: any;
5
5
  drawOnCanvas(canvas: any): void;
6
6
  }
7
- export function createContainer(Skia: any, nativeId: any): StaticContainer | ReanimatedContainer;
7
+ export function createContainer(Skia: any, nativeId: any): StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
8
8
  declare class StaticContainer extends Container {
9
9
  redraw(): void;
10
10
  recording: {
@@ -21,4 +21,8 @@ declare class ReanimatedContainer extends Container {
21
21
  } | undefined;
22
22
  mapperId: any;
23
23
  }
24
+ declare class NativeReanimatedContainer extends Container {
25
+ redraw(): void;
26
+ mapperId: any;
27
+ }
24
28
  export {};
@@ -21,6 +21,12 @@ export class SkiaSGRoot {
21
21
  Skia: any;
22
22
  nativeId: any;
23
23
  drawOnCanvas(canvas: any): void;
24
+ } | {
25
+ redraw(): void;
26
+ mapperId: any;
27
+ Skia: any;
28
+ nativeId: any;
29
+ drawOnCanvas(canvas: any): void;
24
30
  };
25
31
  root: any;
26
32
  get sg(): {
@@ -0,0 +1,46 @@
1
+ export class ReanimatedRecorder {
2
+ constructor(Skia: any);
3
+ recorder: any;
4
+ processAnimationValues(props: any): void;
5
+ getRecorder(): any;
6
+ getSharedValues(): any[];
7
+ saveGroup(): void;
8
+ restoreGroup(): void;
9
+ savePaint(props: any): void;
10
+ restorePaint(): void;
11
+ restorePaintDeclaration(): void;
12
+ materializePaint(): void;
13
+ pushPathEffect(pathEffectType: any, props: any): void;
14
+ pushImageFilter(imageFilterType: any, props: any): void;
15
+ pushColorFilter(colorFilterType: any, props: any): void;
16
+ pushShader(shaderType: any, props: any): void;
17
+ pushBlurMaskFilter(props: any): void;
18
+ composePathEffect(): void;
19
+ composeColorFilter(): void;
20
+ composeImageFilter(): void;
21
+ saveCTM(props: any): void;
22
+ restoreCTM(): void;
23
+ drawPaint(): void;
24
+ saveLayer(): void;
25
+ saveBackdropFilter(): void;
26
+ drawBox(boxProps: any, shadows: any): void;
27
+ drawImage(props: any): void;
28
+ drawCircle(props: any): void;
29
+ drawPoints(props: any): void;
30
+ drawPath(props: any): void;
31
+ drawRect(props: any): void;
32
+ drawRRect(props: any): void;
33
+ drawOval(props: any): void;
34
+ drawLine(props: any): void;
35
+ drawPatch(props: any): void;
36
+ drawVertices(props: any): void;
37
+ drawDiffRect(props: any): void;
38
+ drawText(props: any): void;
39
+ drawTextPath(props: any): void;
40
+ drawTextBlob(props: any): void;
41
+ drawGlyphs(props: any): void;
42
+ drawPicture(props: any): void;
43
+ drawImageSVG(props: any): void;
44
+ drawParagraph(props: any): void;
45
+ drawAtlas(props: any): void;
46
+ }
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import type { SkiaProps } from "../../processors";
3
3
  import type { ImageProps } from "../../../dom/types";
4
- export declare const Image: (props: SkiaProps<ImageProps>) => React.JSX.Element;
4
+ export declare const Image: ({ fit, ...props }: SkiaProps<ImageProps>) => React.JSX.Element;
@@ -0,0 +1,52 @@
1
+ import type { SharedValue } from "react-native-reanimated";
2
+ import type { TextProps, AtlasProps, BlurMaskFilterProps, BoxProps, BoxShadowProps, CircleProps, CTMProps, DiffRectProps, GlyphsProps, ImageProps, ImageSVGProps, LineProps, NodeType, OvalProps, PaintProps, ParagraphProps, PatchProps, PathProps, PictureProps, PointsProps, RectProps, RoundedRectProps, TextBlobProps, TextPathProps, VerticesProps } from "../../dom/types";
3
+ import type { AnimatedProps } from "../../renderer/processors/Animations/Animations";
4
+ import type { SkCanvas } from "./Canvas";
5
+ export interface BaseRecorder {
6
+ saveGroup(): void;
7
+ restoreGroup(): void;
8
+ savePaint(props: AnimatedProps<PaintProps>): void;
9
+ restorePaint(): void;
10
+ restorePaintDeclaration(): void;
11
+ materializePaint(): void;
12
+ pushPathEffect(pathEffectType: NodeType, props: AnimatedProps<unknown>): void;
13
+ pushImageFilter(imageFilterType: NodeType, props: AnimatedProps<unknown>): void;
14
+ pushColorFilter(colorFilterType: NodeType, props: AnimatedProps<unknown>): void;
15
+ pushShader(shaderType: NodeType, props: AnimatedProps<unknown>): void;
16
+ pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void;
17
+ composePathEffect(): void;
18
+ composeColorFilter(): void;
19
+ composeImageFilter(): void;
20
+ saveCTM(props: AnimatedProps<CTMProps>): void;
21
+ restoreCTM(): void;
22
+ drawPaint(): void;
23
+ saveLayer(): void;
24
+ saveBackdropFilter(): void;
25
+ drawBox(boxProps: AnimatedProps<BoxProps>, shadows: {
26
+ props: BoxShadowProps;
27
+ animatedProps?: Record<string, SharedValue<unknown>>;
28
+ }[]): void;
29
+ drawImage(props: AnimatedProps<ImageProps>): void;
30
+ drawCircle(props: AnimatedProps<CircleProps>): void;
31
+ drawPoints(props: AnimatedProps<PointsProps>): void;
32
+ drawPath(props: AnimatedProps<PathProps>): void;
33
+ drawRect(props: AnimatedProps<RectProps>): void;
34
+ drawRRect(props: AnimatedProps<RoundedRectProps>): void;
35
+ drawOval(props: AnimatedProps<OvalProps>): void;
36
+ drawLine(props: AnimatedProps<LineProps>): void;
37
+ drawPatch(props: AnimatedProps<PatchProps>): void;
38
+ drawVertices(props: AnimatedProps<VerticesProps>): void;
39
+ drawDiffRect(props: AnimatedProps<DiffRectProps>): void;
40
+ drawText(props: AnimatedProps<TextProps>): void;
41
+ drawTextPath(props: AnimatedProps<TextPathProps>): void;
42
+ drawTextBlob(props: AnimatedProps<TextBlobProps>): void;
43
+ drawGlyphs(props: AnimatedProps<GlyphsProps>): void;
44
+ drawPicture(props: AnimatedProps<PictureProps>): void;
45
+ drawImageSVG(props: AnimatedProps<ImageSVGProps>): void;
46
+ drawParagraph(props: AnimatedProps<ParagraphProps>): void;
47
+ drawAtlas(props: AnimatedProps<AtlasProps>): void;
48
+ }
49
+ export interface JsiRecorder extends BaseRecorder {
50
+ play(canvas: SkCanvas): void;
51
+ applyUpdates(variables: SharedValue<unknown>[]): void;
52
+ }
@@ -28,6 +28,7 @@ import type { AnimatedImageFactory } from "./AnimatedImage";
28
28
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
29
29
  import type { Video } from "./Video";
30
30
  import type { NativeBufferFactory } from "./NativeBuffer";
31
+ import type { JsiRecorder } from "./Recorder";
31
32
  export interface SkiaContext {
32
33
  getSurface(): SkSurface;
33
34
  present(): void;
@@ -80,4 +81,5 @@ export interface Skia {
80
81
  Video: (url: string) => Promise<Video> | Video;
81
82
  Context(surface: bigint, width: number, height: number): SkiaContext;
82
83
  NativeBuffer: NativeBufferFactory;
84
+ Recorder(): JsiRecorder;
83
85
  }
@@ -30,4 +30,5 @@ export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
32
  export * from "./NativeBuffer";
33
+ export * from "./Recorder";
33
34
  export * from "./Video";
@@ -19,5 +19,10 @@ declare class ReanimatedContainer extends Container {
19
19
  constructor(Skia: Skia, nativeId: number);
20
20
  redraw(): void;
21
21
  }
22
- export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | ReanimatedContainer;
22
+ declare class NativeReanimatedContainer extends Container {
23
+ private mapperId;
24
+ constructor(Skia: Skia, nativeId: number);
25
+ redraw(): void;
26
+ }
27
+ export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | ReanimatedContainer | NativeReanimatedContainer;
23
28
  export {};
@@ -0,0 +1,53 @@
1
+ import type { SharedValue } from "react-native-reanimated";
2
+ import type { BaseRecorder, JsiRecorder, Skia } from "../../skia/types";
3
+ import type { PaintProps, NodeType, BlurMaskFilterProps, CTMProps, BoxProps, BoxShadowProps, ImageProps, CircleProps, PointsProps, PathProps, RectProps, RoundedRectProps, OvalProps, LineProps, PatchProps, VerticesProps, DiffRectProps, TextProps, TextPathProps, TextBlobProps, GlyphsProps, PictureProps, ImageSVGProps, ParagraphProps, AtlasProps } from "../../dom/types";
4
+ import type { AnimatedProps } from "../../renderer";
5
+ export declare class ReanimatedRecorder implements BaseRecorder {
6
+ private values;
7
+ private recorder;
8
+ constructor(Skia: Skia);
9
+ private processAnimationValues;
10
+ getRecorder(): JsiRecorder;
11
+ getSharedValues(): SharedValue<unknown>[];
12
+ saveGroup(): void;
13
+ restoreGroup(): void;
14
+ savePaint(props: AnimatedProps<PaintProps>): void;
15
+ restorePaint(): void;
16
+ restorePaintDeclaration(): void;
17
+ materializePaint(): void;
18
+ pushPathEffect(pathEffectType: NodeType, props: AnimatedProps<unknown>): void;
19
+ pushImageFilter(imageFilterType: NodeType, props: AnimatedProps<unknown>): void;
20
+ pushColorFilter(colorFilterType: NodeType, props: AnimatedProps<unknown>): void;
21
+ pushShader(shaderType: NodeType, props: AnimatedProps<unknown>): void;
22
+ pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void;
23
+ composePathEffect(): void;
24
+ composeColorFilter(): void;
25
+ composeImageFilter(): void;
26
+ saveCTM(props: AnimatedProps<CTMProps>): void;
27
+ restoreCTM(): void;
28
+ drawPaint(): void;
29
+ saveLayer(): void;
30
+ saveBackdropFilter(): void;
31
+ drawBox(boxProps: AnimatedProps<BoxProps>, shadows: {
32
+ props: BoxShadowProps;
33
+ }[]): void;
34
+ drawImage(props: AnimatedProps<ImageProps>): void;
35
+ drawCircle(props: AnimatedProps<CircleProps>): void;
36
+ drawPoints(props: AnimatedProps<PointsProps>): void;
37
+ drawPath(props: AnimatedProps<PathProps>): void;
38
+ drawRect(props: AnimatedProps<RectProps>): void;
39
+ drawRRect(props: AnimatedProps<RoundedRectProps>): void;
40
+ drawOval(props: AnimatedProps<OvalProps>): void;
41
+ drawLine(props: AnimatedProps<LineProps>): void;
42
+ drawPatch(props: AnimatedProps<PatchProps>): void;
43
+ drawVertices(props: AnimatedProps<VerticesProps>): void;
44
+ drawDiffRect(props: AnimatedProps<DiffRectProps>): void;
45
+ drawText(props: AnimatedProps<TextProps>): void;
46
+ drawTextPath(props: AnimatedProps<TextPathProps>): void;
47
+ drawTextBlob(props: AnimatedProps<TextBlobProps>): void;
48
+ drawGlyphs(props: AnimatedProps<GlyphsProps>): void;
49
+ drawPicture(props: AnimatedProps<PictureProps>): void;
50
+ drawImageSVG(props: AnimatedProps<ImageSVGProps>): void;
51
+ drawParagraph(props: AnimatedProps<ParagraphProps>): void;
52
+ drawAtlas(props: AnimatedProps<AtlasProps>): void;
53
+ }
@@ -2,7 +2,7 @@ import type { SharedValue } from "react-native-reanimated";
2
2
  import { NodeType } from "../../dom/types";
3
3
  import type { BlurMaskFilterProps, CircleProps, CTMProps, ImageProps, PaintProps, PointsProps, PathProps, RectProps, RoundedRectProps, OvalProps, LineProps, PatchProps, VerticesProps, DiffRectProps, TextProps, TextPathProps, TextBlobProps, GlyphsProps, PictureProps, ImageSVGProps, ParagraphProps, AtlasProps, BoxProps, BoxShadowProps } from "../../dom/types";
4
4
  import type { AnimatedProps } from "../../renderer";
5
- import type { SkPaint } from "../../skia/types";
5
+ import type { SkPaint, BaseRecorder } from "../../skia/types";
6
6
  import type { Command } from "./Core";
7
7
  export interface Recording {
8
8
  commands: Command[];
@@ -11,7 +11,7 @@ export interface Recording {
11
11
  interface AnimationValues {
12
12
  animationValues: Set<SharedValue<unknown>>;
13
13
  }
14
- export declare class Recorder {
14
+ export declare class Recorder implements BaseRecorder {
15
15
  commands: Command[];
16
16
  cursors: Command[][];
17
17
  animationValues: Set<SharedValue<unknown>>;
@@ -1,5 +1,5 @@
1
1
  import type { DrawingNodeProps } from "../../dom/types";
2
+ import type { BaseRecorder } from "../../skia/types/Recorder";
2
3
  import type { Node } from "../Node";
3
- import type { Recorder } from "./Recorder";
4
4
  export declare const processPaint: ({ opacity, color, strokeWidth, blendMode, style, strokeJoin, strokeCap, strokeMiter, antiAlias, dither, paint: paintRef, }: DrawingNodeProps) => DrawingNodeProps | null;
5
- export declare const visit: (recorder: Recorder, root: Node[]) => void;
5
+ export declare const visit: (recorder: BaseRecorder, root: Node[]) => void;
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@shopify/react-native-skia",
3
3
  "publishConfig": {
4
- "access": "public"
4
+ "access": "public",
5
+ "provenance": true
5
6
  },
6
7
  "bin": {
7
8
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
9
  },
9
10
  "title": "React Native Skia",
10
- "version": "1.10.2",
11
+ "version": "1.11.1",
11
12
  "description": "High-performance React Native Graphics using Skia",
12
13
  "main": "lib/module/index.js",
13
14
  "react-native": "src/index.ts",
@@ -3,6 +3,6 @@ import React from "react";
3
3
  import type { SkiaProps } from "../../processors";
4
4
  import type { ImageProps } from "../../../dom/types";
5
5
 
6
- export const Image = (props: SkiaProps<ImageProps>) => {
7
- return <skImage {...props} />;
6
+ export const Image = ({ fit = "contain", ...props }: SkiaProps<ImageProps>) => {
7
+ return <skImage fit={fit} {...props} />;
8
8
  };
@@ -0,0 +1,91 @@
1
+ import type { SharedValue } from "react-native-reanimated";
2
+
3
+ import type {
4
+ TextProps,
5
+ AtlasProps,
6
+ BlurMaskFilterProps,
7
+ BoxProps,
8
+ BoxShadowProps,
9
+ CircleProps,
10
+ CTMProps,
11
+ DiffRectProps,
12
+ GlyphsProps,
13
+ ImageProps,
14
+ ImageSVGProps,
15
+ LineProps,
16
+ NodeType,
17
+ OvalProps,
18
+ PaintProps,
19
+ ParagraphProps,
20
+ PatchProps,
21
+ PathProps,
22
+ PictureProps,
23
+ PointsProps,
24
+ RectProps,
25
+ RoundedRectProps,
26
+ TextBlobProps,
27
+ TextPathProps,
28
+ VerticesProps,
29
+ } from "../../dom/types";
30
+ import type { AnimatedProps } from "../../renderer/processors/Animations/Animations";
31
+
32
+ import type { SkCanvas } from "./Canvas";
33
+
34
+ export interface BaseRecorder {
35
+ saveGroup(): void;
36
+ restoreGroup(): void;
37
+ savePaint(props: AnimatedProps<PaintProps>): void;
38
+ restorePaint(): void;
39
+ restorePaintDeclaration(): void;
40
+ materializePaint(): void;
41
+ pushPathEffect(pathEffectType: NodeType, props: AnimatedProps<unknown>): void;
42
+ pushImageFilter(
43
+ imageFilterType: NodeType,
44
+ props: AnimatedProps<unknown>
45
+ ): void;
46
+ pushColorFilter(
47
+ colorFilterType: NodeType,
48
+ props: AnimatedProps<unknown>
49
+ ): void;
50
+ pushShader(shaderType: NodeType, props: AnimatedProps<unknown>): void;
51
+ pushBlurMaskFilter(props: AnimatedProps<BlurMaskFilterProps>): void;
52
+ composePathEffect(): void;
53
+ composeColorFilter(): void;
54
+ composeImageFilter(): void;
55
+ saveCTM(props: AnimatedProps<CTMProps>): void;
56
+ restoreCTM(): void;
57
+ drawPaint(): void;
58
+ saveLayer(): void;
59
+ saveBackdropFilter(): void;
60
+ drawBox(
61
+ boxProps: AnimatedProps<BoxProps>,
62
+ shadows: {
63
+ props: BoxShadowProps;
64
+ animatedProps?: Record<string, SharedValue<unknown>>;
65
+ }[]
66
+ ): void;
67
+ drawImage(props: AnimatedProps<ImageProps>): void;
68
+ drawCircle(props: AnimatedProps<CircleProps>): void;
69
+ drawPoints(props: AnimatedProps<PointsProps>): void;
70
+ drawPath(props: AnimatedProps<PathProps>): void;
71
+ drawRect(props: AnimatedProps<RectProps>): void;
72
+ drawRRect(props: AnimatedProps<RoundedRectProps>): void;
73
+ drawOval(props: AnimatedProps<OvalProps>): void;
74
+ drawLine(props: AnimatedProps<LineProps>): void;
75
+ drawPatch(props: AnimatedProps<PatchProps>): void;
76
+ drawVertices(props: AnimatedProps<VerticesProps>): void;
77
+ drawDiffRect(props: AnimatedProps<DiffRectProps>): void;
78
+ drawText(props: AnimatedProps<TextProps>): void;
79
+ drawTextPath(props: AnimatedProps<TextPathProps>): void;
80
+ drawTextBlob(props: AnimatedProps<TextBlobProps>): void;
81
+ drawGlyphs(props: AnimatedProps<GlyphsProps>): void;
82
+ drawPicture(props: AnimatedProps<PictureProps>): void;
83
+ drawImageSVG(props: AnimatedProps<ImageSVGProps>): void;
84
+ drawParagraph(props: AnimatedProps<ParagraphProps>): void;
85
+ drawAtlas(props: AnimatedProps<AtlasProps>): void;
86
+ }
87
+
88
+ export interface JsiRecorder extends BaseRecorder {
89
+ play(canvas: SkCanvas): void;
90
+ applyUpdates(variables: SharedValue<unknown>[]): void;
91
+ }
@@ -32,6 +32,7 @@ import type { AnimatedImageFactory } from "./AnimatedImage";
32
32
  import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
33
33
  import type { Video } from "./Video";
34
34
  import type { NativeBufferFactory } from "./NativeBuffer";
35
+ import type { JsiRecorder } from "./Recorder";
35
36
 
36
37
  export interface SkiaContext {
37
38
  getSurface(): SkSurface;
@@ -104,4 +105,5 @@ export interface Skia {
104
105
  Video: (url: string) => Promise<Video> | Video;
105
106
  Context(surface: bigint, width: number, height: number): SkiaContext;
106
107
  NativeBuffer: NativeBufferFactory;
108
+ Recorder(): JsiRecorder;
107
109
  }
@@ -30,4 +30,5 @@ export * from "./Size";
30
30
  export * from "./Paragraph";
31
31
  export * from "./Matrix4";
32
32
  export * from "./NativeBuffer";
33
+ export * from "./Recorder";
33
34
  export * from "./Video";
@@ -132,4 +132,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
132
132
  Context: (_surface: bigint, _width: number, _height: number) => {
133
133
  throw new Error("Not implemented on React Native Web");
134
134
  },
135
+ Recorder: () => {
136
+ throw new Error("Not implemented on React Native Web");
137
+ },
135
138
  });
@@ -1,6 +1,8 @@
1
1
  import Rea from "../external/reanimated/ReanimatedProxy";
2
2
  import type { Skia, SkCanvas } from "../skia/types";
3
3
  import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
4
+ import type { JsiRecorder } from "../skia/types/Recorder";
5
+ import { Platform } from "../Platform";
4
6
 
5
7
  import type { Node } from "./Node";
6
8
  import type { Recording } from "./Recorder/Recorder";
@@ -8,6 +10,7 @@ import { Recorder } from "./Recorder/Recorder";
8
10
  import { visit } from "./Recorder/Visitor";
9
11
  import { replay } from "./Recorder/Player";
10
12
  import { createDrawingContext } from "./Recorder/DrawingContext";
13
+ import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
11
14
 
12
15
  const drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {
13
16
  "worklet";
@@ -26,6 +29,26 @@ const drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {
26
29
  picture.dispose();
27
30
  };
28
31
 
32
+ const nativeDrawOnscreen = (
33
+ Skia: Skia,
34
+ nativeId: number,
35
+ recorder: JsiRecorder
36
+ ) => {
37
+ "worklet";
38
+
39
+ const rec = Skia.PictureRecorder();
40
+ const canvas = rec.beginRecording();
41
+ //const start = performance.now();
42
+
43
+ recorder.play(canvas);
44
+ const picture = rec.finishRecordingAsPicture();
45
+ //const end = performance.now();
46
+ //console.log("Recording time: ", end - start);
47
+ SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
48
+ rec.dispose();
49
+ picture.dispose();
50
+ };
51
+
29
52
  export abstract class Container {
30
53
  public root: Node[] = [];
31
54
  protected recording: Recording | null = null;
@@ -41,7 +64,6 @@ export abstract class Container {
41
64
  this.recording.paintPool,
42
65
  canvas
43
66
  );
44
- //console.log(this.recording.commands);
45
67
  replay(ctx, this.recording.commands);
46
68
  }
47
69
 
@@ -101,8 +123,45 @@ class ReanimatedContainer extends Container {
101
123
  }
102
124
  }
103
125
 
126
+ class NativeReanimatedContainer extends Container {
127
+ private mapperId: number | null = null;
128
+
129
+ constructor(Skia: Skia, nativeId: number) {
130
+ super(Skia, nativeId);
131
+ }
132
+
133
+ redraw() {
134
+ if (this.mapperId !== null) {
135
+ Rea.stopMapper(this.mapperId);
136
+ }
137
+ const { nativeId, Skia } = this;
138
+ const recorder = new ReanimatedRecorder(Skia);
139
+ visit(recorder, this.root);
140
+ const sharedValues = recorder.getSharedValues();
141
+ const sharedRecorder = recorder.getRecorder();
142
+ if (sharedValues.length > 0) {
143
+ this.mapperId = Rea.startMapper(() => {
144
+ "worklet";
145
+ sharedRecorder.applyUpdates(sharedValues);
146
+ nativeDrawOnscreen(Skia, nativeId, sharedRecorder);
147
+ }, sharedValues);
148
+ }
149
+ Rea.runOnUI(() => {
150
+ "worklet";
151
+ nativeDrawOnscreen(Skia, nativeId, sharedRecorder);
152
+ })();
153
+ }
154
+ }
155
+
104
156
  export const createContainer = (Skia: Skia, nativeId: number) => {
105
- return HAS_REANIMATED_3 && nativeId !== -1
106
- ? new ReanimatedContainer(Skia, nativeId)
107
- : new StaticContainer(Skia, nativeId);
157
+ const native = Platform.OS !== "web";
158
+ if (HAS_REANIMATED_3 && nativeId !== -1) {
159
+ if (native) {
160
+ return new NativeReanimatedContainer(Skia, nativeId);
161
+ } else {
162
+ return new ReanimatedContainer(Skia, nativeId);
163
+ }
164
+ } else {
165
+ return new StaticContainer(Skia, nativeId);
166
+ }
108
167
  };
@@ -87,6 +87,7 @@ export const createDrawingContext = (
87
87
  )
88
88
  );
89
89
  }
90
+
90
91
  // Path Effects
91
92
  if (pathEffects.length > 0) {
92
93
  getCurrentPaint().setPathEffect(