@shopify/react-native-skia 0.1.175 → 0.1.178

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 (112) hide show
  1. package/android/CMakeLists.txt +2 -0
  2. package/android/build.gradle +2 -1
  3. package/cpp/jsi/JsiHostObject.cpp +13 -7
  4. package/cpp/jsi/JsiHostObject.h +3 -1
  5. package/cpp/jsi/RuntimeAwareCache.cpp +9 -0
  6. package/cpp/jsi/RuntimeAwareCache.h +101 -0
  7. package/cpp/jsi/RuntimeLifecycleMonitor.cpp +57 -0
  8. package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
  9. package/cpp/rnskia/RNSkJsView.cpp +1 -1
  10. package/cpp/rnskia/RNSkManager.cpp +4 -0
  11. package/cpp/rnskia/dom/base/JsiDomNode.h +22 -2
  12. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +12 -8
  13. package/lib/commonjs/external/reanimated/index.d.ts +1 -0
  14. package/lib/commonjs/external/reanimated/index.js +13 -0
  15. package/lib/commonjs/external/reanimated/index.js.map +1 -1
  16. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +8 -0
  17. package/lib/commonjs/external/reanimated/moduleWrapper.js +72 -0
  18. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -0
  19. package/lib/commonjs/external/reanimated/renderHelpers.d.ts +5 -0
  20. package/lib/commonjs/external/reanimated/renderHelpers.js +85 -0
  21. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -0
  22. package/lib/commonjs/external/reanimated/useSharedValueEffect.d.ts +2 -5
  23. package/lib/commonjs/external/reanimated/useSharedValueEffect.js +10 -25
  24. package/lib/commonjs/external/reanimated/useSharedValueEffect.js.map +1 -1
  25. package/lib/commonjs/headless/index.d.ts +3 -0
  26. package/lib/commonjs/headless/index.js +57 -0
  27. package/lib/commonjs/headless/index.js.map +1 -0
  28. package/lib/commonjs/mock/index.d.ts +1 -2
  29. package/lib/commonjs/mock/index.js +0 -4
  30. package/lib/commonjs/mock/index.js.map +1 -1
  31. package/lib/commonjs/renderer/Canvas.js +7 -1
  32. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  33. package/lib/commonjs/renderer/Container.d.ts +2 -1
  34. package/lib/commonjs/renderer/Container.js +2 -0
  35. package/lib/commonjs/renderer/Container.js.map +1 -1
  36. package/lib/commonjs/renderer/HostConfig.js +6 -4
  37. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  38. package/lib/commonjs/renderer/Reconciler.d.ts +1 -1
  39. package/lib/commonjs/renderer/Reconciler.js +2 -1
  40. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  41. package/lib/commonjs/renderer/processors/Animations/Animations.d.ts +4 -1
  42. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  43. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +8 -1
  44. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  45. package/lib/module/external/reanimated/index.d.ts +1 -0
  46. package/lib/module/external/reanimated/index.js +1 -0
  47. package/lib/module/external/reanimated/index.js.map +1 -1
  48. package/lib/module/external/reanimated/moduleWrapper.d.ts +8 -0
  49. package/lib/module/external/reanimated/moduleWrapper.js +51 -0
  50. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -0
  51. package/lib/module/external/reanimated/renderHelpers.d.ts +5 -0
  52. package/lib/module/external/reanimated/renderHelpers.js +76 -0
  53. package/lib/module/external/reanimated/renderHelpers.js.map +1 -0
  54. package/lib/module/external/reanimated/useSharedValueEffect.d.ts +2 -5
  55. package/lib/module/external/reanimated/useSharedValueEffect.js +7 -22
  56. package/lib/module/external/reanimated/useSharedValueEffect.js.map +1 -1
  57. package/lib/module/headless/index.d.ts +3 -0
  58. package/lib/module/headless/index.js +29 -0
  59. package/lib/module/headless/index.js.map +1 -0
  60. package/lib/module/mock/index.d.ts +1 -2
  61. package/lib/module/mock/index.js +0 -3
  62. package/lib/module/mock/index.js.map +1 -1
  63. package/lib/module/renderer/Canvas.js +7 -1
  64. package/lib/module/renderer/Canvas.js.map +1 -1
  65. package/lib/module/renderer/Container.d.ts +2 -1
  66. package/lib/module/renderer/Container.js +2 -0
  67. package/lib/module/renderer/Container.js.map +1 -1
  68. package/lib/module/renderer/HostConfig.js +5 -4
  69. package/lib/module/renderer/HostConfig.js.map +1 -1
  70. package/lib/module/renderer/Reconciler.d.ts +1 -1
  71. package/lib/module/renderer/Reconciler.js +2 -1
  72. package/lib/module/renderer/Reconciler.js.map +1 -1
  73. package/lib/module/renderer/processors/Animations/Animations.d.ts +4 -1
  74. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  75. package/lib/module/skia/web/JsiSkSurfaceFactory.js +8 -1
  76. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  77. package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
  78. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +8 -0
  79. package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +5 -0
  80. package/lib/typescript/src/external/reanimated/useSharedValueEffect.d.ts +2 -5
  81. package/lib/typescript/src/headless/index.d.ts +3 -0
  82. package/lib/typescript/src/mock/index.d.ts +1 -2
  83. package/lib/typescript/src/renderer/Container.d.ts +2 -1
  84. package/lib/typescript/src/renderer/Reconciler.d.ts +1 -1
  85. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +4 -1
  86. package/libs/ios/libskia.xcframework/Info.plist +5 -5
  87. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  88. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  89. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  90. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  91. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  92. package/libs/ios/libsksg.xcframework/Info.plist +5 -5
  93. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  94. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  95. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  96. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  97. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  98. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  99. package/package.json +1 -1
  100. package/react-native-skia.podspec +7 -26
  101. package/src/external/reanimated/index.ts +1 -0
  102. package/src/external/reanimated/moduleWrapper.ts +62 -0
  103. package/src/external/reanimated/renderHelpers.ts +74 -0
  104. package/src/external/reanimated/useSharedValueEffect.ts +17 -23
  105. package/src/headless/index.ts +31 -0
  106. package/src/mock/index.ts +0 -5
  107. package/src/renderer/Canvas.tsx +6 -2
  108. package/src/renderer/Container.tsx +2 -1
  109. package/src/renderer/HostConfig.ts +8 -2
  110. package/src/renderer/Reconciler.tsx +3 -2
  111. package/src/renderer/processors/Animations/Animations.ts +9 -1
  112. package/src/skia/web/JsiSkSurfaceFactory.ts +6 -3
@@ -1 +1 @@
1
- {"version":3,"names":["Host","JsiSkSurface","JsiSkSurfaceFactory","constructor","CanvasKit","Make","width","height","surface","MakeSurface","MakeOffscreen","OC","globalThis","OffscreenCanvas","undefined","offscreen","MakeWebGLCanvasSurface"],"sources":["JsiSkSurfaceFactory.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SurfaceFactory } from \"../types\";\n\nimport { Host } from \"./Host\";\nimport { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkSurfaceFactory extends Host implements SurfaceFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n Make(width: number, height: number) {\n const surface = this.CanvasKit.MakeSurface(width, height);\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n\n MakeOffscreen(width: number, height: number) {\n // OffscreenCanvas may be unvailable in some environments.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const OC = (globalThis as any).OffscreenCanvas;\n let surface: Surface | null;\n if (OC === undefined) {\n surface = this.CanvasKit.MakeSurface(width, height);\n } else {\n const offscreen = new OC(width, height);\n surface = this.CanvasKit.MakeWebGLCanvasSurface(\n offscreen as unknown as HTMLCanvasElement\n );\n }\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n}\n"],"mappings":"AAIA,SAASA,IAAT,QAAqB,QAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,OAAO,MAAMC,mBAAN,SAAkCF,IAAlC,CAAiE;EACtEG,WAAW,CAACC,SAAD,EAAuB;IAChC,MAAMA,SAAN;EACD;;EAEDC,IAAI,CAACC,KAAD,EAAgBC,MAAhB,EAAgC;IAClC,MAAMC,OAAO,GAAG,KAAKJ,SAAL,CAAeK,WAAf,CAA2BH,KAA3B,EAAkCC,MAAlC,CAAhB;;IACA,IAAI,CAACC,OAAL,EAAc;MACZ,OAAO,IAAP;IACD;;IACD,OAAO,IAAIP,YAAJ,CAAiB,KAAKG,SAAtB,EAAiCI,OAAjC,CAAP;EACD;;EAEDE,aAAa,CAACJ,KAAD,EAAgBC,MAAhB,EAAgC;IAC3C;IACA;IACA,MAAMI,EAAE,GAAIC,UAAD,CAAoBC,eAA/B;IACA,IAAIL,OAAJ;;IACA,IAAIG,EAAE,KAAKG,SAAX,EAAsB;MACpBN,OAAO,GAAG,KAAKJ,SAAL,CAAeK,WAAf,CAA2BH,KAA3B,EAAkCC,MAAlC,CAAV;IACD,CAFD,MAEO;MACL,MAAMQ,SAAS,GAAG,IAAIJ,EAAJ,CAAOL,KAAP,EAAcC,MAAd,CAAlB;MACAC,OAAO,GAAG,KAAKJ,SAAL,CAAeY,sBAAf,CACRD,SADQ,CAAV;IAGD;;IACD,IAAI,CAACP,OAAL,EAAc;MACZ,OAAO,IAAP;IACD;;IACD,OAAO,IAAIP,YAAJ,CAAiB,KAAKG,SAAtB,EAAiCI,OAAjC,CAAP;EACD;;AA9BqE"}
1
+ {"version":3,"names":["Host","JsiSkSurface","JsiSkSurfaceFactory","constructor","CanvasKit","Make","width","height","surface","MakeSurface","MakeOffscreen","OC","globalThis","OffscreenCanvas","undefined","offscreen","webglContext","GetWebGLContext","grContext","MakeWebGLContext","Error","MakeRenderTarget"],"sources":["JsiSkSurfaceFactory.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SurfaceFactory } from \"../types\";\n\nimport { Host } from \"./Host\";\nimport { JsiSkSurface } from \"./JsiSkSurface\";\n\nexport class JsiSkSurfaceFactory extends Host implements SurfaceFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n Make(width: number, height: number) {\n const surface = this.CanvasKit.MakeSurface(width, height);\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n\n MakeOffscreen(width: number, height: number) {\n // OffscreenCanvas may be unvailable in some environments.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const OC = (globalThis as any).OffscreenCanvas;\n let surface: Surface | null;\n if (OC === undefined) {\n surface = this.CanvasKit.MakeSurface(width, height);\n } else {\n const offscreen = new OC(width, height);\n const webglContext = this.CanvasKit.GetWebGLContext(offscreen);\n const grContext = this.CanvasKit.MakeWebGLContext(webglContext);\n if (!grContext) {\n throw new Error(\"Could not make a graphics context\");\n }\n surface = this.CanvasKit.MakeRenderTarget(grContext, width, height);\n }\n if (!surface) {\n return null;\n }\n return new JsiSkSurface(this.CanvasKit, surface);\n }\n}\n"],"mappings":"AAIA,SAASA,IAAT,QAAqB,QAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AAEA,OAAO,MAAMC,mBAAN,SAAkCF,IAAlC,CAAiE;EACtEG,WAAW,CAACC,SAAD,EAAuB;IAChC,MAAMA,SAAN;EACD;;EAEDC,IAAI,CAACC,KAAD,EAAgBC,MAAhB,EAAgC;IAClC,MAAMC,OAAO,GAAG,KAAKJ,SAAL,CAAeK,WAAf,CAA2BH,KAA3B,EAAkCC,MAAlC,CAAhB;;IACA,IAAI,CAACC,OAAL,EAAc;MACZ,OAAO,IAAP;IACD;;IACD,OAAO,IAAIP,YAAJ,CAAiB,KAAKG,SAAtB,EAAiCI,OAAjC,CAAP;EACD;;EAEDE,aAAa,CAACJ,KAAD,EAAgBC,MAAhB,EAAgC;IAC3C;IACA;IACA,MAAMI,EAAE,GAAIC,UAAD,CAAoBC,eAA/B;IACA,IAAIL,OAAJ;;IACA,IAAIG,EAAE,KAAKG,SAAX,EAAsB;MACpBN,OAAO,GAAG,KAAKJ,SAAL,CAAeK,WAAf,CAA2BH,KAA3B,EAAkCC,MAAlC,CAAV;IACD,CAFD,MAEO;MACL,MAAMQ,SAAS,GAAG,IAAIJ,EAAJ,CAAOL,KAAP,EAAcC,MAAd,CAAlB;MACA,MAAMS,YAAY,GAAG,KAAKZ,SAAL,CAAea,eAAf,CAA+BF,SAA/B,CAArB;MACA,MAAMG,SAAS,GAAG,KAAKd,SAAL,CAAee,gBAAf,CAAgCH,YAAhC,CAAlB;;MACA,IAAI,CAACE,SAAL,EAAgB;QACd,MAAM,IAAIE,KAAJ,CAAU,mCAAV,CAAN;MACD;;MACDZ,OAAO,GAAG,KAAKJ,SAAL,CAAeiB,gBAAf,CAAgCH,SAAhC,EAA2CZ,KAA3C,EAAkDC,MAAlD,CAAV;IACD;;IACD,IAAI,CAACC,OAAL,EAAc;MACZ,OAAO,IAAP;IACD;;IACD,OAAO,IAAIP,YAAJ,CAAiB,KAAKG,SAAtB,EAAiCI,OAAjC,CAAP;EACD;;AAjCqE"}
@@ -1 +1,2 @@
1
1
  export * from "./useSharedValueEffect";
2
+ export * from "./renderHelpers";
@@ -0,0 +1,8 @@
1
+ import type { SharedValueType } from "../../renderer/processors/Animations";
2
+ export declare const HAS_REANIMATED: boolean;
3
+ export declare function throwOnIncompatibleReanimatedVersion(): void;
4
+ export declare const useSharedValue: any;
5
+ export declare const startMapper: any;
6
+ export declare const stopMapper: any;
7
+ export declare const runOnJS: any;
8
+ export declare const isSharedValue: <T>(value: unknown) => value is SharedValueType<T>;
@@ -0,0 +1,5 @@
1
+ import type { Container } from "../../renderer/Container";
2
+ import type { AnimatedProps } from "../../renderer/processors";
3
+ import type { Node } from "../../dom/types";
4
+ export declare function extractReanimatedProps(props: AnimatedProps<any>): AnimatedProps<any, never>[];
5
+ export declare function bindReanimatedProps(container: Container, node: Node<any>, reanimatedProps: AnimatedProps<any>): void;
@@ -1,11 +1,8 @@
1
- declare type SharedValueTypeWrapper<T = number> = {
2
- value: T;
3
- };
1
+ import type { SharedValueType } from "../../renderer/processors/Animations";
4
2
  /**
5
3
  * Connects a shared value from reanimated to a SkiaView or Canvas
6
4
  * so whenever the shared value changes the SkiaView will redraw.
7
5
  * @param cb Callback that will be called whenever the shared value changes.
8
6
  * @param values One or more shared values to listen for.
9
7
  */
10
- export declare const useSharedValueEffect: <T = number>(cb: () => void, value: SharedValueTypeWrapper<T>, ...values: SharedValueTypeWrapper<T>[]) => void;
11
- export {};
8
+ export declare const useSharedValueEffect: <T = number>(cb: () => void, value: SharedValueType<T>, ...values: SharedValueType<T>[]) => void;
@@ -0,0 +1,3 @@
1
+ import type { ReactNode } from "react";
2
+ export * from "../renderer/components";
3
+ export declare const draw: (element: ReactNode, width: number, height: number) => any;
@@ -1,6 +1,5 @@
1
1
  import type { Skia as SkiaApi } from "../skia/types";
2
2
  import type * as SkiaExports from "../skia";
3
- import type * as ExternalExports from "../external";
4
3
  import type * as ValueExports from "../values";
5
4
  import type * as AnimationExports from "../animation";
6
5
  import { ShaderLib } from "../renderer/components/shaders/ShaderLib";
@@ -9,7 +8,7 @@ export declare const vec: (x?: number, y?: number) => {
9
8
  x: number;
10
9
  y: number;
11
10
  };
12
- export declare const Mock: typeof SkiaExports & typeof ExternalExports & typeof ValueExports & typeof AnimationExports & {
11
+ export declare const Mock: typeof SkiaExports & typeof ValueExports & typeof AnimationExports & {
13
12
  createDrawing: () => any;
14
13
  createDeclaration: () => any;
15
14
  ShaderLib: typeof ShaderLib;
@@ -4,9 +4,10 @@ import type { DependencyManager } from "./DependencyManager";
4
4
  export declare class Container {
5
5
  depMgr: DependencyManager;
6
6
  redraw: () => void;
7
+ getNativeId: () => number;
7
8
  private _root;
8
9
  Sk: SkDOM;
9
- constructor(Skia: Skia, depMgr: DependencyManager, redraw?: () => void);
10
+ constructor(Skia: Skia, depMgr: DependencyManager, redraw?: () => void, getNativeId?: () => number);
10
11
  draw(ctx: DrawingContext): void;
11
12
  get root(): RenderNode<GroupProps>;
12
13
  }
@@ -5,7 +5,7 @@ declare type RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;
5
5
  export declare class SkiaRoot {
6
6
  private root;
7
7
  private container;
8
- constructor(Skia: Skia, registerValues?: RegisterValues, redraw?: () => void);
8
+ constructor(Skia: Skia, registerValues?: RegisterValues, redraw?: () => void, getNativeId?: () => number);
9
9
  render(element: ReactNode): void;
10
10
  unmount(): void;
11
11
  get dom(): import("..").RenderNode<import("..").GroupProps>;
@@ -1,11 +1,14 @@
1
1
  import type { SkiaSelector, SkiaValue } from "../../../values";
2
+ export declare type SharedValueType<T = number> = {
3
+ value: T;
4
+ };
2
5
  export declare const isValue: (value: unknown) => value is SkiaValue<unknown>;
3
6
  export declare const isSelector: <T, R>(value: unknown) => value is {
4
7
  selector: (v: T) => R;
5
8
  value: SkiaValue<T>;
6
9
  };
7
10
  export declare const isAnimated: <T>(props: AnimatedProps<T, never>) => boolean;
8
- export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P>;
11
+ export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P> | SharedValueType<T>;
9
12
  export declare type AnimatedProps<T, O extends keyof T | never = never> = {
10
13
  [K in keyof T]: K extends "children" ? T[K] : K extends O ? T[K] : AnimatedProp<T[K]>;
11
14
  };
@@ -6,32 +6,32 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_arm64e_x86_64-simulator</string>
9
+ <string>ios-arm64_arm64e</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>libskia.a</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
15
  <string>arm64e</string>
16
- <string>x86_64</string>
17
16
  </array>
18
17
  <key>SupportedPlatform</key>
19
18
  <string>ios</string>
20
- <key>SupportedPlatformVariant</key>
21
- <string>simulator</string>
22
19
  </dict>
23
20
  <dict>
24
21
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_arm64e</string>
22
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
26
23
  <key>LibraryPath</key>
27
24
  <string>libskia.a</string>
28
25
  <key>SupportedArchitectures</key>
29
26
  <array>
30
27
  <string>arm64</string>
31
28
  <string>arm64e</string>
29
+ <string>x86_64</string>
32
30
  </array>
33
31
  <key>SupportedPlatform</key>
34
32
  <string>ios</string>
33
+ <key>SupportedPlatformVariant</key>
34
+ <string>simulator</string>
35
35
  </dict>
36
36
  </array>
37
37
  <key>CFBundlePackageType</key>
@@ -6,32 +6,32 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_arm64e_x86_64-simulator</string>
9
+ <string>ios-arm64_arm64e</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>libskottie.a</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
15
  <string>arm64e</string>
16
- <string>x86_64</string>
17
16
  </array>
18
17
  <key>SupportedPlatform</key>
19
18
  <string>ios</string>
20
- <key>SupportedPlatformVariant</key>
21
- <string>simulator</string>
22
19
  </dict>
23
20
  <dict>
24
21
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_arm64e</string>
22
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
26
23
  <key>LibraryPath</key>
27
24
  <string>libskottie.a</string>
28
25
  <key>SupportedArchitectures</key>
29
26
  <array>
30
27
  <string>arm64</string>
31
28
  <string>arm64e</string>
29
+ <string>x86_64</string>
32
30
  </array>
33
31
  <key>SupportedPlatform</key>
34
32
  <string>ios</string>
33
+ <key>SupportedPlatformVariant</key>
34
+ <string>simulator</string>
35
35
  </dict>
36
36
  </array>
37
37
  <key>CFBundlePackageType</key>
@@ -6,32 +6,32 @@
6
6
  <array>
7
7
  <dict>
8
8
  <key>LibraryIdentifier</key>
9
- <string>ios-arm64_arm64e</string>
9
+ <string>ios-arm64_arm64e_x86_64-simulator</string>
10
10
  <key>LibraryPath</key>
11
11
  <string>libsksg.a</string>
12
12
  <key>SupportedArchitectures</key>
13
13
  <array>
14
14
  <string>arm64</string>
15
15
  <string>arm64e</string>
16
+ <string>x86_64</string>
16
17
  </array>
17
18
  <key>SupportedPlatform</key>
18
19
  <string>ios</string>
20
+ <key>SupportedPlatformVariant</key>
21
+ <string>simulator</string>
19
22
  </dict>
20
23
  <dict>
21
24
  <key>LibraryIdentifier</key>
22
- <string>ios-arm64_arm64e_x86_64-simulator</string>
25
+ <string>ios-arm64_arm64e</string>
23
26
  <key>LibraryPath</key>
24
27
  <string>libsksg.a</string>
25
28
  <key>SupportedArchitectures</key>
26
29
  <array>
27
30
  <string>arm64</string>
28
31
  <string>arm64e</string>
29
- <string>x86_64</string>
30
32
  </array>
31
33
  <key>SupportedPlatform</key>
32
34
  <string>ios</string>
33
- <key>SupportedPlatformVariant</key>
34
- <string>simulator</string>
35
35
  </dict>
36
36
  </array>
37
37
  <key>CFBundlePackageType</key>
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.175",
10
+ "version": "0.1.178",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -24,7 +24,12 @@ Pod::Spec.new do |s|
24
24
  s.pod_target_xcconfig = {
25
25
  'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) SK_GL=1 SK_METAL=1',
26
26
  'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
27
- 'DEFINES_MODULE' => 'YES'
27
+ 'DEFINES_MODULE' => 'YES',
28
+ "HEADER_SEARCH_PATHS" => '"$(PODS_ROOT)/../../node_modules/@shopify/react-native-skia/cpp/" ' +
29
+ '"$(PODS_ROOT)/../../node_modules/@shopify/react-native-skia/cpp/api/" ' +
30
+ '"$(PODS_ROOT)/../../node_modules/@shopify/react-native-skia/cpp/rnskia/" ' +
31
+ '"$(PODS_ROOT)/../../node_modules/@shopify/react-native-skia/cpp/rnskia/dom/" ' +
32
+ '"$(PODS_ROOT)/../../node_modules/@shopify/react-native-skia/cpp/skia/"'
28
33
  }
29
34
 
30
35
  s.frameworks = 'GLKit', 'MetalKit'
@@ -40,33 +45,9 @@ Pod::Spec.new do |s|
40
45
  # All iOS cpp/h files
41
46
  s.source_files = [
42
47
  "ios/**/*.{h,c,cc,cpp,m,mm,swift}",
48
+ "cpp/**/*.{h,cpp}"
43
49
  ]
44
50
 
45
- s.subspec 'SkiaHeaders' do |ss|
46
- ss.header_mappings_dir = 'cpp/skia'
47
- ss.source_files = "cpp/skia/**/*.{h,cpp}"
48
- end
49
-
50
- s.subspec 'Utils' do |ss|
51
- ss.header_mappings_dir = 'cpp/utils'
52
- ss.source_files = "cpp/utils/**/*.{h,cpp}"
53
- end
54
-
55
- s.subspec 'Jsi' do |ss|
56
- ss.header_mappings_dir = 'cpp/jsi'
57
- ss.source_files = "cpp/jsi/**/*.{h,cpp}"
58
- end
59
-
60
- s.subspec 'Api' do |ss|
61
- ss.header_mappings_dir = 'cpp/api'
62
- ss.source_files = "cpp/api/**/*.{h,cpp}"
63
- end
64
-
65
- s.subspec 'RNSkia' do |ss|
66
- ss.header_mappings_dir = 'cpp/rnskia'
67
- ss.source_files = "cpp/rnskia/**/*.{h,cpp}"
68
- end
69
-
70
51
  s.dependency "React"
71
52
  s.dependency "React-callinvoker"
72
53
  s.dependency "React-Core"
@@ -1 +1,2 @@
1
1
  export * from "./useSharedValueEffect";
2
+ export * from "./renderHelpers";
@@ -0,0 +1,62 @@
1
+ import { useMemo } from "react";
2
+
3
+ import type { SharedValueType } from "../../renderer/processors/Animations";
4
+
5
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
+ let Reanimated: any;
7
+
8
+ try {
9
+ Reanimated = require("react-native-reanimated");
10
+ } catch (e) {
11
+ // Ignore
12
+ }
13
+
14
+ export const HAS_REANIMATED = !!Reanimated;
15
+
16
+ function throwOnMissingReanimated() {
17
+ throw new Error(
18
+ "Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
19
+ react-naitve-skia's integration layer API."
20
+ );
21
+ }
22
+
23
+ let ReanimatedVersionTested = false;
24
+
25
+ export function throwOnIncompatibleReanimatedVersion() {
26
+ if (ReanimatedVersionTested) {
27
+ // we avoid testing version more than once as it won't change and we throw
28
+ // an error when version is incompatible
29
+ return;
30
+ }
31
+ ReanimatedVersionTested = true;
32
+ const reanimatedVersion =
33
+ // eslint-disable-next-line import/extensions
34
+ require("react-native-reanimated/package.json").version;
35
+ // The first compatible version is 3.0.0 but we need to exclude 3.0.0 pre-releases
36
+ // as they have limited support for the used API.
37
+ if (
38
+ !reanimatedVersion ||
39
+ reanimatedVersion < "3.0.0" ||
40
+ reanimatedVersion.includes("3.0.0-")
41
+ ) {
42
+ throw new Error(
43
+ `Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`
44
+ );
45
+ }
46
+ }
47
+
48
+ export const useSharedValue =
49
+ Reanimated?.useSharedValue ||
50
+ ((value: number) => useMemo(() => ({ value }), [value]));
51
+
52
+ export const startMapper = Reanimated?.startMapper || throwOnMissingReanimated;
53
+ export const stopMapper = Reanimated?.stopMapper || throwOnMissingReanimated;
54
+ export const runOnJS = Reanimated?.runOnJS || throwOnMissingReanimated;
55
+ export const isSharedValue = <T>(
56
+ value: unknown
57
+ ): value is SharedValueType<T> => {
58
+ if (!Reanimated) {
59
+ throwOnMissingReanimated();
60
+ }
61
+ return !!value && Reanimated.isSharedValue(value);
62
+ };
@@ -0,0 +1,74 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable reanimated/js-function-in-worklet */
3
+ import type { Container } from "../../renderer/Container";
4
+ import type { AnimatedProps } from "../../renderer/processors";
5
+ import type { Node } from "../../dom/types";
6
+
7
+ import {
8
+ startMapper,
9
+ stopMapper,
10
+ isSharedValue,
11
+ throwOnIncompatibleReanimatedVersion,
12
+ HAS_REANIMATED,
13
+ } from "./moduleWrapper";
14
+
15
+ const _bindings = new WeakMap<Node<unknown>, unknown>();
16
+
17
+ export function extractReanimatedProps(props: AnimatedProps<any>) {
18
+ if (!HAS_REANIMATED) {
19
+ return [props, {}];
20
+ }
21
+ const reanimatedProps = {} as AnimatedProps<any>;
22
+ const otherProps = {} as AnimatedProps<any>;
23
+ for (const propName in props) {
24
+ if (propName === "children") {
25
+ continue;
26
+ }
27
+ const propValue = props[propName];
28
+ if (isSharedValue(propValue)) {
29
+ reanimatedProps[propName] = propValue;
30
+ otherProps[propName] = propValue.value;
31
+ } else {
32
+ otherProps[propName] = propValue;
33
+ }
34
+ }
35
+ return [otherProps, reanimatedProps];
36
+ }
37
+
38
+ export function bindReanimatedProps(
39
+ container: Container,
40
+ node: Node<any>,
41
+ reanimatedProps: AnimatedProps<any>
42
+ ) {
43
+ if (!HAS_REANIMATED) {
44
+ return;
45
+ }
46
+ if (__DEV__) {
47
+ throwOnIncompatibleReanimatedVersion();
48
+ }
49
+ const sharedValues = Object.values(reanimatedProps);
50
+ const previousMapperId = _bindings.get(node);
51
+ if (previousMapperId !== undefined) {
52
+ stopMapper(previousMapperId);
53
+ }
54
+ if (sharedValues.length > 0) {
55
+ const viewId = container.getNativeId();
56
+ const { SkiaViewApi } = global;
57
+ const mapperId = startMapper(() => {
58
+ "worklet";
59
+ for (const propName in reanimatedProps) {
60
+ node && node.setProp(propName, reanimatedProps[propName].value);
61
+ }
62
+ // On React Native we use the SkiaViewApi to redraw because it can
63
+ // run on the worklet thread (container.redraw can't)
64
+ // if SkiaViewApi is undefined, we are on web and container.redraw()
65
+ // can safely be invoked
66
+ if (SkiaViewApi) {
67
+ SkiaViewApi.requestRedraw(viewId);
68
+ } else {
69
+ container.redraw();
70
+ }
71
+ }, sharedValues);
72
+ _bindings.set(node, mapperId);
73
+ }
74
+ }
@@ -1,22 +1,14 @@
1
- import { useEffect, useMemo } from "react";
1
+ import { useEffect } from "react";
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
- let Reanimated: any;
3
+ import type { SharedValueType } from "../../renderer/processors/Animations";
5
4
 
6
- try {
7
- Reanimated = require("react-native-reanimated");
8
- } catch (e) {
9
- // Ignore
10
- }
11
-
12
- type SharedValueTypeWrapper<T = number> = {
13
- value: T;
14
- };
15
-
16
- const useSharedValueWrapper =
17
- Reanimated?.useSharedValue === undefined
18
- ? (value: number) => useMemo(() => ({ value }), [value])
19
- : Reanimated.useSharedValue;
5
+ import {
6
+ HAS_REANIMATED,
7
+ useSharedValue,
8
+ runOnJS,
9
+ startMapper,
10
+ stopMapper,
11
+ } from "./moduleWrapper";
20
12
 
21
13
  /**
22
14
  * Connects a shared value from reanimated to a SkiaView or Canvas
@@ -26,19 +18,21 @@ const useSharedValueWrapper =
26
18
  */
27
19
  export const useSharedValueEffect = <T = number>(
28
20
  cb: () => void,
29
- value: SharedValueTypeWrapper<T>,
30
- ...values: SharedValueTypeWrapper<T>[]
21
+ value: SharedValueType<T>,
22
+ ...values: SharedValueType<T>[]
31
23
  ) => {
32
- const input = useSharedValueWrapper(0);
24
+ console.warn(
25
+ `useSharedValueEffect() is now deprecated, you can use Reanimated values directly.
26
+ Learn more at https://shopify.github.io/react-native-skia/.`
27
+ );
28
+ const input = useSharedValue(0);
33
29
 
34
30
  useEffect(() => {
35
- if (!Reanimated) {
31
+ if (!HAS_REANIMATED) {
36
32
  console.warn(
37
33
  "Reanimated was not found and the useSharedValueEffect hook will have no effect."
38
34
  );
39
35
  } else {
40
- const { runOnJS, startMapper, stopMapper } = Reanimated;
41
-
42
36
  // Start a mapper in Reanimated
43
37
  const mapperId = startMapper(
44
38
  () => {
@@ -0,0 +1,31 @@
1
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
+ // @ts-ignore
3
+ import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
4
+ import type { ReactNode } from "react";
5
+
6
+ import { JsiSkApi } from "../skia/web";
7
+ import { SkiaRoot } from "../renderer/Reconciler";
8
+ import { JsiDrawingContext } from "../dom/types";
9
+
10
+ export * from "../renderer/components";
11
+
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ let Skia: any;
14
+
15
+ export const draw = (element: ReactNode, width: number, height: number) => {
16
+ if (!Skia) {
17
+ Skia = JsiSkApi(CanvasKit);
18
+ }
19
+ const surface = Skia.Surface.MakeOffscreen(width, height);
20
+ if (surface === null) {
21
+ throw new Error("Couldn't create surface!");
22
+ }
23
+ const root = new SkiaRoot(Skia);
24
+ root.render(element);
25
+ const canvas = surface.getCanvas();
26
+ const ctx = new JsiDrawingContext(Skia, canvas);
27
+ root.dom.render(ctx);
28
+ surface.flush();
29
+ const image = surface.makeImageSnapshot();
30
+ return image;
31
+ };
package/src/mock/index.ts CHANGED
@@ -6,10 +6,8 @@ import * as ValuesHooks from "../values/hooks";
6
6
  import { Selector } from "../values/selector";
7
7
  import * as BaseSkia from "../skia/types";
8
8
  import type * as SkiaExports from "../skia";
9
- import type * as ExternalExports from "../external";
10
9
  import type * as ValueExports from "../values";
11
10
  import type * as AnimationExports from "../animation";
12
- import { useSharedValueEffect } from "../external/reanimated/useSharedValueEffect";
13
11
  import * as timingFunctions from "../animation/timing";
14
12
  import * as springFunctions from "../animation/spring";
15
13
  import * as decayFunctions from "../animation/decay";
@@ -35,7 +33,6 @@ export const Skia: SkiaApi = new Stub() as any;
35
33
  export const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });
36
34
 
37
35
  export const Mock: typeof SkiaExports &
38
- typeof ExternalExports &
39
36
  typeof ValueExports &
40
37
  typeof AnimationExports & {
41
38
  createDrawing: () => any;
@@ -82,8 +79,6 @@ export const Mock: typeof SkiaExports &
82
79
  bottomRight: Noop,
83
80
  center: Noop,
84
81
  processTransform2d: Noop,
85
- // ExternalExports
86
- useSharedValueEffect,
87
82
  // ValueExports
88
83
  ...Values,
89
84
  ...ValuesHooks,
@@ -37,6 +37,10 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
37
37
  const redraw = useCallback(() => {
38
38
  innerRef.current?.redraw();
39
39
  }, [innerRef]);
40
+ const getNativeId = useCallback(() => {
41
+ const id = innerRef.current?.nativeId ?? -1;
42
+ return id;
43
+ }, [innerRef]);
40
44
 
41
45
  const registerValues = useCallback(
42
46
  (values: Array<SkiaValue<unknown>>) => {
@@ -48,8 +52,8 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
48
52
  [ref]
49
53
  );
50
54
  const root = useMemo(
51
- () => new SkiaRoot(Skia, registerValues, redraw),
52
- [redraw, registerValues]
55
+ () => new SkiaRoot(Skia, registerValues, redraw, getNativeId),
56
+ [redraw, registerValues, getNativeId]
53
57
  );
54
58
 
55
59
  // Render effect
@@ -15,7 +15,8 @@ export class Container {
15
15
  constructor(
16
16
  Skia: Skia,
17
17
  public depMgr: DependencyManager,
18
- public redraw: () => void = () => {}
18
+ public redraw: () => void = () => {},
19
+ public getNativeId: () => number = () => 0
19
20
  ) {
20
21
  this.Sk = new JsiSkDOM({ Skia, depMgr });
21
22
  this._root = this.Sk.Group();
@@ -4,6 +4,10 @@ import { DefaultEventPriority } from "react-reconciler/constants";
4
4
 
5
5
  import type { NodeType, Node } from "../dom/types";
6
6
  import type { SkiaValue } from "../values";
7
+ import {
8
+ bindReanimatedProps,
9
+ extractReanimatedProps,
10
+ } from "../external/reanimated";
7
11
 
8
12
  import type { Container } from "./Container";
9
13
  import { createNode } from "./HostComponents";
@@ -121,8 +125,9 @@ export const skHostConfig: SkiaHostConfig = {
121
125
  _internalInstanceHandle
122
126
  ) {
123
127
  debug("createInstance", type);
124
- const props = { ...pristineProps };
128
+ const [props, reanimatedProps] = extractReanimatedProps(pristineProps);
125
129
  const node = createNode(container, type, materialize(props));
130
+ bindReanimatedProps(container, node, reanimatedProps);
126
131
  container.depMgr.subscribeNode(node, props);
127
132
  return node;
128
133
  },
@@ -193,9 +198,10 @@ export const skHostConfig: SkiaHostConfig = {
193
198
  if (shallowEq(prevProps, nextProps)) {
194
199
  return;
195
200
  }
196
- const props = { ...nextProps };
201
+ const [props, reanimatedProps] = extractReanimatedProps(nextProps);
197
202
  updatePayload.depMgr.unsubscribeNode(instance);
198
203
  instance.setProps(materialize(props));
204
+ bindReanimatedProps(updatePayload, instance, reanimatedProps);
199
205
  updatePayload.depMgr.subscribeNode(instance, props);
200
206
  },
201
207