@shopify/react-native-skia 2.3.10 → 2.3.12

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 (53) hide show
  1. package/android/cpp/jni/include/JniSkiaBaseView.h +9 -2
  2. package/android/cpp/jni/include/JniSkiaPictureView.h +97 -2
  3. package/android/cpp/rnskia-android/OpenGLContext.h +1 -0
  4. package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +3 -1
  5. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +43 -0
  6. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +5 -0
  7. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerDelegate.java +8 -2
  8. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
  9. package/apple/SkiaCVPixelBufferUtils.mm +8 -4
  10. package/cpp/api/recorder/Drawings.h +10 -2
  11. package/cpp/api/recorder/JsiRecorder.h +1 -1
  12. package/cpp/rnskia/RNSkJsiViewApi.h +2 -0
  13. package/cpp/rnskia/RNSkPictureView.h +2 -0
  14. package/lib/commonjs/renderer/Canvas.js +2 -1
  15. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  16. package/lib/commonjs/sksg/Container.native.d.ts +0 -3
  17. package/lib/commonjs/sksg/Container.native.js +8 -14
  18. package/lib/commonjs/sksg/Container.native.js.map +1 -1
  19. package/lib/commonjs/sksg/Reconciler.js +2 -2
  20. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  21. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  22. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  23. package/lib/commonjs/views/SkiaPictureView.d.ts +1 -0
  24. package/lib/commonjs/views/SkiaPictureView.js +3 -1
  25. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  26. package/lib/commonjs/views/SkiaPictureView.web.js +13 -2
  27. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  28. package/lib/module/renderer/Canvas.js +2 -1
  29. package/lib/module/renderer/Canvas.js.map +1 -1
  30. package/lib/module/sksg/Container.native.d.ts +0 -3
  31. package/lib/module/sksg/Container.native.js +8 -14
  32. package/lib/module/sksg/Container.native.js.map +1 -1
  33. package/lib/module/sksg/Reconciler.js +2 -2
  34. package/lib/module/sksg/Reconciler.js.map +1 -1
  35. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  36. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  37. package/lib/module/views/SkiaPictureView.d.ts +1 -0
  38. package/lib/module/views/SkiaPictureView.js +3 -1
  39. package/lib/module/views/SkiaPictureView.js.map +1 -1
  40. package/lib/module/views/SkiaPictureView.web.js +13 -2
  41. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  42. package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +0 -4
  43. package/lib/typescript/lib/module/sksg/Container.native.d.ts +0 -4
  44. package/lib/typescript/src/sksg/Container.native.d.ts +0 -3
  45. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  46. package/lib/typescript/src/views/SkiaPictureView.d.ts +1 -0
  47. package/package.json +1 -1
  48. package/src/renderer/Canvas.tsx +4 -2
  49. package/src/sksg/Container.native.ts +7 -16
  50. package/src/sksg/Reconciler.ts +2 -2
  51. package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
  52. package/src/views/SkiaPictureView.tsx +3 -1
  53. package/src/views/SkiaPictureView.web.tsx +14 -2
@@ -4,12 +4,8 @@ import _StaticContainer = require("./StaticContainer");
4
4
  declare class NativeReanimatedContainer extends _StaticContainer.Container {
5
5
  constructor(Skia: any, nativeId: any);
6
6
  nativeId: any;
7
- recorderA: _ReanimatedRecorder.ReanimatedRecorder;
8
- recorderB: _ReanimatedRecorder.ReanimatedRecorder;
9
- currentRecorder: _ReanimatedRecorder.ReanimatedRecorder;
10
7
  picture: any;
11
8
  redraw(): void;
12
9
  mapperId: any;
13
10
  }
14
- import _ReanimatedRecorder = require("./Recorder/ReanimatedRecorder");
15
11
  export {};
@@ -3,13 +3,9 @@ import { StaticContainer } from "./StaticContainer";
3
3
  declare class NativeReanimatedContainer extends Container {
4
4
  constructor(Skia: any, nativeId: any);
5
5
  nativeId: any;
6
- recorderA: ReanimatedRecorder;
7
- recorderB: ReanimatedRecorder;
8
- currentRecorder: ReanimatedRecorder;
9
6
  picture: any;
10
7
  redraw(): void;
11
8
  mapperId: any;
12
9
  }
13
10
  import { Container } from "./StaticContainer";
14
- import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
15
11
  export {};
@@ -6,9 +6,6 @@ declare class NativeReanimatedContainer extends Container {
6
6
  private nativeId;
7
7
  private mapperId;
8
8
  private picture;
9
- private recorderA;
10
- private recorderB;
11
- private currentRecorder;
12
9
  constructor(Skia: Skia, nativeId: number);
13
10
  redraw(): void;
14
11
  }
@@ -3,6 +3,7 @@ export interface NativeProps extends ViewProps {
3
3
  debug?: boolean;
4
4
  opaque?: boolean;
5
5
  colorSpace?: string;
6
+ coldStart?: boolean;
6
7
  }
7
8
  declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
8
9
  export default _default;
@@ -3,6 +3,7 @@ import type { SkRect } from "../skia/types";
3
3
  import type { SkiaPictureViewNativeProps } from "./types";
4
4
  interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
5
5
  mode?: "default" | "continuous";
6
+ coldStart?: boolean;
6
7
  }
7
8
  export declare class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
8
9
  private requestId;
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": "2.3.10",
11
+ "version": "2.3.12",
12
12
  "skia": {
13
13
  "version": "m142",
14
14
  "checksums": {
@@ -160,7 +160,6 @@ export const Canvas = ({
160
160
  },
161
161
  [onLayout, onSize]
162
162
  );
163
-
164
163
  return (
165
164
  <SkiaPictureViewNativeComponent
166
165
  ref={viewRef}
@@ -169,7 +168,10 @@ export const Canvas = ({
169
168
  debug={debug}
170
169
  opaque={opaque}
171
170
  colorSpace={colorSpace}
172
- onLayout={onLayoutWeb}
171
+ coldStart={false}
172
+ onLayout={
173
+ Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
174
+ }
173
175
  {...viewProps}
174
176
  />
175
177
  );
@@ -27,18 +27,12 @@ const nativeDrawOnscreen = (
27
27
  class NativeReanimatedContainer extends Container {
28
28
  private mapperId: number | null = null;
29
29
  private picture: SkPicture;
30
- private recorderA: ReanimatedRecorder;
31
- private recorderB: ReanimatedRecorder;
32
- private currentRecorder: ReanimatedRecorder;
33
30
 
34
31
  constructor(
35
32
  Skia: Skia,
36
33
  private nativeId: number
37
34
  ) {
38
35
  super(Skia);
39
- this.recorderA = new ReanimatedRecorder(Skia);
40
- this.recorderB = new ReanimatedRecorder(Skia);
41
- this.currentRecorder = this.recorderA;
42
36
  this.picture = Skia.Picture.MakePicture(null)!;
43
37
  }
44
38
 
@@ -49,21 +43,18 @@ class NativeReanimatedContainer extends Container {
49
43
  if (this.unmounted) {
50
44
  return;
51
45
  }
52
-
53
- // Swap to the next recorder (double buffering)
54
- const recorder = this.currentRecorder;
55
- this.currentRecorder =
56
- this.currentRecorder === this.recorderA ? this.recorderB : this.recorderA;
57
-
58
- const { nativeId, picture } = this;
59
- recorder.reset();
46
+ const recorder = new ReanimatedRecorder(this.Skia);
47
+ const { nativeId, picture, Skia } = this;
60
48
  visit(recorder, this.root);
61
49
  const sharedValues = recorder.getSharedValues();
62
50
  const sharedRecorder = recorder.getRecorder();
63
- Rea.runOnUI(() => {
51
+ // Draw first frame
52
+ Rea.executeOnUIRuntimeSync(() => {
64
53
  "worklet";
65
- nativeDrawOnscreen(nativeId, sharedRecorder, picture);
54
+ const firstPicture = Skia.Picture.MakePicture(null)!;
55
+ nativeDrawOnscreen(nativeId, sharedRecorder, firstPicture);
66
56
  })();
57
+ // Animate
67
58
  if (sharedValues.length > 0) {
68
59
  this.mapperId = Rea.startMapper(() => {
69
60
  "worklet";
@@ -27,12 +27,13 @@ export class SkiaSGRoot {
27
27
  public Skia: Skia,
28
28
  nativeId = -1
29
29
  ) {
30
+ const strictMode = false;
30
31
  this.container = createContainer(Skia, nativeId);
31
32
  this.root = skiaReconciler.createContainer(
32
33
  this.container,
33
34
  0,
34
35
  null,
35
- true,
36
+ strictMode,
36
37
  null,
37
38
  "",
38
39
  console.error,
@@ -48,7 +49,6 @@ export class SkiaSGRoot {
48
49
  private updateContainer(element: ReactNode) {
49
50
  return new Promise((resolve) => {
50
51
  skiaReconciler.updateContainer(element, this.root, null, () => {
51
- debug("updateContainer");
52
52
  resolve(true);
53
53
  });
54
54
  });
@@ -5,6 +5,7 @@ export interface NativeProps extends ViewProps {
5
5
  debug?: boolean;
6
6
  opaque?: boolean;
7
7
  colorSpace?: string;
8
+ coldStart?: boolean;
8
9
  }
9
10
 
10
11
  // eslint-disable-next-line import/no-default-export
@@ -11,6 +11,7 @@ const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
11
11
 
12
12
  interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
13
13
  mode?: "default" | "continuous";
14
+ coldStart?: boolean;
14
15
  }
15
16
 
16
17
  export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
@@ -82,13 +83,14 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
82
83
  }
83
84
 
84
85
  render() {
85
- const { mode, debug = false, opaque = false, ...viewProps } = this.props;
86
+ const { mode, debug = false, opaque = false, coldStart = false, ...viewProps } = this.props;
86
87
  return (
87
88
  <NativeSkiaPictureView
88
89
  collapsable={false}
89
90
  nativeID={`${this._nativeId}`}
90
91
  debug={debug}
91
92
  opaque={opaque}
93
+ coldStart={coldStart}
92
94
  {...viewProps}
93
95
  />
94
96
  );
@@ -16,6 +16,18 @@ import type { ISkiaViewApiWeb } from "../specs/NativeSkiaModule.web";
16
16
  import type { SkiaPictureViewNativeProps } from "./types";
17
17
  import { SkiaViewNativeId } from "./SkiaViewNativeId";
18
18
 
19
+ const dp2Pixel = (pd: number, rect?: SkRect) => {
20
+ if (!rect) {
21
+ return undefined;
22
+ }
23
+ return {
24
+ x: rect.x * pd,
25
+ y: rect.y * pd,
26
+ width: rect.width * pd,
27
+ height: rect.height * pd,
28
+ };
29
+ };
30
+
19
31
  interface Renderer {
20
32
  onResize(): void;
21
33
  draw(picture: SkPicture): void;
@@ -41,7 +53,7 @@ class WebGLRenderer implements Renderer {
41
53
  canvas!.clear(CanvasKit.TRANSPARENT);
42
54
  this.draw(picture);
43
55
  this.surface.ref.flush();
44
- return this.surface.makeImageSnapshot(rect);
56
+ return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
45
57
  }
46
58
 
47
59
  onResize() {
@@ -187,7 +199,7 @@ class StaticWebGLRenderer implements Renderer {
187
199
  const { surface, tempCanvas } = renderResult;
188
200
 
189
201
  try {
190
- this.cachedImage = surface.makeImageSnapshot(rect);
202
+ this.cachedImage = surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
191
203
  } catch (error) {
192
204
  console.error("Error creating image snapshot:", error);
193
205
  } finally {