@shopify/react-native-skia 1.2.1 → 1.2.3

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 (115) hide show
  1. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +34 -14
  2. package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +2 -1
  3. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +13 -8
  4. package/cpp/api/JsiSkImageFactory.h +3 -3
  5. package/cpp/rnskia/RNSkPlatformContext.h +3 -3
  6. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +2 -6
  7. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +42 -7
  8. package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +178 -5
  9. package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +10 -13
  10. package/lib/commonjs/external/ModuleProxy.d.ts +10 -0
  11. package/lib/commonjs/external/ModuleProxy.js +36 -0
  12. package/lib/commonjs/external/ModuleProxy.js.map +1 -0
  13. package/lib/commonjs/external/reanimated/ReanimatedProxy.d.ts +3 -0
  14. package/lib/commonjs/external/reanimated/ReanimatedProxy.js +18 -0
  15. package/lib/commonjs/external/reanimated/ReanimatedProxy.js.map +1 -0
  16. package/lib/commonjs/external/reanimated/buffers.js +9 -6
  17. package/lib/commonjs/external/reanimated/buffers.js.map +1 -1
  18. package/lib/commonjs/external/reanimated/interpolators.js +8 -7
  19. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  20. package/lib/commonjs/external/reanimated/renderHelpers.js +27 -11
  21. package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
  22. package/lib/commonjs/external/reanimated/textures.js +4 -3
  23. package/lib/commonjs/external/reanimated/textures.js.map +1 -1
  24. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +6 -6
  25. package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
  26. package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js +6 -5
  27. package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js.map +1 -1
  28. package/lib/commonjs/renderer/Offscreen.js +1 -5
  29. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  30. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +3 -3
  31. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  32. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -3
  33. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  34. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +1 -1
  35. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +1 -1
  36. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
  37. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +0 -2
  38. package/lib/commonjs/specs/NativeSkiaModule.web.js +0 -8
  39. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  40. package/lib/module/external/ModuleProxy.d.ts +10 -0
  41. package/lib/module/external/ModuleProxy.js +28 -0
  42. package/lib/module/external/ModuleProxy.js.map +1 -0
  43. package/lib/module/external/reanimated/ReanimatedProxy.d.ts +3 -0
  44. package/lib/module/external/reanimated/ReanimatedProxy.js +12 -0
  45. package/lib/module/external/reanimated/ReanimatedProxy.js.map +1 -0
  46. package/lib/module/external/reanimated/buffers.js +8 -6
  47. package/lib/module/external/reanimated/buffers.js.map +1 -1
  48. package/lib/module/external/reanimated/interpolators.js +7 -7
  49. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  50. package/lib/module/external/reanimated/renderHelpers.js +26 -11
  51. package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
  52. package/lib/module/external/reanimated/textures.js +3 -3
  53. package/lib/module/external/reanimated/textures.js.map +1 -1
  54. package/lib/module/external/reanimated/useAnimatedImageValue.js +5 -6
  55. package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
  56. package/lib/module/external/reanimated/useDerivedValueOnJS.js +5 -5
  57. package/lib/module/external/reanimated/useDerivedValueOnJS.js.map +1 -1
  58. package/lib/module/renderer/Offscreen.js +1 -5
  59. package/lib/module/renderer/Offscreen.js.map +1 -1
  60. package/lib/module/skia/types/Image/ImageFactory.d.ts +3 -3
  61. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  62. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -3
  63. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  64. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +1 -1
  65. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +1 -1
  66. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
  67. package/lib/module/specs/NativeSkiaModule.web.d.ts +0 -2
  68. package/lib/module/specs/NativeSkiaModule.web.js +0 -3
  69. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  70. package/lib/typescript/src/external/ModuleProxy.d.ts +10 -0
  71. package/lib/typescript/src/external/reanimated/ReanimatedProxy.d.ts +3 -0
  72. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +3 -3
  73. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +3 -3
  74. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +1 -1
  75. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +0 -2
  76. package/libs/ios/libskia.xcframework/Info.plist +5 -5
  77. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  78. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  79. package/libs/ios/libskottie.xcframework/Info.plist +5 -5
  80. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  81. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  82. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  83. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  84. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  85. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  86. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  87. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  88. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  89. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  90. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  91. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  92. package/package.json +1 -1
  93. package/src/external/ModuleProxy.ts +30 -0
  94. package/src/external/reanimated/ReanimatedProxy.ts +18 -0
  95. package/src/external/reanimated/buffers.ts +7 -6
  96. package/src/external/reanimated/interpolators.ts +7 -12
  97. package/src/external/reanimated/renderHelpers.ts +31 -18
  98. package/src/external/reanimated/textures.tsx +3 -3
  99. package/src/external/reanimated/useAnimatedImageValue.ts +5 -10
  100. package/src/external/reanimated/useDerivedValueOnJS.ts +5 -10
  101. package/src/renderer/Offscreen.tsx +1 -7
  102. package/src/skia/types/Image/ImageFactory.ts +3 -3
  103. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +3 -3
  104. package/src/skia/web/JsiSkNativeBufferFactory.ts +1 -1
  105. package/src/specs/NativeSkiaModule.web.ts +0 -4
  106. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDrawViewManagerDelegate.java +0 -34
  107. package/cpp/skia/include/gpu/GrBackendDrawableInfo.h +0 -9
  108. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +0 -15
  109. package/lib/commonjs/external/reanimated/moduleWrapper.js +0 -46
  110. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +0 -1
  111. package/lib/module/external/reanimated/moduleWrapper.d.ts +0 -15
  112. package/lib/module/external/reanimated/moduleWrapper.js +0 -37
  113. package/lib/module/external/reanimated/moduleWrapper.js.map +0 -1
  114. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +0 -15
  115. package/src/external/reanimated/moduleWrapper.ts +0 -83
@@ -15,7 +15,7 @@ export class JsiSkNativeBufferFactory extends Host {
15
15
  ctx.putImageData(imageData, 0, 0);
16
16
  return canvas;
17
17
  }
18
- Release(_platformBuffer) {
18
+ Release(_nativeBuffer) {
19
19
  // it's a noop on Web
20
20
  }
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"names":["Host","JsiSkNativeBufferFactory","constructor","CanvasKit","MakeFromImage","image","info","getImageInfo","uint8ClampedArray","Uint8ClampedArray","readPixels","imageData","ImageData","width","height","canvas","OffscreenCanvas","ctx","getContext","Error","putImageData","Release","_platformBuffer"],"sources":["JsiSkNativeBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport {\n type NativeBuffer,\n type NativeBufferFactory,\n type SkImage,\n} from \"../types\";\n\nimport { Host } from \"./Host\";\n\nexport class JsiSkNativeBufferFactory\n extends Host\n implements NativeBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(image: SkImage): NativeBuffer {\n const info = image.getImageInfo();\n const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);\n const imageData = new ImageData(uint8ClampedArray, info.width, info.height);\n const canvas = new OffscreenCanvas(info.width, info.height);\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get 2d context from canvas\");\n }\n ctx.putImageData(imageData, 0, 0);\n return canvas;\n }\n\n Release(_platformBuffer: NativeBuffer) {\n // it's a noop on Web\n }\n}\n"],"mappings":"AAQA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,OAAO,MAAMC,wBAAwB,SAC3BD,IAAI,CAEd;EACEE,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,KAAc,EAAgB;IAC1C,MAAMC,IAAI,GAAGD,KAAK,CAACE,YAAY,CAAC,CAAC;IACjC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAACJ,KAAK,CAACK,UAAU,CAAC,CAAE,CAAC;IACpE,MAAMC,SAAS,GAAG,IAAIC,SAAS,CAACJ,iBAAiB,EAAEF,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3E,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAACV,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3D,MAAMG,GAAG,GAAGF,MAAM,CAACG,UAAU,CAAC,IAAI,CAAC;IACnC,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;IACzD;IACAF,GAAG,CAACG,YAAY,CAACT,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,OAAOI,MAAM;EACf;EAEAM,OAAOA,CAACC,eAA6B,EAAE;IACrC;EAAA;AAEJ"}
1
+ {"version":3,"names":["Host","JsiSkNativeBufferFactory","constructor","CanvasKit","MakeFromImage","image","info","getImageInfo","uint8ClampedArray","Uint8ClampedArray","readPixels","imageData","ImageData","width","height","canvas","OffscreenCanvas","ctx","getContext","Error","putImageData","Release","_nativeBuffer"],"sources":["JsiSkNativeBufferFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport {\n type NativeBuffer,\n type NativeBufferFactory,\n type SkImage,\n} from \"../types\";\n\nimport { Host } from \"./Host\";\n\nexport class JsiSkNativeBufferFactory\n extends Host\n implements NativeBufferFactory\n{\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeFromImage(image: SkImage): NativeBuffer {\n const info = image.getImageInfo();\n const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);\n const imageData = new ImageData(uint8ClampedArray, info.width, info.height);\n const canvas = new OffscreenCanvas(info.width, info.height);\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) {\n throw new Error(\"Failed to get 2d context from canvas\");\n }\n ctx.putImageData(imageData, 0, 0);\n return canvas;\n }\n\n Release(_nativeBuffer: NativeBuffer) {\n // it's a noop on Web\n }\n}\n"],"mappings":"AAQA,SAASA,IAAI,QAAQ,QAAQ;AAE7B,OAAO,MAAMC,wBAAwB,SAC3BD,IAAI,CAEd;EACEE,WAAWA,CAACC,SAAoB,EAAE;IAChC,KAAK,CAACA,SAAS,CAAC;EAClB;EAEAC,aAAaA,CAACC,KAAc,EAAgB;IAC1C,MAAMC,IAAI,GAAGD,KAAK,CAACE,YAAY,CAAC,CAAC;IACjC,MAAMC,iBAAiB,GAAG,IAAIC,iBAAiB,CAACJ,KAAK,CAACK,UAAU,CAAC,CAAE,CAAC;IACpE,MAAMC,SAAS,GAAG,IAAIC,SAAS,CAACJ,iBAAiB,EAAEF,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3E,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAACV,IAAI,CAACO,KAAK,EAAEP,IAAI,CAACQ,MAAM,CAAC;IAC3D,MAAMG,GAAG,GAAGF,MAAM,CAACG,UAAU,CAAC,IAAI,CAAC;IACnC,IAAI,CAACD,GAAG,EAAE;MACR,MAAM,IAAIE,KAAK,CAAC,sCAAsC,CAAC;IACzD;IACAF,GAAG,CAACG,YAAY,CAACT,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;IACjC,OAAOI,MAAM;EACf;EAEAM,OAAOA,CAACC,aAA2B,EAAE;IACnC;EAAA;AAEJ"}
@@ -1,2 +0,0 @@
1
- import { throwOnMissingReanimated } from "../external/reanimated/moduleWrapper";
2
- export default throwOnMissingReanimated;
@@ -1,5 +1,2 @@
1
- import { throwOnMissingReanimated } from "../external/reanimated/moduleWrapper";
2
1
 
3
- // eslint-disable-next-line import/no-default-export
4
- export default throwOnMissingReanimated;
5
2
  //# sourceMappingURL=NativeSkiaModule.web.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["throwOnMissingReanimated"],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":["import { throwOnMissingReanimated } from \"../external/reanimated/moduleWrapper\";\n\n// eslint-disable-next-line import/no-default-export\nexport default throwOnMissingReanimated;\n"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,sCAAsC;;AAE/E;AACA,eAAeA,wBAAwB"}
1
+ {"version":3,"names":[],"sources":["NativeSkiaModule.web.ts"],"sourcesContent":[""],"mappings":""}
@@ -0,0 +1,10 @@
1
+ type ImportType = ReturnType<typeof require>;
2
+ /**
3
+ * Create a lazily-imported module proxy.
4
+ * This is useful for lazily requiring optional dependencies.
5
+ */
6
+ export declare const createModuleProxy: <TModule>(getModule: () => ImportType) => TModule;
7
+ export declare class OptionalDependencyNotInstalledError extends Error {
8
+ constructor(name: string);
9
+ }
10
+ export {};
@@ -0,0 +1,3 @@
1
+ import type * as ReanimatedT from "react-native-reanimated";
2
+ declare const Reanimated: typeof ReanimatedT;
3
+ export default Reanimated;
@@ -46,7 +46,7 @@ export interface ImageFactory {
46
46
  MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
47
47
  /**
48
48
  * Return an Image backed by a given native buffer.
49
- * The platform buffer must be a valid owning reference.
49
+ * The native buffer must be a valid owning reference.
50
50
  *
51
51
  * For instance, this API is used by
52
52
  * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
@@ -54,9 +54,9 @@ export interface ImageFactory {
54
54
  *
55
55
  * - On Android; This is an `AHardwareBuffer*`
56
56
  * - On iOS, this is a `CVPixelBufferRef`
57
- * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
57
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer
58
58
  * @throws Throws an error if the Image could not be created, for example when the given
59
- * platform buffer is invalid.
59
+ * native buffer is invalid.
60
60
  */
61
61
  MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
62
62
  /**
@@ -8,11 +8,11 @@ export declare const isNativeBufferWeb: (buffer: NativeBuffer) => buffer is Canv
8
8
  export declare const isNativeBufferNode: (buffer: NativeBuffer) => buffer is ArrayBuffer;
9
9
  export interface NativeBufferFactory {
10
10
  /**
11
- * Copy pixels to a platform buffer. (for testing purposes)
11
+ * Copy pixels to a native buffer.
12
12
  */
13
13
  MakeFromImage: (image: SkImage) => NativeBuffer;
14
14
  /**
15
- * Release a platform buffer that was created with `MakeFromImage`.
15
+ * Release a native buffer that was created with `MakeFromImage`.
16
16
  */
17
- Release: (platformBuffer: NativeBuffer) => void;
17
+ Release: (nativeBuffer: NativeBuffer) => void;
18
18
  }
@@ -4,5 +4,5 @@ import { Host } from "./Host";
4
4
  export declare class JsiSkNativeBufferFactory extends Host implements NativeBufferFactory {
5
5
  constructor(CanvasKit: CanvasKit);
6
6
  MakeFromImage(image: SkImage): NativeBuffer;
7
- Release(_platformBuffer: NativeBuffer): void;
7
+ Release(_nativeBuffer: NativeBuffer): void;
8
8
  }
@@ -1,2 +0,0 @@
1
- import { throwOnMissingReanimated } from "../external/reanimated/moduleWrapper";
2
- export default throwOnMissingReanimated;
@@ -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>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>
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>libskia.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>
@@ -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>
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": "1.2.1",
10
+ "version": "1.2.3",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "react-native": "src/index.ts",
@@ -0,0 +1,30 @@
1
+ // https://github.com/mrousavy/react-native-vision-camera/blob/main/package/src/dependencies/ModuleProxy.ts
2
+ type ImportType = ReturnType<typeof require>;
3
+
4
+ /**
5
+ * Create a lazily-imported module proxy.
6
+ * This is useful for lazily requiring optional dependencies.
7
+ */
8
+ export const createModuleProxy = <TModule>(
9
+ getModule: () => ImportType
10
+ ): TModule => {
11
+ const holder: { module: TModule | undefined } = { module: undefined };
12
+
13
+ const proxy = new Proxy(holder, {
14
+ get: (target, property) => {
15
+ if (target.module == null) {
16
+ // lazy initialize module via require()
17
+ // caller needs to make sure the require() call is wrapped in a try/catch
18
+ target.module = getModule() as TModule;
19
+ }
20
+ return target.module[property as keyof typeof holder.module];
21
+ },
22
+ });
23
+ return proxy as unknown as TModule;
24
+ };
25
+
26
+ export class OptionalDependencyNotInstalledError extends Error {
27
+ constructor(name: string) {
28
+ super(`${name} is not installed!`);
29
+ }
30
+ }
@@ -0,0 +1,18 @@
1
+ import type * as ReanimatedT from "react-native-reanimated";
2
+
3
+ import {
4
+ OptionalDependencyNotInstalledError,
5
+ createModuleProxy,
6
+ } from "../ModuleProxy";
7
+ type TReanimated = typeof ReanimatedT;
8
+
9
+ const Reanimated = createModuleProxy<TReanimated>(() => {
10
+ try {
11
+ return require("react-native-reanimated");
12
+ } catch (e) {
13
+ throw new OptionalDependencyNotInstalledError("react-native-reanimated");
14
+ }
15
+ });
16
+
17
+ // eslint-disable-next-line import/no-default-export
18
+ export default Reanimated;
@@ -4,17 +4,18 @@ import type { WorkletFunction } from "react-native-reanimated/lib/typescript/rea
4
4
  import type { SkColor, SkHostRect, SkPoint, SkRSXform } from "../../skia/types";
5
5
  import { Skia } from "../../skia";
6
6
 
7
- import { startMapper, stopMapper, makeMutable } from "./moduleWrapper";
8
7
  import { notifyChange } from "./interpolators";
8
+ import Rea from "./ReanimatedProxy";
9
9
 
10
10
  type Modifier<T> = (input: T, index: number) => void;
11
11
 
12
- const useBufferValue = <T>(size: number, bufferInitializer: () => T) =>
13
- useMemo(
14
- () => makeMutable(new Array(size).fill(0).map(bufferInitializer)),
12
+ const useBufferValue = <T>(size: number, bufferInitializer: () => T) => {
13
+ return useMemo(
14
+ () => Rea.makeMutable(new Array(size).fill(0).map(bufferInitializer)),
15
15
  // eslint-disable-next-line react-hooks/exhaustive-deps
16
16
  [size]
17
17
  );
18
+ };
18
19
 
19
20
  const useBuffer = <T>(
20
21
  size: number,
@@ -24,7 +25,7 @@ const useBuffer = <T>(
24
25
  const values = useBufferValue(size, bufferInitializer);
25
26
  const mod = modifier as WorkletFunction;
26
27
  const deps = [size, ...Object.values(mod.__closure ?? {})];
27
- const mapperId = startMapper(() => {
28
+ const mapperId = Rea.startMapper(() => {
28
29
  "worklet";
29
30
  values.value.forEach((val, index) => {
30
31
  modifier(val, index);
@@ -34,7 +35,7 @@ const useBuffer = <T>(
34
35
 
35
36
  useEffect(() => {
36
37
  return () => {
37
- stopMapper(mapperId);
38
+ Rea.stopMapper(mapperId);
38
39
  };
39
40
  }, [mapperId]);
40
41
 
@@ -10,12 +10,7 @@ import { interpolatePaths, interpolateVector } from "../../animation";
10
10
  import { Skia } from "../../skia";
11
11
  import { isOnMainThread } from "../../renderer/Offscreen";
12
12
 
13
- import {
14
- useAnimatedReaction,
15
- useFrameCallback,
16
- useSharedValue,
17
- useDerivedValue,
18
- } from "./moduleWrapper";
13
+ import Rea from "./ReanimatedProxy";
19
14
 
20
15
  export const notifyChange = (value: SharedValue<unknown>) => {
21
16
  "worklet";
@@ -27,8 +22,8 @@ export const notifyChange = (value: SharedValue<unknown>) => {
27
22
 
28
23
  export const usePathValue = (cb: (path: SkPath) => void, init?: SkPath) => {
29
24
  const pathInit = useMemo(() => Skia.Path.Make(), []);
30
- const path = useSharedValue(pathInit);
31
- useDerivedValue(() => {
25
+ const path = Rea.useSharedValue(pathInit);
26
+ Rea.useDerivedValue(() => {
32
27
  path.value.reset();
33
28
  if (init !== undefined) {
34
29
  path.value.addPath(init);
@@ -40,7 +35,7 @@ export const usePathValue = (cb: (path: SkPath) => void, init?: SkPath) => {
40
35
  };
41
36
 
42
37
  export const useClock = () => {
43
- const clock = useSharedValue(0);
38
+ const clock = Rea.useSharedValue(0);
44
39
  const callback = useCallback(
45
40
  (info: FrameInfo) => {
46
41
  "worklet";
@@ -48,7 +43,7 @@ export const useClock = () => {
48
43
  },
49
44
  [clock]
50
45
  );
51
- useFrameCallback(callback);
46
+ Rea.useFrameCallback(callback);
52
47
  return clock;
53
48
  };
54
49
 
@@ -73,8 +68,8 @@ const useInterpolator = <T>(
73
68
  ) => {
74
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
75
70
  const init = useMemo(() => factory(), []);
76
- const result = useSharedValue(init);
77
- useAnimatedReaction(
71
+ const result = Rea.useSharedValue(init);
72
+ Rea.useAnimatedReaction(
78
73
  () => value.value,
79
74
  (val) => {
80
75
  result.value = interpolator(val, input, output, options, result.value);
@@ -4,26 +4,39 @@ import type { Container } from "../../renderer/Container";
4
4
  import type { AnimatedProps } from "../../renderer/processors";
5
5
  import type { Node } from "../../dom/types";
6
6
 
7
- import {
8
- startMapper,
9
- stopMapper,
10
- isSharedValue,
11
- HAS_REANIMATED3,
12
- HAS_REANIMATED2,
13
- runOnJS,
14
- } from "./moduleWrapper";
7
+ import Rea from "./ReanimatedProxy";
8
+
9
+ let HAS_REANIMATED = false;
10
+ let HAS_REANIMATED_3 = false;
11
+ try {
12
+ require("react-native-reanimated");
13
+ HAS_REANIMATED = true;
14
+ const reanimatedVersion =
15
+ require("react-native-reanimated/package.json").version;
16
+ if (
17
+ reanimatedVersion &&
18
+ (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))
19
+ ) {
20
+ HAS_REANIMATED_3 = true;
21
+ }
22
+ } catch (e) {
23
+ HAS_REANIMATED = false;
24
+ }
15
25
 
16
26
  const _bindings = new WeakMap<Node<unknown>, unknown>();
17
27
 
18
28
  export const unbindReanimatedNode = (node: Node<unknown>) => {
29
+ if (!HAS_REANIMATED) {
30
+ return;
31
+ }
19
32
  const previousMapperId = _bindings.get(node);
20
33
  if (previousMapperId !== undefined) {
21
- stopMapper(previousMapperId as number);
34
+ Rea.stopMapper(previousMapperId as number);
22
35
  }
23
36
  };
24
37
 
25
38
  export function extractReanimatedProps(props: AnimatedProps<any>) {
26
- if (!HAS_REANIMATED3 && !HAS_REANIMATED2) {
39
+ if (!HAS_REANIMATED) {
27
40
  return [props, {}];
28
41
  }
29
42
  const reanimatedProps = {} as AnimatedProps<any>;
@@ -33,7 +46,7 @@ export function extractReanimatedProps(props: AnimatedProps<any>) {
33
46
  continue;
34
47
  }
35
48
  const propValue = props[propName];
36
- if (isSharedValue(propValue)) {
49
+ if (Rea.isSharedValue(propValue)) {
37
50
  reanimatedProps[propName] = propValue;
38
51
  otherProps[propName] = propValue.value;
39
52
  } else {
@@ -51,7 +64,7 @@ function bindReanimatedProps2(
51
64
  const sharedValues = Object.values(reanimatedProps);
52
65
  const previousMapperId = _bindings.get(node);
53
66
  if (previousMapperId !== undefined) {
54
- stopMapper(previousMapperId as number);
67
+ Rea.stopMapper(previousMapperId as number);
55
68
  }
56
69
  if (sharedValues.length > 0) {
57
70
  const viewId = container.getNativeId();
@@ -70,9 +83,9 @@ function bindReanimatedProps2(
70
83
  container.redraw();
71
84
  }
72
85
  };
73
- const mapperId = startMapper(() => {
86
+ const mapperId = Rea.startMapper(() => {
74
87
  "worklet";
75
- runOnJS(updateProps)();
88
+ Rea.runOnJS(updateProps)();
76
89
  }, sharedValues);
77
90
  _bindings.set(node, mapperId);
78
91
  }
@@ -83,21 +96,21 @@ export function bindReanimatedProps(
83
96
  node: Node<any>,
84
97
  reanimatedProps: AnimatedProps<any>
85
98
  ) {
86
- if (HAS_REANIMATED2 && !HAS_REANIMATED3) {
99
+ if (HAS_REANIMATED && !HAS_REANIMATED_3) {
87
100
  return bindReanimatedProps2(container, node, reanimatedProps);
88
101
  }
89
- if (!HAS_REANIMATED3) {
102
+ if (!HAS_REANIMATED) {
90
103
  return;
91
104
  }
92
105
  const sharedValues = Object.values(reanimatedProps);
93
106
  const previousMapperId = _bindings.get(node);
94
107
  if (previousMapperId !== undefined) {
95
- stopMapper(previousMapperId as number);
108
+ Rea.stopMapper(previousMapperId as number);
96
109
  }
97
110
  if (sharedValues.length > 0) {
98
111
  const viewId = container.getNativeId();
99
112
  const { SkiaViewApi } = global;
100
- const mapperId = startMapper(() => {
113
+ const mapperId = Rea.startMapper(() => {
101
114
  "worklet";
102
115
  if (node) {
103
116
  for (const propName in reanimatedProps) {
@@ -14,7 +14,7 @@ import {
14
14
  } from "../../renderer/Offscreen";
15
15
  import { Skia, useImage } from "../../skia";
16
16
 
17
- import { runOnUI, useSharedValue } from "./moduleWrapper";
17
+ import Rea from "./ReanimatedProxy";
18
18
 
19
19
  const createTexture = (
20
20
  texture: SharedValue<SkImage | null>,
@@ -57,10 +57,10 @@ export const usePictureAsTexture = (
57
57
  picture: SkPicture | null,
58
58
  size: SkSize
59
59
  ) => {
60
- const texture = useSharedValue<SkImage | null>(null);
60
+ const texture = Rea.useSharedValue<SkImage | null>(null);
61
61
  useEffect(() => {
62
62
  if (picture !== null) {
63
- runOnUI(createTexture)(texture, picture, size);
63
+ Rea.runOnUI(createTexture)(texture, picture, size);
64
64
  }
65
65
  }, [texture, picture, size]);
66
66
  return texture;
@@ -4,11 +4,7 @@ import { type FrameInfo, type SharedValue } from "react-native-reanimated";
4
4
  import { useAnimatedImage } from "../../skia/core/AnimatedImage";
5
5
  import type { DataSourceParam, SkImage } from "../../skia/types";
6
6
 
7
- import {
8
- throwOnMissingReanimated,
9
- useFrameCallback,
10
- useSharedValue,
11
- } from "./moduleWrapper";
7
+ import Rea from "./ReanimatedProxy";
12
8
 
13
9
  const DEFAULT_FRAME_DURATION = 60;
14
10
 
@@ -16,11 +12,10 @@ export const useAnimatedImageValue = (
16
12
  source: DataSourceParam,
17
13
  paused?: SharedValue<boolean>
18
14
  ) => {
19
- throwOnMissingReanimated();
20
- const defaultPaused = useSharedValue(false);
15
+ const defaultPaused = Rea.useSharedValue(false);
21
16
  const isPaused = paused ?? defaultPaused;
22
- const currentFrame = useSharedValue<null | SkImage>(null);
23
- const lastTimestamp = useSharedValue(-1);
17
+ const currentFrame = Rea.useSharedValue<null | SkImage>(null);
18
+ const lastTimestamp = Rea.useSharedValue(-1);
24
19
  const animatedImage = useAnimatedImage(
25
20
  source,
26
21
  (err) => {
@@ -32,7 +27,7 @@ export const useAnimatedImageValue = (
32
27
  const frameDuration =
33
28
  animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;
34
29
 
35
- useFrameCallback((frameInfo: FrameInfo) => {
30
+ Rea.useFrameCallback((frameInfo: FrameInfo) => {
36
31
  if (!animatedImage) {
37
32
  currentFrame.value = null;
38
33
  return;
@@ -1,11 +1,6 @@
1
1
  import { useEffect, useMemo } from "react";
2
2
 
3
- import {
4
- useSharedValue,
5
- runOnJS,
6
- startMapper,
7
- stopMapper,
8
- } from "./moduleWrapper";
3
+ import Rea from "./ReanimatedProxy";
9
4
 
10
5
  export const useDerivedValueOnJS = (
11
6
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -13,13 +8,13 @@ export const useDerivedValueOnJS = (
13
8
  deps: unknown[]
14
9
  ) => {
15
10
  const init = useMemo(() => fn(), [fn]);
16
- const value = useSharedValue(init);
11
+ const value = Rea.useSharedValue(init);
17
12
  useEffect(() => {
18
- const mapperId = startMapper(() => {
13
+ const mapperId = Rea.startMapper(() => {
19
14
  "worklet";
20
- runOnJS(fn)();
15
+ Rea.runOnJS(fn)();
21
16
  }, deps);
22
- return () => stopMapper(mapperId);
17
+ return () => Rea.stopMapper(mapperId);
23
18
  }, [deps, fn]);
24
19
  return value;
25
20
  };
@@ -32,16 +32,10 @@ export const drawAsImage = (element: ReactElement, size: SkSize) => {
32
32
  return drawAsImageFromPicture(drawAsPicture(element), size);
33
33
  };
34
34
 
35
- // TODO: We're not sure yet why PixelRatio is not needed here.
36
- const pd = 1;
37
35
  export const drawAsImageFromPicture = (picture: SkPicture, size: SkSize) => {
38
36
  "worklet";
39
- const surface = Skia.Surface.MakeOffscreen(
40
- size.width * pd,
41
- size.height * pd
42
- )!;
37
+ const surface = Skia.Surface.MakeOffscreen(size.width, size.height)!;
43
38
  const canvas = surface.getCanvas();
44
- canvas.scale(pd, pd);
45
39
  canvas.drawPicture(picture);
46
40
  surface.flush();
47
41
  const image = surface.makeImageSnapshot();
@@ -54,7 +54,7 @@ export interface ImageFactory {
54
54
 
55
55
  /**
56
56
  * Return an Image backed by a given native buffer.
57
- * The platform buffer must be a valid owning reference.
57
+ * The native buffer must be a valid owning reference.
58
58
  *
59
59
  * For instance, this API is used by
60
60
  * [react-native-vision-camera](https://github.com/mrousavy/react-native-vision-camera)
@@ -62,9 +62,9 @@ export interface ImageFactory {
62
62
  *
63
63
  * - On Android; This is an `AHardwareBuffer*`
64
64
  * - On iOS, this is a `CVPixelBufferRef`
65
- * @param nativeBuffer A strong `uintptr_t` pointer to the native platform buffer
65
+ * @param nativeBuffer A strong `uintptr_t` pointer to the native buffer
66
66
  * @throws Throws an error if the Image could not be created, for example when the given
67
- * platform buffer is invalid.
67
+ * native buffer is invalid.
68
68
  */
69
69
  MakeImageFromNativeBuffer: (nativeBuffer: NativeBuffer) => SkImage;
70
70
 
@@ -28,11 +28,11 @@ export const isNativeBufferNode = (
28
28
 
29
29
  export interface NativeBufferFactory {
30
30
  /**
31
- * Copy pixels to a platform buffer. (for testing purposes)
31
+ * Copy pixels to a native buffer.
32
32
  */
33
33
  MakeFromImage: (image: SkImage) => NativeBuffer;
34
34
  /**
35
- * Release a platform buffer that was created with `MakeFromImage`.
35
+ * Release a native buffer that was created with `MakeFromImage`.
36
36
  */
37
- Release: (platformBuffer: NativeBuffer) => void;
37
+ Release: (nativeBuffer: NativeBuffer) => void;
38
38
  }
@@ -29,7 +29,7 @@ export class JsiSkNativeBufferFactory
29
29
  return canvas;
30
30
  }
31
31
 
32
- Release(_platformBuffer: NativeBuffer) {
32
+ Release(_nativeBuffer: NativeBuffer) {
33
33
  // it's a noop on Web
34
34
  }
35
35
  }
@@ -1,4 +0,0 @@
1
- import { throwOnMissingReanimated } from "../external/reanimated/moduleWrapper";
2
-
3
- // eslint-disable-next-line import/no-default-export
4
- export default throwOnMissingReanimated;