@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.
- package/android/CMakeLists.txt +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +1 -1
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +1 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +1 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +6 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
- package/apple/MetalContext.h +2 -2
- package/apple/MetalWindowContext.h +2 -2
- package/apple/MetalWindowContext.mm +7 -4
- package/apple/RNSkApplePlatformContext.mm +1 -1
- package/apple/RNSkAppleView.h +7 -1
- package/apple/RNSkMetalCanvasProvider.h +4 -1
- package/apple/RNSkMetalCanvasProvider.mm +9 -4
- package/apple/SkiaPictureView.mm +4 -0
- package/apple/SkiaUIView.h +1 -0
- package/apple/SkiaUIView.mm +9 -0
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkSurface.h +1 -1
- package/cpp/api/JsiSkiaContext.h +1 -1
- package/cpp/api/recorder/ImageFilters.h +3 -3
- package/cpp/api/recorder/Paint.h +4 -0
- package/cpp/rnskia/{DawnContext.h → RNDawnContext.h} +3 -3
- package/cpp/rnskia/{DawnWindowContext.cpp → RNDawnWindowContext.cpp} +3 -3
- package/cpp/rnskia/{DawnWindowContext.h → RNDawnWindowContext.h} +2 -2
- package/cpp/rnskia/RNSkJsiViewApi.h +36 -1
- package/cpp/rnskia/RNSkPlatformContext.h +1 -1
- package/cpp/rnskia/RNSkView.h +10 -0
- package/lib/commonjs/dom/types/Drawings.d.ts +1 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +12 -4
- package/lib/commonjs/renderer/Canvas.js +49 -25
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/ImageFilter.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +4 -0
- package/lib/commonjs/skia/types/Matrix4.js +18 -1
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +13 -7
- package/lib/commonjs/sksg/Container.js +44 -18
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
- package/lib/commonjs/sksg/Reconciler.js +2 -2
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +9 -3
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +2 -2
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/dom/types/Drawings.d.ts +1 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +12 -4
- package/lib/module/renderer/Canvas.js +48 -25
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/ImageFilter.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +4 -0
- package/lib/module/skia/types/Matrix4.js +16 -0
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +13 -7
- package/lib/module/sksg/Container.js +44 -18
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Reconciler.d.ts +3 -2
- package/lib/module/sksg/Reconciler.js +2 -2
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +9 -3
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +2 -2
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/types.d.ts +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +8 -2
- package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +11 -3
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +7 -4
- package/lib/typescript/lib/module/mock/index.d.ts +1 -0
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +11 -2
- package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Container.d.ts +11 -3
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +7 -4
- package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +12 -4
- package/lib/typescript/src/skia/types/Matrix4.d.ts +4 -0
- package/lib/typescript/src/sksg/Container.d.ts +13 -7
- package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/views/types.d.ts +1 -0
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/apple/libpathops.xcframework/Info.plist +15 -15
- package/libs/apple/libskia.xcframework/Info.plist +11 -11
- package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/apple/libskottie.xcframework/Info.plist +16 -16
- package/libs/apple/libskparagraph.xcframework/Info.plist +8 -8
- package/libs/apple/libsksg.xcframework/Info.plist +6 -6
- package/libs/apple/libskshaper.xcframework/Info.plist +10 -10
- package/libs/apple/libskunicode_core.xcframework/Info.plist +10 -10
- package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
- package/libs/apple/libsvg.xcframework/Info.plist +15 -15
- package/package.json +1 -1
- package/react-native-skia.podspec +5 -5
- package/src/dom/types/Drawings.ts +1 -1
- package/src/renderer/Canvas.tsx +53 -30
- package/src/renderer/__tests__/FitBox.spec.tsx +556 -4
- package/src/renderer/__tests__/e2e/ImageFilter.spec.tsx +4 -4
- package/src/renderer/__tests__/e2e/Paint.spec.tsx +18 -0
- package/src/renderer/__tests__/e2e/Skottie.spec.tsx +24 -1
- package/src/renderer/__tests__/setup.tsx +2 -0
- package/src/renderer/components/ImageFilter.tsx +1 -1
- package/src/skia/types/Matrix4.ts +16 -0
- package/src/sksg/Container.ts +73 -20
- package/src/sksg/Reconciler.ts +5 -3
- package/src/sksg/Recorder/Player.ts +7 -7
- package/src/sksg/Recorder/commands/ImageFilters.ts +3 -6
- package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
- package/src/views/types.ts +1 -0
- /package/cpp/rnskia/{DawnUtils.h → RNDawnUtils.h} +0 -0
- /package/cpp/rnskia/{ImageProvider.h → RNImageProvider.h} +0 -0
- /package/cpp/rnskia/{WindowContext.h → RNWindowContext.h} +0 -0
package/src/renderer/Canvas.tsx
CHANGED
@@ -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 {
|
11
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
135
|
+
colorSpace={colorSpace}
|
113
136
|
{...viewProps}
|
114
137
|
/>
|
115
138
|
);
|