@shopify/react-native-skia 2.1.1 → 2.2.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 (129) hide show
  1. package/android/CMakeLists.txt +1 -1
  2. package/android/cpp/rnskia-android/OpenGLWindowContext.h +1 -1
  3. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +1 -1
  4. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +1 -1
  5. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -1
  6. package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -1
  7. package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +6 -0
  8. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
  9. package/apple/MetalContext.h +2 -2
  10. package/apple/MetalWindowContext.h +2 -2
  11. package/apple/MetalWindowContext.mm +7 -4
  12. package/apple/RNSkApplePlatformContext.mm +1 -1
  13. package/apple/RNSkAppleView.h +7 -1
  14. package/apple/RNSkMetalCanvasProvider.h +4 -1
  15. package/apple/RNSkMetalCanvasProvider.mm +9 -4
  16. package/apple/SkiaPictureView.mm +4 -0
  17. package/apple/SkiaUIView.h +1 -0
  18. package/apple/SkiaUIView.mm +9 -0
  19. package/cpp/api/JsiSkImage.h +1 -1
  20. package/cpp/api/JsiSkSurface.h +1 -1
  21. package/cpp/api/JsiSkiaContext.h +1 -1
  22. package/cpp/api/recorder/ImageFilters.h +3 -3
  23. package/cpp/api/recorder/Paint.h +4 -0
  24. package/cpp/rnskia/{DawnContext.h → RNDawnContext.h} +3 -3
  25. package/cpp/rnskia/{DawnWindowContext.cpp → RNDawnWindowContext.cpp} +3 -3
  26. package/cpp/rnskia/{DawnWindowContext.h → RNDawnWindowContext.h} +2 -2
  27. package/cpp/rnskia/RNSkJsiViewApi.h +36 -1
  28. package/cpp/rnskia/RNSkPlatformContext.h +1 -1
  29. package/cpp/rnskia/RNSkView.h +10 -0
  30. package/lib/commonjs/dom/types/Drawings.d.ts +1 -1
  31. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  32. package/lib/commonjs/renderer/Canvas.d.ts +12 -4
  33. package/lib/commonjs/renderer/Canvas.js +49 -25
  34. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  35. package/lib/commonjs/renderer/components/ImageFilter.js.map +1 -1
  36. package/lib/commonjs/skia/types/Matrix4.d.ts +4 -0
  37. package/lib/commonjs/skia/types/Matrix4.js +18 -1
  38. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  39. package/lib/commonjs/sksg/Container.d.ts +13 -7
  40. package/lib/commonjs/sksg/Container.js +44 -18
  41. package/lib/commonjs/sksg/Container.js.map +1 -1
  42. package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
  43. package/lib/commonjs/sksg/Reconciler.js +2 -2
  44. package/lib/commonjs/sksg/Reconciler.js.map +1 -1
  45. package/lib/commonjs/sksg/Recorder/Player.js +9 -3
  46. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  47. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +2 -2
  48. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  49. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  50. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  51. package/lib/commonjs/views/types.d.ts +1 -0
  52. package/lib/commonjs/views/types.js.map +1 -1
  53. package/lib/module/dom/types/Drawings.d.ts +1 -1
  54. package/lib/module/dom/types/Drawings.js.map +1 -1
  55. package/lib/module/renderer/Canvas.d.ts +12 -4
  56. package/lib/module/renderer/Canvas.js +48 -25
  57. package/lib/module/renderer/Canvas.js.map +1 -1
  58. package/lib/module/renderer/components/ImageFilter.js.map +1 -1
  59. package/lib/module/skia/types/Matrix4.d.ts +4 -0
  60. package/lib/module/skia/types/Matrix4.js +16 -0
  61. package/lib/module/skia/types/Matrix4.js.map +1 -1
  62. package/lib/module/sksg/Container.d.ts +13 -7
  63. package/lib/module/sksg/Container.js +44 -18
  64. package/lib/module/sksg/Container.js.map +1 -1
  65. package/lib/module/sksg/Reconciler.d.ts +3 -2
  66. package/lib/module/sksg/Reconciler.js +2 -2
  67. package/lib/module/sksg/Reconciler.js.map +1 -1
  68. package/lib/module/sksg/Recorder/Player.js +9 -3
  69. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  70. package/lib/module/sksg/Recorder/commands/ImageFilters.js +2 -2
  71. package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  72. package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  73. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
  74. package/lib/module/views/types.d.ts +1 -0
  75. package/lib/module/views/types.js.map +1 -1
  76. package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +8 -2
  77. package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
  78. package/lib/typescript/lib/commonjs/sksg/Container.d.ts +11 -3
  79. package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +7 -4
  80. package/lib/typescript/lib/module/mock/index.d.ts +1 -0
  81. package/lib/typescript/lib/module/renderer/Canvas.d.ts +11 -2
  82. package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
  83. package/lib/typescript/lib/module/sksg/Container.d.ts +11 -3
  84. package/lib/typescript/lib/module/sksg/Reconciler.d.ts +7 -4
  85. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
  86. package/lib/typescript/src/renderer/Canvas.d.ts +12 -4
  87. package/lib/typescript/src/skia/types/Matrix4.d.ts +4 -0
  88. package/lib/typescript/src/sksg/Container.d.ts +13 -7
  89. package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
  90. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
  91. package/lib/typescript/src/views/types.d.ts +1 -0
  92. package/libs/android/arm64-v8a/libskia.a +0 -0
  93. package/libs/android/armeabi-v7a/libskia.a +0 -0
  94. package/libs/android/x86/libskia.a +0 -0
  95. package/libs/android/x86_64/libskia.a +0 -0
  96. package/libs/apple/libpathops.xcframework/Info.plist +15 -15
  97. package/libs/apple/libskia.xcframework/Info.plist +11 -11
  98. package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  99. package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  100. package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
  101. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
  102. package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  103. package/libs/apple/libskottie.xcframework/Info.plist +16 -16
  104. package/libs/apple/libskparagraph.xcframework/Info.plist +8 -8
  105. package/libs/apple/libsksg.xcframework/Info.plist +6 -6
  106. package/libs/apple/libskshaper.xcframework/Info.plist +10 -10
  107. package/libs/apple/libskunicode_core.xcframework/Info.plist +10 -10
  108. package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
  109. package/libs/apple/libsvg.xcframework/Info.plist +15 -15
  110. package/package.json +1 -1
  111. package/react-native-skia.podspec +5 -5
  112. package/src/dom/types/Drawings.ts +1 -1
  113. package/src/renderer/Canvas.tsx +53 -30
  114. package/src/renderer/__tests__/FitBox.spec.tsx +556 -4
  115. package/src/renderer/__tests__/e2e/ImageFilter.spec.tsx +4 -4
  116. package/src/renderer/__tests__/e2e/Paint.spec.tsx +18 -0
  117. package/src/renderer/__tests__/e2e/Skottie.spec.tsx +24 -1
  118. package/src/renderer/__tests__/setup.tsx +2 -0
  119. package/src/renderer/components/ImageFilter.tsx +1 -1
  120. package/src/skia/types/Matrix4.ts +16 -0
  121. package/src/sksg/Container.ts +73 -20
  122. package/src/sksg/Reconciler.ts +5 -3
  123. package/src/sksg/Recorder/Player.ts +7 -7
  124. package/src/sksg/Recorder/commands/ImageFilters.ts +3 -6
  125. package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
  126. package/src/views/types.ts +1 -0
  127. /package/cpp/rnskia/{DawnUtils.h → RNDawnUtils.h} +0 -0
  128. /package/cpp/rnskia/{ImageProvider.h → RNImageProvider.h} +0 -0
  129. /package/cpp/rnskia/{WindowContext.h → RNWindowContext.h} +0 -0
@@ -1,57 +1,59 @@
1
1
  import type { FC } from "react";
2
2
  import React, {
3
- useCallback,
4
3
  useEffect,
5
4
  useImperativeHandle,
6
5
  useLayoutEffect,
7
6
  useMemo,
8
7
  useRef,
8
+ useState,
9
9
  } from "react";
10
- import type { LayoutChangeEvent, ViewProps } from "react-native";
11
- import type { SharedValue } from "react-native-reanimated";
10
+ import type {
11
+ MeasureInWindowOnSuccessCallback,
12
+ MeasureOnSuccessCallback,
13
+ View,
14
+ ViewProps,
15
+ } from "react-native";
16
+ import { type SharedValue } from "react-native-reanimated";
12
17
 
13
18
  import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
14
19
  import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
15
20
  import type { SkImage, SkRect, SkSize } from "../skia/types";
16
21
  import { SkiaSGRoot } from "../sksg/Reconciler";
17
22
  import { Skia } from "../skia";
18
- import type { SkiaBaseViewProps } from "../views";
19
23
 
20
24
  export interface CanvasRef extends FC<CanvasProps> {
21
25
  makeImageSnapshot(rect?: SkRect): SkImage;
22
26
  makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;
23
27
  redraw(): void;
24
28
  getNativeId(): number;
29
+ measure(callback: MeasureOnSuccessCallback): void;
30
+ measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
25
31
  }
26
32
 
27
33
  export const useCanvasRef = () => useRef<CanvasRef>(null);
28
34
 
29
- //const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
30
-
31
- // TODO: no need to go through the JS thread for this
32
- const useOnSizeEvent = (
33
- resultValue: SkiaBaseViewProps["onSize"],
34
- onLayout?: (event: LayoutChangeEvent) => void
35
- ) => {
36
- return useCallback(
37
- (event: LayoutChangeEvent) => {
38
- if (onLayout) {
39
- onLayout(event);
40
- }
41
- const { width, height } = event.nativeEvent.layout;
42
-
43
- if (resultValue) {
44
- resultValue.value = { width, height };
45
- }
46
- },
47
- [onLayout, resultValue]
48
- );
35
+ export const useCanvasSize = () => {
36
+ const ref = useCanvasRef();
37
+ const [size, setSize] = useState<SkSize>({ width: 0, height: 0 });
38
+ useLayoutEffect(() => {
39
+ if (ref.current) {
40
+ ref.current.measure((_x, _y, width, height) => {
41
+ setSize({ width, height });
42
+ });
43
+ }
44
+ // eslint-disable-next-line react-hooks/exhaustive-deps
45
+ }, []);
46
+ return { ref, size };
49
47
  };
50
48
 
51
- export interface CanvasProps extends ViewProps {
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
+ export const isFabric = Boolean((global as any)?.nativeFabricUIManager);
51
+
52
+ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
52
53
  debug?: boolean;
53
54
  opaque?: boolean;
54
55
  onSize?: SharedValue<SkSize>;
56
+ colorSpace?: "p3" | "srgb";
55
57
  ref?: React.Ref<CanvasRef>;
56
58
  }
57
59
 
@@ -60,23 +62,36 @@ export const Canvas = ({
60
62
  opaque,
61
63
  children,
62
64
  onSize,
63
- onLayout: _onLayout,
65
+ colorSpace = "p3",
64
66
  ref,
67
+ // Here know this is a type error but this is done on purpose to check it at runtime
68
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
69
+ // @ts-expect-error
70
+ onLayout,
65
71
  ...viewProps
66
72
  }: CanvasProps) => {
67
- const onLayout = useOnSizeEvent(onSize, _onLayout);
73
+ if (onLayout && isFabric) {
74
+ console.error(
75
+ // eslint-disable-next-line max-len
76
+ "<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://shopify.github.io/react-native-skia/docs/canvas/overview/#getting-the-canvas-size"
77
+ );
78
+ }
79
+ const viewRef = useRef<View>(null);
68
80
  // Native ID
69
81
  const nativeId = useMemo(() => {
70
82
  return SkiaViewNativeId.current++;
71
83
  }, []);
72
84
 
73
85
  // Root
74
- const root = useMemo(() => new SkiaSGRoot(Skia, nativeId), [nativeId]);
86
+ const root = useMemo(
87
+ () => new SkiaSGRoot(Skia, nativeId, onSize),
88
+ [nativeId, onSize]
89
+ );
75
90
 
76
91
  // Render effects
77
92
  useLayoutEffect(() => {
78
93
  root.render(children);
79
- }, [children, root]);
94
+ }, [children, root, nativeId]);
80
95
 
81
96
  useEffect(() => {
82
97
  return () => {
@@ -101,15 +116,23 @@ export const Canvas = ({
101
116
  getNativeId: () => {
102
117
  return nativeId;
103
118
  },
119
+ measure: (callback) => {
120
+ viewRef.current?.measure(callback);
121
+ },
122
+ measureInWindow: (callback) => {
123
+ viewRef.current?.measureInWindow(callback);
124
+ },
104
125
  } as CanvasRef)
105
126
  );
127
+
106
128
  return (
107
129
  <SkiaPictureViewNativeComponent
130
+ ref={viewRef}
108
131
  collapsable={false}
109
132
  nativeID={`${nativeId}`}
110
133
  debug={debug}
111
134
  opaque={opaque}
112
- onLayout={onLayout}
135
+ colorSpace={colorSpace}
113
136
  {...viewProps}
114
137
  />
115
138
  );