@shopify/react-native-skia 1.11.9 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/android/build.gradle +1 -1
  2. package/lib/commonjs/Platform/Platform.web.js +1 -0
  3. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  4. package/lib/commonjs/external/reanimated/textures.js +4 -3
  5. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  6. package/lib/commonjs/headless/index.d.ts +1 -1
  7. package/lib/commonjs/headless/index.js +2 -2
  8. package/lib/commonjs/headless/index.js.map +1 -1
  9. package/lib/commonjs/renderer/Canvas.d.ts +3 -3
  10. package/lib/commonjs/renderer/Canvas.js +12 -31
  11. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  12. package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  13. package/lib/commonjs/renderer/Offscreen.js +4 -4
  14. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  15. package/lib/commonjs/renderer/__tests__/setup.d.ts +6 -5
  16. package/lib/commonjs/sksg/Container.d.ts +3 -1
  17. package/lib/commonjs/sksg/Container.js +7 -1
  18. package/lib/commonjs/sksg/Container.js.map +1 -1
  19. package/lib/commonjs/sksg/Elements.d.ts +1 -1
  20. package/lib/commonjs/sksg/Elements.js.map +1 -1
  21. package/lib/commonjs/sksg/HostConfig.d.ts +2 -2
  22. package/lib/commonjs/sksg/HostConfig.js +36 -6
  23. package/lib/commonjs/sksg/HostConfig.js.map +1 -1
  24. package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
  25. package/lib/commonjs/sksg/Reconciler.js +15 -6
  26. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  27. package/lib/module/Platform/Platform.web.js +1 -0
  28. package/lib/module/Platform/Platform.web.js.map +1 -1
  29. package/lib/module/external/reanimated/textures.js +5 -4
  30. package/lib/module/external/reanimated/textures.js.map +1 -1
  31. package/lib/module/headless/index.d.ts +1 -1
  32. package/lib/module/headless/index.js +2 -2
  33. package/lib/module/headless/index.js.map +1 -1
  34. package/lib/module/renderer/Canvas.d.ts +3 -3
  35. package/lib/module/renderer/Canvas.js +11 -31
  36. package/lib/module/renderer/Canvas.js.map +1 -1
  37. package/lib/module/renderer/Offscreen.d.ts +2 -2
  38. package/lib/module/renderer/Offscreen.js +4 -4
  39. package/lib/module/renderer/Offscreen.js.map +1 -1
  40. package/lib/module/renderer/__tests__/setup.d.ts +6 -5
  41. package/lib/module/sksg/Container.d.ts +3 -1
  42. package/lib/module/sksg/Container.js +7 -1
  43. package/lib/module/sksg/Container.js.map +1 -1
  44. package/lib/module/sksg/Elements.d.ts +1 -1
  45. package/lib/module/sksg/Elements.js.map +1 -1
  46. package/lib/module/sksg/HostConfig.d.ts +2 -2
  47. package/lib/module/sksg/HostConfig.js +36 -7
  48. package/lib/module/sksg/HostConfig.js.map +1 -1
  49. package/lib/module/sksg/Reconciler.d.ts +3 -2
  50. package/lib/module/sksg/Reconciler.js +15 -6
  51. package/lib/module/sksg/Reconciler.js.map +1 -1
  52. package/lib/typescript/lib/commonjs/headless/index.d.ts +1 -1
  53. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +9 -1
  54. package/lib/typescript/lib/commonjs/renderer/Offscreen.d.ts +2 -2
  55. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +3 -0
  56. package/lib/typescript/lib/commonjs/sksg/HostConfig.d.ts +21 -4
  57. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +9 -2
  58. package/lib/typescript/lib/module/Platform/Platform.web.d.ts +1 -1
  59. package/lib/typescript/lib/module/headless/index.d.ts +1 -1
  60. package/lib/typescript/lib/module/mock/index.d.ts +22 -11
  61. package/lib/typescript/lib/module/renderer/Canvas.d.ts +10 -2
  62. package/lib/typescript/lib/module/renderer/Offscreen.d.ts +2 -2
  63. package/lib/typescript/lib/module/sksg/Container.d.ts +3 -0
  64. package/lib/typescript/lib/module/sksg/HostConfig.d.ts +20 -4
  65. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +9 -2
  66. package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +1 -1
  67. package/lib/typescript/src/headless/index.d.ts +1 -1
  68. package/lib/typescript/src/renderer/Canvas.d.ts +3 -3
  69. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
  70. package/lib/typescript/src/renderer/__tests__/setup.d.ts +6 -5
  71. package/lib/typescript/src/sksg/Container.d.ts +3 -1
  72. package/lib/typescript/src/sksg/Elements.d.ts +1 -1
  73. package/lib/typescript/src/sksg/HostConfig.d.ts +2 -2
  74. package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
  75. package/package.json +11 -10
  76. package/src/Platform/Platform.web.tsx +2 -1
  77. package/src/__tests__/snapshots/screens/snapshot2-android-ci.png +0 -0
  78. package/src/__tests__/snapshots/screens/snapshot3-android-ci.png +0 -0
  79. package/src/external/reanimated/textures.tsx +5 -4
  80. package/src/headless/index.ts +2 -2
  81. package/src/renderer/Canvas.tsx +57 -80
  82. package/src/renderer/Offscreen.tsx +4 -4
  83. package/src/renderer/__tests__/Data.spec.tsx +9 -10
  84. package/src/renderer/__tests__/Drawings.spec.tsx +11 -11
  85. package/src/renderer/__tests__/FitBox.spec.tsx +10 -10
  86. package/src/renderer/__tests__/Glyphs.spec.tsx +2 -2
  87. package/src/renderer/__tests__/Image.spec.tsx +2 -2
  88. package/src/renderer/__tests__/Paths.spec.tsx +8 -8
  89. package/src/renderer/__tests__/Picture.spec.tsx +10 -12
  90. package/src/renderer/__tests__/Simple.spec.tsx +6 -6
  91. package/src/renderer/__tests__/Surfaces.spec.tsx +2 -2
  92. package/src/renderer/__tests__/Text.spec.tsx +12 -12
  93. package/src/renderer/__tests__/Transform.spec.tsx +8 -8
  94. package/src/renderer/__tests__/documentation/Group.spec.tsx +12 -12
  95. package/src/renderer/__tests__/documentation/getting-started/HelloWorld.spec.tsx +2 -2
  96. package/src/renderer/__tests__/documentation/paint/Overview.spec.tsx +8 -8
  97. package/src/renderer/__tests__/documentation/shapes/Box.spec.tsx +4 -4
  98. package/src/renderer/__tests__/e2e/Atlas.spec.tsx +3 -3
  99. package/src/renderer/__tests__/e2e/Offscreen.spec.tsx +1 -1
  100. package/src/renderer/__tests__/examples/BlendModes.spec.tsx +4 -4
  101. package/src/renderer/__tests__/setup.tsx +17 -13
  102. package/src/sksg/Container.ts +9 -1
  103. package/src/sksg/Elements.tsx +1 -1
  104. package/src/sksg/HostConfig.ts +37 -7
  105. package/src/sksg/Reconciler.ts +16 -6
  106. package/src/sksg/__tests__/Simple.spec.tsx +8 -8
  107. package/lib/commonjs/sksg/HostConfig2.d.ts +0 -19
  108. package/lib/commonjs/sksg/HostConfig2.js +0 -159
  109. package/lib/commonjs/sksg/HostConfig2.js.map +0 -1
  110. package/lib/module/sksg/HostConfig2.d.ts +0 -19
  111. package/lib/module/sksg/HostConfig2.js +0 -152
  112. package/lib/module/sksg/HostConfig2.js.map +0 -1
  113. package/lib/typescript/lib/commonjs/sksg/HostConfig2.d.ts +0 -44
  114. package/lib/typescript/lib/module/sksg/HostConfig2.d.ts +0 -43
  115. package/lib/typescript/src/sksg/HostConfig2.d.ts +0 -19
  116. package/src/sksg/HostConfig2.ts +0 -247
@@ -1,4 +1,4 @@
1
1
  export function isOnMainThread(): boolean;
2
- export function drawAsPicture(element: any, bounds: any): import("../../..").SkPicture;
3
- export function drawAsImage(element: any, size: any): import("../../..").SkImage;
2
+ export function drawAsPicture(element: any, bounds: any): Promise<import("../../..").SkPicture>;
3
+ export function drawAsImage(element: any, size: any): Promise<import("../../..").SkImage>;
4
4
  export function drawAsImageFromPicture(picture: any, size: any): import("../../..").SkImage;
@@ -2,6 +2,9 @@ export class Container {
2
2
  constructor(Skia: any, nativeId: any);
3
3
  Skia: any;
4
4
  nativeId: any;
5
+ set root(value: any);
6
+ get root(): any;
7
+ _root: any;
5
8
  unmount(): void;
6
9
  unmounted: boolean | undefined;
7
10
  drawOnCanvas(canvas: any): void;
@@ -7,8 +7,8 @@ export namespace sksgHostConfig {
7
7
  let scheduleTimeout: typeof setTimeout;
8
8
  let cancelTimeout: typeof clearTimeout;
9
9
  let noTimeout: number;
10
- function getRootHostContext(_rootContainerInstance: any): null;
11
- function getChildHostContext(_parentHostContext: any, _type: any, _rootContainerInstance: any): null;
10
+ function getRootHostContext(_rootContainerInstance: any): {};
11
+ function getChildHostContext(_parentHostContext: any, _type: any, _rootContainerInstance: any): {};
12
12
  function shouldSetTextContent(_type: any, _props: any): boolean;
13
13
  function createTextInstance(_text: any, _rootContainerInstance: any, _hostContext: any, _internalInstanceHandle: any): never;
14
14
  function createInstance(type: any, propsWithChildren: any, _container: any, _hostContext: any, _internalInstanceHandle: any): {
@@ -20,13 +20,13 @@ export namespace sksgHostConfig {
20
20
  function finalizeInitialChildren(parentInstance: any, _type: any, _props: any, _rootContainerInstance: any, _hostContext: any): boolean;
21
21
  function commitMount(): void;
22
22
  function prepareForCommit(_container: any): null;
23
- function resetAfterCommit(container: any): void;
23
+ function resetAfterCommit(_container: any): void;
24
24
  function getPublicInstance(node: any): any;
25
25
  function commitTextUpdate(_textInstance: any, _oldText: any, _newText: any): void;
26
26
  function clearContainer(_container: any): void;
27
27
  function prepareUpdate(_instance: any, _type: any, oldProps: any, newProps: any, container: any, _hostContext: any): any;
28
28
  function preparePortalMount(): void;
29
- function cloneInstance(instance: any, _updatePayload: any, _type: any, _oldProps: any, newProps: any, _internalInstanceHandle: any, keepChildren: any, _recyclableInstance: any): {
29
+ function cloneInstance(instance: any, _type: any, _oldProps: any, newProps: any, _updatePayload: any, _internalInstanceHandle: any, keepChildren: any, _recyclableInstance: any): {
30
30
  type: any;
31
31
  props: any;
32
32
  children: any[];
@@ -44,4 +44,20 @@ export namespace sksgHostConfig {
44
44
  function getInstanceFromNode(_node: any): never;
45
45
  function prepareScopeUpdate(_scopeInstance: any, _instance: any): never;
46
46
  function getInstanceFromScope(_scopeInstance: any): never;
47
+ function shouldAttemptEagerTransition(): boolean;
48
+ function trackSchedulerEvent(): void;
49
+ function resolveEventType(): null;
50
+ function resolveEventTimeStamp(): number;
51
+ function requestPostPaintCallback(): void;
52
+ function maySuspendCommit(): boolean;
53
+ function preloadInstance(): boolean;
54
+ function startSuspendingCommit(): void;
55
+ function suspendInstance(): void;
56
+ function waitForCommitToBeReady(): null;
57
+ let NotPendingTransition: null;
58
+ let HostTransitionContext: import("react").Context<null>;
59
+ function setCurrentUpdatePriority(newPriority: any): void;
60
+ function getCurrentUpdatePriority(): number;
61
+ function resolveUpdatePriority(): number;
62
+ function resetFormInstance(): void;
47
63
  }
@@ -10,6 +10,8 @@ export class SkiaSGRoot {
10
10
  } | undefined;
11
11
  Skia: any;
12
12
  nativeId: any;
13
+ root: any;
14
+ _root: any;
13
15
  unmount(): void;
14
16
  unmounted: boolean | undefined;
15
17
  drawOnCanvas(canvas: any): void;
@@ -22,6 +24,8 @@ export class SkiaSGRoot {
22
24
  mapperId: any;
23
25
  Skia: any;
24
26
  nativeId: any;
27
+ root: any;
28
+ _root: any;
25
29
  unmount(): void;
26
30
  unmounted: boolean | undefined;
27
31
  drawOnCanvas(canvas: any): void;
@@ -30,6 +34,8 @@ export class SkiaSGRoot {
30
34
  mapperId: any;
31
35
  Skia: any;
32
36
  nativeId: any;
37
+ root: any;
38
+ _root: any;
33
39
  unmount(): void;
34
40
  unmounted: boolean | undefined;
35
41
  drawOnCanvas(canvas: any): void;
@@ -41,8 +47,9 @@ export class SkiaSGRoot {
41
47
  children: any;
42
48
  isDeclaration: boolean;
43
49
  };
44
- render(element: any): void;
50
+ updateContainer(element: any): Promise<any>;
51
+ render(element: any): Promise<void>;
45
52
  drawOnCanvas(canvas: any): void;
46
53
  getPicture(): any;
47
- unmount(): void;
54
+ unmount(): Promise<any>;
48
55
  }
@@ -16,6 +16,6 @@ export class SkiaPictureView extends React.Component<any, any, any> {
16
16
  * Sends a redraw request to the native SkiaView.
17
17
  */
18
18
  redraw(): void;
19
- render(): React.CElement<object, React.Component<object, {}, any> & Readonly<import("react-native").NativeMethods>>;
19
+ render(): React.CElement<object, React.Component<object, {}, any> & import("react-native").NativeMethods>;
20
20
  }
21
21
  import React from "react";
@@ -5,4 +5,4 @@ export declare const makeOffscreenSurface: (width: number, height: number) => Sk
5
5
  export declare const getSkiaExports: () => {
6
6
  Skia: import("../skia/types").Skia;
7
7
  };
8
- export declare const drawOffscreen: (surface: SkSurface, element: ReactNode) => import("../skia").SkImage;
8
+ export declare const drawOffscreen: (surface: SkSurface, element: ReactNode) => Promise<import("../skia").SkImage>;
@@ -9,12 +9,12 @@ interface CanvasRef extends FC<CanvasProps> {
9
9
  redraw(): void;
10
10
  getNativeId(): number;
11
11
  }
12
- export declare const useCanvasRef: () => React.RefObject<CanvasRef>;
12
+ export declare const useCanvasRef: () => React.RefObject<CanvasRef | null>;
13
13
  export interface CanvasProps extends ViewProps {
14
14
  debug?: boolean;
15
15
  opaque?: boolean;
16
16
  onSize?: SharedValue<SkSize>;
17
- mode?: "continuous" | "default";
17
+ ref?: React.Ref<CanvasRef>;
18
18
  }
19
- export declare const Canvas: React.ForwardRefExoticComponent<CanvasProps & React.RefAttributes<unknown>>;
19
+ export declare const Canvas: ({ debug, opaque, children, onSize, onLayout: _onLayout, ref, ...viewProps }: CanvasProps) => React.JSX.Element;
20
20
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { ReactElement } from "react";
2
2
  import type { SkPicture, SkRect, SkSize } from "../skia/types";
3
3
  export declare const isOnMainThread: () => boolean;
4
- export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => SkPicture;
5
- export declare const drawAsImage: (element: ReactElement, size: SkSize) => import("../skia").SkImage;
4
+ export declare const drawAsPicture: (element: ReactElement, bounds?: SkRect) => Promise<SkPicture>;
5
+ export declare const drawAsImage: (element: ReactElement, size: SkSize) => Promise<import("../skia").SkImage>;
6
6
  export declare const drawAsImageFromPicture: (picture: SkPicture, size: SkSize) => import("../skia").SkImage;
@@ -43,13 +43,14 @@ export declare const center: {
43
43
  x: number;
44
44
  y: number;
45
45
  };
46
- export declare const drawOnNode: (element: ReactNode) => SkiaExports.SkSurface;
47
- export declare const mountCanvas: (element: ReactNode) => {
46
+ export declare const drawOnNode: (element: ReactNode) => Promise<SkiaExports.SkSurface>;
47
+ export declare const mountCanvas: (element: ReactNode) => Promise<{
48
48
  surface: SkiaExports.SkSurface;
49
49
  root: SkiaSGRoot;
50
- draw: () => void;
51
- };
52
- export declare const serialize: (element: ReactNode) => string;
50
+ render: () => Promise<void>;
51
+ draw: () => Promise<void>;
52
+ }>;
53
+ export declare const serialize: (element: ReactNode) => Promise<string>;
53
54
  export type EvalContext = Record<string, any>;
54
55
  interface TestingSurface {
55
56
  eval<Ctx extends EvalContext = EvalContext, R = any>(fn: (Skia: Skia, ctx: Ctx) => R, ctx?: Ctx): Promise<R>;
@@ -5,10 +5,12 @@ import "../views/api";
5
5
  export declare abstract class Container {
6
6
  protected Skia: Skia;
7
7
  protected nativeId: number;
8
- root: Node[];
8
+ private _root;
9
9
  protected recording: Recording | null;
10
10
  protected unmounted: boolean;
11
11
  constructor(Skia: Skia, nativeId: number);
12
+ get root(): Node[];
13
+ set root(value: Node[]);
12
14
  unmount(): void;
13
15
  drawOnCanvas(canvas: SkCanvas): void;
14
16
  abstract redraw(): void;
@@ -1,6 +1,6 @@
1
1
  import type { FractalNoiseProps, CircleProps, DrawingNodeProps, ImageProps, PaintProps, PathProps, LineProps, OvalProps, DiffRectProps, PointsProps, RectProps, RoundedRectProps, TextProps, VerticesProps, BlurMaskFilterProps, BlendImageFilterProps, BlurImageFilterProps, DisplacementMapImageFilterProps, DropShadowImageFilterProps, OffsetImageFilterProps, RuntimeShaderImageFilterProps, MatrixColorFilterProps, ShaderProps, ImageShaderProps, LinearGradientProps, GroupProps, PatchProps, BlendColorFilterProps, DashPathEffectProps, DiscretePathEffectProps, CornerPathEffectProps, Line2DPathEffectProps, Path1DPathEffectProps, Path2DPathEffectProps, TextPathProps, TextBlobProps, GlyphsProps, TwoPointConicalGradientProps, TurbulenceProps, SweepGradientProps, RadialGradientProps, ColorProps, PictureProps, ImageSVGProps, LerpColorFilterProps, BoxProps, BoxShadowProps, ParagraphProps, AtlasProps, ChildrenProps, MorphologyImageFilterProps, BlendProps } from "../dom/types";
2
2
  import type { SkiaProps } from "../renderer";
3
- declare global {
3
+ declare module "react" {
4
4
  namespace JSX {
5
5
  interface IntrinsicElements {
6
6
  skGroup: SkiaProps<GroupProps>;
@@ -2,14 +2,14 @@ import type { HostConfig } from "react-reconciler";
2
2
  import type { NodeType } from "../dom/types";
3
3
  import type { Node } from "./Node";
4
4
  import type { Container } from "./Container";
5
- export declare const debug: (message?: any, ...optionalParams: any[]) => void;
5
+ export declare const debug: (...args: Parameters<typeof console.log>) => void;
6
6
  type Instance = Node;
7
7
  type Props = object;
8
8
  type TextInstance = Node;
9
9
  type SuspenseInstance = Instance;
10
10
  type HydratableInstance = Instance;
11
11
  type PublicInstance = Instance;
12
- type HostContext = null;
12
+ type HostContext = object;
13
13
  type UpdatePayload = Container;
14
14
  type ChildSet = Node[];
15
15
  type TimeoutHandle = NodeJS.Timeout;
@@ -13,8 +13,9 @@ export declare class SkiaSGRoot {
13
13
  children: import("./Node").Node<unknown>[];
14
14
  isDeclaration: boolean;
15
15
  };
16
- render(element: ReactNode): void;
16
+ private updateContainer;
17
+ render(element: ReactNode): Promise<void>;
17
18
  drawOnCanvas(canvas: SkCanvas): void;
18
19
  getPicture(): import("../skia/types").SkPicture;
19
- unmount(): void;
20
+ unmount(): Promise<unknown>;
20
21
  }
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "setup-skia-web": "./scripts/setup-canvaskit.js"
9
9
  },
10
10
  "title": "React Native Skia",
11
- "version": "1.11.9",
11
+ "version": "2.0.0-next.1",
12
12
  "description": "High-performance React Native Graphics using Skia",
13
13
  "main": "lib/module/index.js",
14
14
  "react-native": "src/index.ts",
@@ -76,9 +76,9 @@
76
76
  "licenseFilename": "LICENSE.md",
77
77
  "readmeFilename": "README.md",
78
78
  "peerDependencies": {
79
- "react": ">=18.0",
80
- "react-native": ">=0.64",
81
- "react-native-reanimated": ">=2.0.0"
79
+ "react": ">=19.0",
80
+ "react-native": ">=0.78",
81
+ "react-native-reanimated": ">=3.0.0"
82
82
  },
83
83
  "peerDependenciesMeta": {
84
84
  "react-native": {
@@ -96,7 +96,7 @@
96
96
  "@types/jest": "29.5.6",
97
97
  "@types/pixelmatch": "5.2.4",
98
98
  "@types/pngjs": "6.0.1",
99
- "@types/react": "^18.2.6",
99
+ "@types/react": "^19.0.0",
100
100
  "@types/react-reconciler": "0.28.9",
101
101
  "@types/ws": "8.5.3",
102
102
  "eslint": "8",
@@ -108,10 +108,10 @@
108
108
  "pixelmatch": "5.3.0",
109
109
  "pngjs": "6.0.0",
110
110
  "prettier": "2.8.7",
111
- "react": "18.3.1",
112
- "react-native": "0.75.2",
111
+ "react": "19.0.0",
112
+ "react-native": "0.78.0",
113
113
  "react-native-builder-bob": "0.18.2",
114
- "react-native-reanimated": "^3.16.5",
114
+ "react-native-reanimated": "3.17.1",
115
115
  "rimraf": "3.0.2",
116
116
  "semantic-release": "^24.1.0",
117
117
  "semantic-release-yarn": "^3.0.2",
@@ -122,7 +122,7 @@
122
122
  },
123
123
  "dependencies": {
124
124
  "canvaskit-wasm": "0.39.1",
125
- "react-reconciler": "0.27.0"
125
+ "react-reconciler": "0.31.0"
126
126
  },
127
127
  "eslintIgnore": [
128
128
  "node_modules/",
@@ -154,5 +154,6 @@
154
154
  }
155
155
  ]
156
156
  ]
157
- }
157
+ },
158
+ "stableVersion": "0.0.0"
158
159
  }
@@ -98,7 +98,8 @@ const useElementLayout = (ref: RefObject<Div>, onLayout: OnLayout) => {
98
98
  const View = (({ children, onLayout, style: rawStyle }: ViewProps) => {
99
99
  const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);
100
100
  const ref = useRef<Div>(null);
101
- useElementLayout(ref, onLayout);
101
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
102
+ useElementLayout(ref as any, onLayout);
102
103
  const cssStyles = useMemo(() => {
103
104
  return {
104
105
  alignItems: "stretch" as const,
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo } from "react";
1
+ import { useEffect, useMemo, useState } from "react";
2
2
  import type { ReactElement } from "react";
3
3
  import type { SharedValue } from "react-native-reanimated";
4
4
 
@@ -27,13 +27,14 @@ const createTexture = (
27
27
 
28
28
  export const useTexture = (element: ReactElement, size: SkSize) => {
29
29
  const { width, height } = size;
30
- const picture = useMemo(() => {
31
- return drawAsPicture(element, {
30
+ const [picture, setPicture] = useState<SkPicture | null>(null);
31
+ useEffect(() => {
32
+ drawAsPicture(element, {
32
33
  x: 0,
33
34
  y: 0,
34
35
  width,
35
36
  height,
36
- });
37
+ }).then((pic) => setPicture(pic));
37
38
  }, [element, width, height]);
38
39
  return usePictureAsTexture(picture, size);
39
40
  };
@@ -29,9 +29,9 @@ export const getSkiaExports = () => {
29
29
  return { Skia };
30
30
  };
31
31
 
32
- export const drawOffscreen = (surface: SkSurface, element: ReactNode) => {
32
+ export const drawOffscreen = async (surface: SkSurface, element: ReactNode) => {
33
33
  const root = new SkiaSGRoot(Skia);
34
- root.render(element);
34
+ await root.render(element);
35
35
  const canvas = surface.getCanvas();
36
36
  root.drawOnCanvas(canvas);
37
37
  root.unmount();
@@ -1,9 +1,9 @@
1
1
  import type { FC } from "react";
2
2
  import React, {
3
- forwardRef,
4
3
  useCallback,
5
4
  useEffect,
6
5
  useImperativeHandle,
6
+ useLayoutEffect,
7
7
  useMemo,
8
8
  useRef,
9
9
  } from "react";
@@ -26,7 +26,7 @@ interface CanvasRef extends FC<CanvasProps> {
26
26
 
27
27
  export const useCanvasRef = () => useRef<CanvasRef>(null);
28
28
 
29
- const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
29
+ //const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
30
30
 
31
31
  // TODO: no need to go through the JS thread for this
32
32
  const useOnSizeEvent = (
@@ -52,87 +52,64 @@ export interface CanvasProps extends ViewProps {
52
52
  debug?: boolean;
53
53
  opaque?: boolean;
54
54
  onSize?: SharedValue<SkSize>;
55
- mode?: "continuous" | "default";
55
+ ref?: React.Ref<CanvasRef>;
56
56
  }
57
57
 
58
- export const Canvas = forwardRef(
59
- (
60
- {
61
- mode,
62
- debug,
63
- opaque,
64
- children,
65
- onSize,
66
- onLayout: _onLayout,
67
- ...viewProps
68
- }: CanvasProps,
69
- ref
70
- ) => {
71
- const rafId = useRef<number | null>(null);
72
- const onLayout = useOnSizeEvent(onSize, _onLayout);
73
- // Native ID
74
- const nativeId = useMemo(() => {
75
- return SkiaViewNativeId.current++;
76
- }, []);
58
+ export const Canvas = ({
59
+ debug,
60
+ opaque,
61
+ children,
62
+ onSize,
63
+ onLayout: _onLayout,
64
+ ref,
65
+ ...viewProps
66
+ }: CanvasProps) => {
67
+ const onLayout = useOnSizeEvent(onSize, _onLayout);
68
+ // Native ID
69
+ const nativeId = useMemo(() => {
70
+ return SkiaViewNativeId.current++;
71
+ }, []);
77
72
 
78
- // Root
79
- const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
73
+ // Root
74
+ const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
80
75
 
81
- // Render effects
82
- useEffect(() => {
83
- root.render(children);
84
- }, [children, root]);
76
+ useLayoutEffect(() => {
77
+ root.render(children);
78
+ }, [root, children]);
85
79
 
86
- useEffect(() => {
87
- return () => {
88
- root.unmount();
89
- };
90
- }, [root]);
80
+ useEffect(() => {
81
+ return () => {
82
+ root.unmount();
83
+ };
84
+ }, [root]);
91
85
 
92
- const requestRedraw = useCallback(() => {
93
- rafId.current = requestAnimationFrame(() => {
94
- root.render(children);
95
- if (mode === "continuous") {
96
- requestRedraw();
97
- }
98
- });
99
- }, [children, mode, root]);
100
-
101
- useEffect(() => {
102
- if (mode === "continuous") {
103
- console.warn("The `mode` property in `Canvas` is deprecated.");
104
- requestRedraw();
105
- }
106
- return () => {
107
- if (rafId.current !== null) {
108
- cancelAnimationFrame(rafId.current);
109
- }
110
- };
111
- }, [mode, requestRedraw]);
112
- // Component methods
113
- useImperativeHandle(ref, () => ({
114
- makeImageSnapshot: (rect?: SkRect) => {
115
- return SkiaViewApi.makeImageSnapshot(nativeId, rect);
116
- },
117
- makeImageSnapshotAsync: (rect?: SkRect) => {
118
- return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);
119
- },
120
- redraw: () => {
121
- SkiaViewApi.requestRedraw(nativeId);
122
- },
123
- getNativeId: () => {
124
- return nativeId;
125
- },
126
- }));
127
- return (
128
- <NativeSkiaPictureView
129
- collapsable={false}
130
- nativeID={`${nativeId}`}
131
- debug={debug}
132
- opaque={opaque}
133
- onLayout={onLayout}
134
- {...viewProps}
135
- />
136
- );
137
- }
138
- );
86
+ // Component methods
87
+ useImperativeHandle(
88
+ ref,
89
+ () =>
90
+ ({
91
+ makeImageSnapshot: (rect?: SkRect) => {
92
+ return SkiaViewApi.makeImageSnapshot(nativeId, rect);
93
+ },
94
+ makeImageSnapshotAsync: (rect?: SkRect) => {
95
+ return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);
96
+ },
97
+ redraw: () => {
98
+ SkiaViewApi.requestRedraw(nativeId);
99
+ },
100
+ getNativeId: () => {
101
+ return nativeId;
102
+ },
103
+ } as CanvasRef)
104
+ );
105
+ return (
106
+ <SkiaPictureViewNativeComponent
107
+ collapsable={false}
108
+ nativeID={`${nativeId}`}
109
+ debug={debug}
110
+ opaque={opaque}
111
+ onLayout={onLayout}
112
+ {...viewProps}
113
+ />
114
+ );
115
+ };
@@ -14,19 +14,19 @@ export const isOnMainThread = () => {
14
14
  );
15
15
  };
16
16
 
17
- export const drawAsPicture = (element: ReactElement, bounds?: SkRect) => {
17
+ export const drawAsPicture = async (element: ReactElement, bounds?: SkRect) => {
18
18
  const recorder = Skia.PictureRecorder();
19
19
  const canvas = recorder.beginRecording(bounds);
20
20
  const root = new SkiaSGRoot(Skia);
21
- root.render(element);
21
+ await root.render(element);
22
22
  root.drawOnCanvas(canvas);
23
23
  const picture = recorder.finishRecordingAsPicture();
24
24
  root.unmount();
25
25
  return picture;
26
26
  };
27
27
 
28
- export const drawAsImage = (element: ReactElement, size: SkSize) => {
29
- return drawAsImageFromPicture(drawAsPicture(element), size);
28
+ export const drawAsImage = async (element: ReactElement, size: SkSize) => {
29
+ return drawAsImageFromPicture(await drawAsPicture(element), size);
30
30
  };
31
31
 
32
32
  export const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {
@@ -39,29 +39,28 @@ describe("Data Loading", () => {
39
39
  expect(SkiaRenderer).toBeDefined();
40
40
  });
41
41
  it("Should accept null as an argument", async () => {
42
- const { surface, draw } = mountCanvas(<CheckData />);
43
- draw();
42
+ const { surface, draw } = await mountCanvas(<CheckData />);
43
+ await draw();
44
44
  processResult(surface, "snapshots/font/green.png");
45
- await wait(42);
46
- draw();
45
+ await draw();
47
46
  processResult(surface, "snapshots/font/green.png");
48
47
  });
49
48
 
50
49
  it("Should load a font file", async () => {
51
- const { surface, draw } = mountCanvas(<CheckFont />);
52
- draw();
50
+ const { surface, draw } = await mountCanvas(<CheckFont />);
51
+ await draw();
53
52
  processResult(surface, "snapshots/font/red.png");
54
53
  await wait(1500);
55
- draw();
54
+ await draw();
56
55
  processResult(surface, "snapshots/font/green.png");
57
56
  });
58
57
 
59
58
  it("Should load an image", async () => {
60
- const { surface, draw } = mountCanvas(<CheckImage />);
61
- draw();
59
+ const { surface, draw } = await mountCanvas(<CheckImage />);
60
+ await draw();
62
61
  processResult(surface, "snapshots/font/red.png");
63
62
  await wait(1500);
64
- draw();
63
+ await draw();
65
64
  processResult(surface, "snapshots/font/green.png");
66
65
  });
67
66
  });
@@ -30,9 +30,9 @@ const CheckEmptyCanvas = () => {
30
30
  };
31
31
 
32
32
  describe("Test introductionary examples from our documentation", () => {
33
- it("Should blend colors using multiplication", () => {
33
+ it("Should blend colors using multiplication", async () => {
34
34
  const r = width * 0.33;
35
- const surface = drawOnNode(
35
+ const surface = await drawOnNode(
36
36
  <Group blendMode="multiply">
37
37
  <Circle cx={r} cy={r} r={r} color="cyan" />
38
38
  <Circle cx={width - r} cy={r} r={r} color="magenta" />
@@ -42,9 +42,9 @@ describe("Test introductionary examples from our documentation", () => {
42
42
  processResult(surface, "snapshots/drawings/blend-mode-multiply.png");
43
43
  });
44
44
 
45
- it("Should use a blur image filter", () => {
45
+ it("Should use a blur image filter", async () => {
46
46
  const r = width * 0.33;
47
- const surface = drawOnNode(
47
+ const surface = await drawOnNode(
48
48
  <Group blendMode="multiply">
49
49
  <Blur blur={30} />
50
50
  <Circle cx={r} cy={r} r={r} color="cyan" />
@@ -55,10 +55,10 @@ describe("Test introductionary examples from our documentation", () => {
55
55
  processResult(surface, "snapshots/drawings/blur-node.png");
56
56
  });
57
57
 
58
- it("Should use multiple paint definitions for one drawing command", () => {
58
+ it("Should use multiple paint definitions for one drawing command", async () => {
59
59
  const r = width / 4;
60
60
  const strokeWidth = 50;
61
- const surface = drawOnNode(
61
+ const surface = await drawOnNode(
62
62
  <>
63
63
  <Circle cx={width / 2} cy={width / 2} r={r} color="red">
64
64
  <Paint color="lightblue" />
@@ -70,7 +70,7 @@ describe("Test introductionary examples from our documentation", () => {
70
70
  processResult(surface, "snapshots/drawings/multiple-paints.png");
71
71
  });
72
72
 
73
- it("Should draw DRect", () => {
73
+ it("Should draw DRect", async () => {
74
74
  const { rrect, rect } = importSkia();
75
75
  const padding = 25 * PIXEL_RATIO;
76
76
  const outer = rrect(rect(0, 0, width, width), padding, padding);
@@ -79,18 +79,18 @@ describe("Test introductionary examples from our documentation", () => {
79
79
  padding * 2,
80
80
  padding * 2
81
81
  );
82
- const surface = drawOnNode(
82
+ const surface = await drawOnNode(
83
83
  <DiffRect inner={inner} outer={outer} color="lightblue" />
84
84
  );
85
85
  processResult(surface, docPath("shapes/drect.png"));
86
86
  });
87
87
 
88
88
  it("should clear the canvas even if it's empty", async () => {
89
- const { surface, draw } = mountCanvas(<CheckEmptyCanvas />);
90
- draw();
89
+ const { surface, draw } = await mountCanvas(<CheckEmptyCanvas />);
90
+ await draw();
91
91
  processResult(surface, "snapshots/green.png");
92
92
  await wait(1000);
93
- draw();
93
+ await draw();
94
94
  processResult(surface, "snapshots/transparent.png");
95
95
  });
96
96
  });