@shopify/react-native-skia 0.1.185 → 0.1.186
Sign up to get free protection for your applications and to get access to all the features.
- package/android/build.gradle +2 -1
- package/android/cpp/jni/JniPlatformContext.cpp +92 -3
- package/android/cpp/jni/include/JniPlatformContext.h +4 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +8 -0
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +17 -1
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +180 -0
- package/cpp/api/JsiSkFont.h +1 -1
- package/cpp/api/JsiSkHostObjects.h +1 -1
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkImageFactory.h +29 -0
- package/cpp/api/JsiSkPaint.h +7 -7
- package/cpp/api/JsiSkPathFactory.h +1 -1
- package/cpp/api/JsiSkPicture.h +2 -2
- package/cpp/api/JsiSkRuntimeEffect.h +3 -3
- package/cpp/api/JsiSkSVG.h +12 -2
- package/cpp/api/JsiSkShader.h +1 -1
- package/cpp/api/JsiSkSurface.h +3 -3
- package/cpp/api/JsiSkSurfaceFactory.h +1 -1
- package/cpp/api/JsiSkTypeface.h +1 -1
- package/cpp/rnskia/RNSkAnimation.h +3 -3
- package/cpp/rnskia/RNSkDomView.h +9 -9
- package/cpp/rnskia/RNSkInfoParameter.h +2 -2
- package/cpp/rnskia/RNSkJsView.h +8 -8
- package/cpp/rnskia/RNSkJsiViewApi.h +5 -5
- package/cpp/rnskia/RNSkPictureView.h +8 -8
- package/cpp/rnskia/RNSkPlatformContext.h +32 -3
- package/cpp/rnskia/RNSkValueApi.h +5 -5
- package/cpp/rnskia/RNSkView.h +6 -6
- package/cpp/rnskia/dom/base/ConcatablePaint.h +6 -6
- package/cpp/rnskia/dom/base/Declaration.h +1 -1
- package/cpp/rnskia/dom/base/DeclarationContext.h +7 -7
- package/cpp/rnskia/dom/base/DrawingContext.h +3 -3
- package/cpp/rnskia/dom/base/NodePropsContainer.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiGlyphsNode.h +8 -7
- package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiImageNode.h +5 -2
- package/cpp/rnskia/dom/nodes/JsiImageSvgNode.h +9 -9
- package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiPathNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiPointsNode.h +1 -1
- package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +7 -3
- package/cpp/rnskia/dom/nodes/JsiTextNode.h +5 -4
- package/cpp/rnskia/dom/nodes/JsiTextPathNode.h +3 -1
- package/cpp/rnskia/dom/props/BlendModeProp.h +1 -1
- package/cpp/rnskia/dom/props/CircleProp.h +1 -1
- package/cpp/rnskia/dom/props/ClipProp.h +1 -1
- package/cpp/rnskia/dom/props/FontProp.h +15 -10
- package/cpp/rnskia/dom/props/ImageProps.h +30 -16
- package/cpp/rnskia/dom/props/PaintProps.h +1 -1
- package/cpp/rnskia/dom/props/PathProp.h +1 -1
- package/cpp/rnskia/dom/props/PointProp.h +1 -1
- package/cpp/rnskia/dom/props/PointsProp.h +1 -1
- package/cpp/rnskia/dom/props/RRectProp.h +2 -2
- package/cpp/rnskia/dom/props/RadiusProp.h +1 -1
- package/cpp/rnskia/dom/props/RectProp.h +1 -1
- package/cpp/rnskia/dom/props/StrokeProps.h +1 -1
- package/cpp/rnskia/dom/props/SvgProp.h +18 -12
- package/cpp/rnskia/dom/props/TextBlobProp.h +60 -57
- package/cpp/rnskia/dom/props/TileModeProp.h +1 -1
- package/cpp/rnskia/dom/props/UniformsProp.h +1 -1
- package/cpp/rnskia/dom/props/VertexModeProp.h +1 -1
- package/cpp/rnskia/dom/props/VerticesProps.h +1 -1
- package/cpp/rnskia/values/RNSkClockValue.h +2 -2
- package/cpp/rnskia/values/RNSkComputedValue.h +1 -1
- package/cpp/rnskia/values/RNSkReadonlyValue.h +3 -3
- package/cpp/rnskia/values/RNSkValue.h +4 -4
- package/cpp/utils/RNSkMeasureTime.h +1 -1
- package/cpp/utils/RNSkTimingInfo.h +1 -1
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +16 -13
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +8 -0
- package/ios/RNSkia-iOS/SkiaManager.mm +20 -1
- package/ios/RNSkia-iOS/ViewScreenshotService.h +21 -0
- package/ios/RNSkia-iOS/ViewScreenshotService.mm +79 -0
- package/lib/commonjs/dom/nodes/drawings/ImageNode.js +22 -1
- package/lib/commonjs/dom/nodes/drawings/ImageNode.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/ImageSVG.js +5 -0
- package/lib/commonjs/dom/nodes/drawings/ImageSVG.js.map +1 -1
- package/lib/commonjs/dom/nodes/drawings/Text.d.ts +2 -2
- package/lib/commonjs/dom/nodes/drawings/Text.js +13 -2
- package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
- package/lib/commonjs/dom/nodes/paint/Shaders.js +5 -0
- package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/commonjs/dom/types/Drawings.d.ts +5 -5
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/dom/types/Shaders.d.ts +1 -1
- package/lib/commonjs/dom/types/Shaders.js.map +1 -1
- package/lib/commonjs/mock/index.js +2 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/core/Image.d.ts +14 -2
- package/lib/commonjs/skia/core/Image.js +37 -1
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +7 -0
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/SVG/SVG.d.ts +4 -1
- package/lib/commonjs/skia/types/SVG/SVG.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +7 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/dom/nodes/drawings/ImageNode.js +22 -1
- package/lib/module/dom/nodes/drawings/ImageNode.js.map +1 -1
- package/lib/module/dom/nodes/drawings/ImageSVG.js +5 -0
- package/lib/module/dom/nodes/drawings/ImageSVG.js.map +1 -1
- package/lib/module/dom/nodes/drawings/Text.d.ts +2 -2
- package/lib/module/dom/nodes/drawings/Text.js +13 -2
- package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
- package/lib/module/dom/nodes/paint/Shaders.js +5 -0
- package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
- package/lib/module/dom/types/Drawings.d.ts +5 -5
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/dom/types/Shaders.d.ts +1 -1
- package/lib/module/dom/types/Shaders.js.map +1 -1
- package/lib/module/mock/index.js +2 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/core/Image.d.ts +14 -2
- package/lib/module/skia/core/Image.js +32 -0
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +7 -0
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/SVG/SVG.d.ts +4 -1
- package/lib/module/skia/types/SVG/SVG.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -1
- package/lib/module/skia/web/JsiSkImageFactory.js +7 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/typescript/src/dom/nodes/drawings/Text.d.ts +2 -2
- package/lib/typescript/src/dom/types/Drawings.d.ts +5 -5
- package/lib/typescript/src/dom/types/Shaders.d.ts +1 -1
- package/lib/typescript/src/skia/core/Image.d.ts +14 -2
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +7 -0
- package/lib/typescript/src/skia/types/SVG/SVG.d.ts +4 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -1
- package/package.json +2 -2
- package/scripts/install-npm.js +3 -2
- package/src/dom/nodes/drawings/ImageNode.ts +9 -1
- package/src/dom/nodes/drawings/ImageSVG.ts +3 -0
- package/src/dom/nodes/drawings/Text.ts +13 -3
- package/src/dom/nodes/paint/Shaders.ts +4 -0
- package/src/dom/types/Drawings.ts +5 -5
- package/src/dom/types/Shaders.ts +1 -1
- package/src/mock/index.ts +1 -0
- package/src/skia/core/Image.ts +43 -1
- package/src/skia/types/Image/ImageFactory.ts +8 -0
- package/src/skia/types/SVG/SVG.ts +4 -1
- package/src/skia/web/JsiSkImageFactory.ts +8 -1
@@ -15,6 +15,12 @@ export class ImageNode extends JsiDrawingNode<
|
|
15
15
|
|
16
16
|
deriveProps() {
|
17
17
|
const { image } = this.props;
|
18
|
+
if (!image) {
|
19
|
+
return {
|
20
|
+
src: { x: 0, y: 0, width: 0, height: 0 },
|
21
|
+
dst: { x: 0, y: 0, width: 0, height: 0 },
|
22
|
+
};
|
23
|
+
}
|
18
24
|
const fit = this.props.fit ?? "contain";
|
19
25
|
const rect = processRect(this.Skia, this.props);
|
20
26
|
const { src, dst } = fitRects(
|
@@ -36,6 +42,8 @@ export class ImageNode extends JsiDrawingNode<
|
|
36
42
|
throw new Error("ImageNode: src and dst are undefined");
|
37
43
|
}
|
38
44
|
const { src, dst } = this.derived;
|
39
|
-
|
45
|
+
if (image) {
|
46
|
+
canvas.drawImageRect(image, src, dst, paint);
|
47
|
+
}
|
40
48
|
}
|
41
49
|
}
|
@@ -15,6 +15,9 @@ export class ImageSVGNode extends JsiDrawingNode<ImageSVGProps, null> {
|
|
15
15
|
|
16
16
|
draw({ canvas }: DrawingContext) {
|
17
17
|
const { svg } = this.props;
|
18
|
+
if (!svg) {
|
19
|
+
return;
|
20
|
+
}
|
18
21
|
const { x, y, width, height } = processRect(this.Skia, this.props);
|
19
22
|
canvas.save();
|
20
23
|
canvas.translate(x, y);
|
@@ -22,11 +22,16 @@ export class TextNode extends JsiDrawingNode<TextProps, null> {
|
|
22
22
|
|
23
23
|
draw({ canvas, paint }: DrawingContext) {
|
24
24
|
const { text, x, y, font } = this.props;
|
25
|
-
|
25
|
+
if (font) {
|
26
|
+
canvas.drawText(text, x, y, paint, font);
|
27
|
+
}
|
26
28
|
}
|
27
29
|
}
|
28
30
|
|
29
|
-
export class TextPathNode extends JsiDrawingNode<
|
31
|
+
export class TextPathNode extends JsiDrawingNode<
|
32
|
+
TextPathProps,
|
33
|
+
SkTextBlob | null
|
34
|
+
> {
|
30
35
|
constructor(ctx: NodeContext, props: TextPathProps) {
|
31
36
|
super(ctx, NodeType.TextPath, props);
|
32
37
|
}
|
@@ -34,6 +39,9 @@ export class TextPathNode extends JsiDrawingNode<TextPathProps, SkTextBlob> {
|
|
34
39
|
deriveProps() {
|
35
40
|
const path = processPath(this.Skia, this.props.path);
|
36
41
|
const { font, initialOffset } = this.props;
|
42
|
+
if (!font) {
|
43
|
+
return null;
|
44
|
+
}
|
37
45
|
let { text } = this.props;
|
38
46
|
const ids = font.getGlyphIDs(text);
|
39
47
|
const widths = font.getGlyphWidths(ids);
|
@@ -117,6 +125,8 @@ export class GlyphsNode extends JsiDrawingNode<GlyphsProps, ProcessedGlyphs> {
|
|
117
125
|
}
|
118
126
|
const { glyphs, positions } = this.derived;
|
119
127
|
const { x, y, font } = this.props;
|
120
|
-
|
128
|
+
if (font) {
|
129
|
+
canvas.drawGlyphs(glyphs, positions, x, y, font, paint);
|
130
|
+
}
|
121
131
|
}
|
122
132
|
}
|
@@ -60,6 +60,10 @@ export class ImageShaderNode extends ShaderDeclaration<ImageShaderProps> {
|
|
60
60
|
|
61
61
|
decorate(ctx: DeclarationContext) {
|
62
62
|
const { fit, image, tx, ty, fm, mm, ...imageShaderProps } = this.props;
|
63
|
+
if (!image) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
63
67
|
const rct = getRect(this.Skia, imageShaderProps);
|
64
68
|
const m3 = this.Skia.Matrix();
|
65
69
|
if (rct) {
|
@@ -35,7 +35,7 @@ export interface DrawingNodeProps extends GroupProps {
|
|
35
35
|
export type ImageProps = DrawingNodeProps &
|
36
36
|
RectDef & {
|
37
37
|
fit?: Fit;
|
38
|
-
image: SkImage;
|
38
|
+
image: SkImage | null;
|
39
39
|
};
|
40
40
|
|
41
41
|
export type CircleProps = CircleDef & DrawingNodeProps;
|
@@ -91,7 +91,7 @@ export interface VerticesProps extends DrawingNodeProps {
|
|
91
91
|
}
|
92
92
|
|
93
93
|
export type ImageSVGProps = RectDef & {
|
94
|
-
svg: SkSVG;
|
94
|
+
svg: SkSVG | null;
|
95
95
|
} & DrawingNodeProps;
|
96
96
|
|
97
97
|
export interface PictureProps extends DrawingNodeProps {
|
@@ -109,14 +109,14 @@ export interface DiffRectProps extends DrawingNodeProps {
|
|
109
109
|
}
|
110
110
|
|
111
111
|
export interface TextProps extends DrawingNodeProps {
|
112
|
-
font: SkFont;
|
112
|
+
font: SkFont | null;
|
113
113
|
text: string;
|
114
114
|
x: number;
|
115
115
|
y: number;
|
116
116
|
}
|
117
117
|
|
118
118
|
export interface TextPathProps extends DrawingNodeProps {
|
119
|
-
font: SkFont;
|
119
|
+
font: SkFont | null;
|
120
120
|
text: string;
|
121
121
|
path: PathDef;
|
122
122
|
initialOffset: number;
|
@@ -134,7 +134,7 @@ export interface Glyph {
|
|
134
134
|
}
|
135
135
|
|
136
136
|
export interface GlyphsProps extends DrawingNodeProps {
|
137
|
-
font: SkFont;
|
137
|
+
font: SkFont | null;
|
138
138
|
x: number;
|
139
139
|
y: number;
|
140
140
|
glyphs: Glyph[];
|
package/src/dom/types/Shaders.ts
CHANGED
package/src/mock/index.ts
CHANGED
package/src/skia/core/Image.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
import { findNodeHandle, Platform } from "react-native";
|
2
|
+
|
1
3
|
import { Skia } from "../Skia";
|
2
|
-
import type { DataSourceParam } from "../types";
|
4
|
+
import type { DataSourceParam, SkImage } from "../types";
|
3
5
|
|
4
6
|
import { useRawData } from "./Data";
|
5
7
|
|
@@ -12,3 +14,43 @@ export const useImage = (
|
|
12
14
|
source: DataSourceParam,
|
13
15
|
onError?: (err: Error) => void
|
14
16
|
) => useRawData(source, imgFactory, onError);
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Creates an image from a given view reference. NOTE: This method has different implementations
|
20
|
+
* on web/native. On web, the callback is called with the view ref and the callback is expected to
|
21
|
+
* return a promise that resolves to a Skia Image object. On native, the view ref is used to
|
22
|
+
* find the view tag and the Skia Image object is created from the view tag. This means that on web
|
23
|
+
* you will need to implement the logic to create the image from the view ref yourself.
|
24
|
+
* @param viewRef Ref to the view we're creating an image from
|
25
|
+
* @returns A promise that resolves to a Skia Image object or rejects
|
26
|
+
* with an error id the view tag is invalid.
|
27
|
+
*/
|
28
|
+
export const makeImageFromView = <
|
29
|
+
T extends
|
30
|
+
| number
|
31
|
+
| React.Component<unknown, unknown>
|
32
|
+
| React.ComponentClass<unknown>
|
33
|
+
>(
|
34
|
+
viewRef: React.RefObject<T>,
|
35
|
+
callback:
|
36
|
+
| null
|
37
|
+
| ((viewRef: React.RefObject<T>) => Promise<SkImage | null>) = null
|
38
|
+
) => {
|
39
|
+
// In web implementation we just delegate the work to the provided callback
|
40
|
+
if (Platform.OS === "web") {
|
41
|
+
if (callback) {
|
42
|
+
return callback(viewRef);
|
43
|
+
} else {
|
44
|
+
Promise.reject(
|
45
|
+
new Error(
|
46
|
+
"Callback is required on web in the makeImageFromView function."
|
47
|
+
)
|
48
|
+
);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
const viewTag = findNodeHandle(viewRef.current);
|
52
|
+
if (viewTag !== null && viewTag !== 0) {
|
53
|
+
return Skia.Image.MakeImageFromViewTag(viewTag);
|
54
|
+
}
|
55
|
+
return Promise.reject(new Error("Invalid view tag"));
|
56
|
+
};
|
@@ -63,6 +63,14 @@ export interface ImageFactory {
|
|
63
63
|
*/
|
64
64
|
MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
|
65
65
|
|
66
|
+
/**
|
67
|
+
* Returns an image that will be a screenshot of the view represented by
|
68
|
+
* the view tag
|
69
|
+
* @param viewTag - The tag of the view to make an image from.
|
70
|
+
* @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.
|
71
|
+
*/
|
72
|
+
MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;
|
73
|
+
|
66
74
|
/**
|
67
75
|
* Returns an image with the given pixel data and format.
|
68
76
|
* Note that we will always make a copy of the pixel data, because of inconsistencies in
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { CanvasKit } from "canvaskit-wasm";
|
2
2
|
|
3
|
-
import type { SkData, ImageInfo } from "../types";
|
3
|
+
import type { SkData, ImageInfo, SkImage } from "../types";
|
4
4
|
import type { ImageFactory } from "../types/Image/ImageFactory";
|
5
5
|
|
6
6
|
import { Host, ckEnum } from "./Host";
|
@@ -12,6 +12,13 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
12
12
|
super(CanvasKit);
|
13
13
|
}
|
14
14
|
|
15
|
+
MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {
|
16
|
+
const view = viewTag as unknown as HTMLElement;
|
17
|
+
// TODO: Implement screenshot from view in React JS
|
18
|
+
console.log(view);
|
19
|
+
return Promise.resolve(null);
|
20
|
+
}
|
21
|
+
|
15
22
|
MakeImageFromEncoded(encoded: SkData) {
|
16
23
|
const image = this.CanvasKit.MakeImageFromEncoded(
|
17
24
|
JsiSkData.fromValue(encoded)
|