@shopify/react-native-skia 0.1.184 → 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 +8 -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 +10 -8
- 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 +9 -6
- 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/Image.d.ts +6 -0
- package/lib/commonjs/skia/types/Image/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/JsiSkImage.d.ts +1 -0
- package/lib/commonjs/skia/web/JsiSkImage.js +4 -0
- package/lib/commonjs/skia/web/JsiSkImage.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/Image.d.ts +6 -0
- package/lib/module/skia/types/Image/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/JsiSkImage.d.ts +1 -0
- package/lib/module/skia/web/JsiSkImage.js +4 -0
- package/lib/module/skia/web/JsiSkImage.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/Image.d.ts +6 -0
- 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/JsiSkImage.d.ts +1 -0
- 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/Image.ts +7 -0
- package/src/skia/types/Image/ImageFactory.ts +8 -0
- package/src/skia/types/SVG/SVG.ts +4 -1
- package/src/skia/web/JsiSkImage.ts +7 -0
- package/src/skia/web/JsiSkImageFactory.ts +8 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Host","ckEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromEncoded","encoded","image","fromValue","MakeImage","info","data","bytesPerRow","alphaType","colorSpace","ColorSpace","SRGB","colorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type { SkData, ImageInfo } from \"../types\";\nimport type { ImageFactory } from \"../types/Image/ImageFactory\";\n\nimport { Host, ckEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: ckEnum(info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: ckEnum(info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"AAKA,SAASA,IAAT,EAAeC,MAAf,QAA6B,QAA7B;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,SAASC,SAAT,QAA0B,aAA1B;AAEA,OAAO,MAAMC,iBAAN,SAAgCJ,IAAhC,CAA6D;EAClEK,WAAW,CAACC,SAAD,EAAuB;IAChC,MAAMA,SAAN;EACD;;EAEDC,oBAAoB,CAACC,OAAD,EAAkB;IACpC,MAAMC,KAAK,GAAG,
|
1
|
+
{"version":3,"names":["Host","ckEnum","JsiSkImage","JsiSkData","JsiSkImageFactory","constructor","CanvasKit","MakeImageFromViewTag","viewTag","view","console","log","Promise","resolve","MakeImageFromEncoded","encoded","image","fromValue","MakeImage","info","data","bytesPerRow","alphaType","colorSpace","ColorSpace","SRGB","colorType","height","width"],"sources":["JsiSkImageFactory.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport type { SkData, ImageInfo, SkImage } from \"../types\";\nimport type { ImageFactory } from \"../types/Image/ImageFactory\";\n\nimport { Host, ckEnum } from \"./Host\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkData } from \"./JsiSkData\";\n\nexport class JsiSkImageFactory extends Host implements ImageFactory {\n constructor(CanvasKit: CanvasKit) {\n super(CanvasKit);\n }\n\n MakeImageFromViewTag(viewTag: number): Promise<SkImage | null> {\n const view = viewTag as unknown as HTMLElement;\n // TODO: Implement screenshot from view in React JS\n console.log(view);\n return Promise.resolve(null);\n }\n\n MakeImageFromEncoded(encoded: SkData) {\n const image = this.CanvasKit.MakeImageFromEncoded(\n JsiSkData.fromValue(encoded)\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {\n // see toSkImageInfo() from canvaskit\n const image = this.CanvasKit.MakeImage(\n {\n alphaType: ckEnum(info.alphaType),\n colorSpace: this.CanvasKit.ColorSpace.SRGB,\n colorType: ckEnum(info.colorType),\n height: info.height,\n width: info.width,\n },\n JsiSkData.fromValue(data),\n bytesPerRow\n );\n if (image === null) {\n return null;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n}\n"],"mappings":"AAKA,SAASA,IAAT,EAAeC,MAAf,QAA6B,QAA7B;AACA,SAASC,UAAT,QAA2B,cAA3B;AACA,SAASC,SAAT,QAA0B,aAA1B;AAEA,OAAO,MAAMC,iBAAN,SAAgCJ,IAAhC,CAA6D;EAClEK,WAAW,CAACC,SAAD,EAAuB;IAChC,MAAMA,SAAN;EACD;;EAEDC,oBAAoB,CAACC,OAAD,EAA2C;IAC7D,MAAMC,IAAI,GAAGD,OAAb,CAD6D,CAE7D;;IACAE,OAAO,CAACC,GAAR,CAAYF,IAAZ;IACA,OAAOG,OAAO,CAACC,OAAR,CAAgB,IAAhB,CAAP;EACD;;EAEDC,oBAAoB,CAACC,OAAD,EAAkB;IACpC,MAAMC,KAAK,GAAG,KAAKV,SAAL,CAAeQ,oBAAf,CACZX,SAAS,CAACc,SAAV,CAAoBF,OAApB,CADY,CAAd;;IAGA,IAAIC,KAAK,KAAK,IAAd,EAAoB;MAClB,OAAO,IAAP;IACD;;IACD,OAAO,IAAId,UAAJ,CAAe,KAAKI,SAApB,EAA+BU,KAA/B,CAAP;EACD;;EAEDE,SAAS,CAACC,IAAD,EAAkBC,IAAlB,EAAgCC,WAAhC,EAAqD;IAC5D;IACA,MAAML,KAAK,GAAG,KAAKV,SAAL,CAAeY,SAAf,CACZ;MACEI,SAAS,EAAErB,MAAM,CAACkB,IAAI,CAACG,SAAN,CADnB;MAEEC,UAAU,EAAE,KAAKjB,SAAL,CAAekB,UAAf,CAA0BC,IAFxC;MAGEC,SAAS,EAAEzB,MAAM,CAACkB,IAAI,CAACO,SAAN,CAHnB;MAIEC,MAAM,EAAER,IAAI,CAACQ,MAJf;MAKEC,KAAK,EAAET,IAAI,CAACS;IALd,CADY,EAQZzB,SAAS,CAACc,SAAV,CAAoBG,IAApB,CARY,EASZC,WATY,CAAd;;IAWA,IAAIL,KAAK,KAAK,IAAd,EAAoB;MAClB,OAAO,IAAP;IACD;;IACD,OAAO,IAAId,UAAJ,CAAe,KAAKI,SAApB,EAA+BU,KAA/B,CAAP;EACD;;AAvCiE"}
|
@@ -8,9 +8,9 @@ export declare class TextNode extends JsiDrawingNode<TextProps, null> {
|
|
8
8
|
protected deriveProps(): null;
|
9
9
|
draw({ canvas, paint }: DrawingContext): void;
|
10
10
|
}
|
11
|
-
export declare class TextPathNode extends JsiDrawingNode<TextPathProps, SkTextBlob> {
|
11
|
+
export declare class TextPathNode extends JsiDrawingNode<TextPathProps, SkTextBlob | null> {
|
12
12
|
constructor(ctx: NodeContext, props: TextPathProps);
|
13
|
-
deriveProps(): SkTextBlob;
|
13
|
+
deriveProps(): SkTextBlob | null;
|
14
14
|
draw({ canvas, paint }: DrawingContext): void;
|
15
15
|
}
|
16
16
|
export declare class TextBlobNode extends JsiDrawingNode<TextBlobProps, null> {
|
@@ -6,7 +6,7 @@ export interface DrawingNodeProps extends GroupProps {
|
|
6
6
|
}
|
7
7
|
export declare type ImageProps = DrawingNodeProps & RectDef & {
|
8
8
|
fit?: Fit;
|
9
|
-
image: SkImage;
|
9
|
+
image: SkImage | null;
|
10
10
|
};
|
11
11
|
export declare type CircleProps = CircleDef & DrawingNodeProps;
|
12
12
|
export interface PathProps extends DrawingNodeProps {
|
@@ -51,7 +51,7 @@ export interface VerticesProps extends DrawingNodeProps {
|
|
51
51
|
indices?: number[];
|
52
52
|
}
|
53
53
|
export declare type ImageSVGProps = RectDef & {
|
54
|
-
svg: SkSVG;
|
54
|
+
svg: SkSVG | null;
|
55
55
|
} & DrawingNodeProps;
|
56
56
|
export interface PictureProps extends DrawingNodeProps {
|
57
57
|
picture: SkPicture;
|
@@ -65,13 +65,13 @@ export interface DiffRectProps extends DrawingNodeProps {
|
|
65
65
|
outer: SkRRect;
|
66
66
|
}
|
67
67
|
export interface TextProps extends DrawingNodeProps {
|
68
|
-
font: SkFont;
|
68
|
+
font: SkFont | null;
|
69
69
|
text: string;
|
70
70
|
x: number;
|
71
71
|
y: number;
|
72
72
|
}
|
73
73
|
export interface TextPathProps extends DrawingNodeProps {
|
74
|
-
font: SkFont;
|
74
|
+
font: SkFont | null;
|
75
75
|
text: string;
|
76
76
|
path: PathDef;
|
77
77
|
initialOffset: number;
|
@@ -86,7 +86,7 @@ export interface Glyph {
|
|
86
86
|
pos: SkPoint;
|
87
87
|
}
|
88
88
|
export interface GlyphsProps extends DrawingNodeProps {
|
89
|
-
font: SkFont;
|
89
|
+
font: SkFont | null;
|
90
90
|
x: number;
|
91
91
|
y: number;
|
92
92
|
glyphs: Glyph[];
|
@@ -1,5 +1,17 @@
|
|
1
|
-
|
1
|
+
/// <reference types="react" />
|
2
|
+
import type { DataSourceParam, SkImage } from "../types";
|
2
3
|
/**
|
3
4
|
* Returns a Skia Image object
|
4
5
|
* */
|
5
|
-
export declare const useImage: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) =>
|
6
|
+
export declare const useImage: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkImage | null;
|
7
|
+
/**
|
8
|
+
* Creates an image from a given view reference. NOTE: This method has different implementations
|
9
|
+
* on web/native. On web, the callback is called with the view ref and the callback is expected to
|
10
|
+
* return a promise that resolves to a Skia Image object. On native, the view ref is used to
|
11
|
+
* find the view tag and the Skia Image object is created from the view tag. This means that on web
|
12
|
+
* you will need to implement the logic to create the image from the view ref yourself.
|
13
|
+
* @param viewRef Ref to the view we're creating an image from
|
14
|
+
* @returns A promise that resolves to a Skia Image object or rejects
|
15
|
+
* with an error id the view tag is invalid.
|
16
|
+
*/
|
17
|
+
export declare const makeImageFromView: <T extends number | import("react").Component<unknown, unknown, any> | import("react").ComponentClass<unknown, any>>(viewRef: import("react").RefObject<T>, callback?: ((viewRef: import("react").RefObject<T>) => Promise<SkImage | null>) | null) => Promise<SkImage | null>;
|
@@ -72,4 +72,10 @@ export interface SkImage extends SkJSIInstance<"Image">, JsiDisposable {
|
|
72
72
|
@return base64 encoded string of data
|
73
73
|
*/
|
74
74
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
75
|
+
/**
|
76
|
+
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
77
|
+
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
78
|
+
* bitmap, or if encoded in a stream.
|
79
|
+
*/
|
80
|
+
makeNonTextureImage(): SkImage;
|
75
81
|
}
|
@@ -48,6 +48,13 @@ export interface ImageFactory {
|
|
48
48
|
* image, nullptr is returned.
|
49
49
|
*/
|
50
50
|
MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
|
51
|
+
/**
|
52
|
+
* Returns an image that will be a screenshot of the view represented by
|
53
|
+
* the view tag
|
54
|
+
* @param viewTag - The tag of the view to make an image from.
|
55
|
+
* @returns Returns a valid SkImage, if the view tag is invalid, nullptr is returned.
|
56
|
+
*/
|
57
|
+
MakeImageFromViewTag: (viewTag: number) => Promise<SkImage | null>;
|
51
58
|
/**
|
52
59
|
* Returns an image with the given pixel data and format.
|
53
60
|
* Note that we will always make a copy of the pixel data, because of inconsistencies in
|
@@ -11,4 +11,5 @@ export declare class JsiSkImage extends HostObject<Image, "Image"> implements Sk
|
|
11
11
|
encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;
|
12
12
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
13
13
|
dispose(): void;
|
14
|
+
makeNonTextureImage(): SkImage;
|
14
15
|
}
|
@@ -1,10 +1,11 @@
|
|
1
1
|
import type { CanvasKit } from "canvaskit-wasm";
|
2
|
-
import type { SkData, ImageInfo } from "../types";
|
2
|
+
import type { SkData, ImageInfo, SkImage } from "../types";
|
3
3
|
import type { ImageFactory } from "../types/Image/ImageFactory";
|
4
4
|
import { Host } from "./Host";
|
5
5
|
import { JsiSkImage } from "./JsiSkImage";
|
6
6
|
export declare class JsiSkImageFactory extends Host implements ImageFactory {
|
7
7
|
constructor(CanvasKit: CanvasKit);
|
8
|
+
MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
|
8
9
|
MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
|
9
10
|
MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
|
10
11
|
}
|
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.
|
10
|
+
"version": "0.1.186",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"files": [
|
@@ -88,7 +88,7 @@
|
|
88
88
|
"jest": "28.1.3",
|
89
89
|
"merge-dirs": "^0.2.1",
|
90
90
|
"react": "18.1.0",
|
91
|
-
"react-native": "0.71.
|
91
|
+
"react-native": "0.71.7",
|
92
92
|
"react-native-builder-bob": "^0.18.2",
|
93
93
|
"ts-jest": "^28.0.7",
|
94
94
|
"typescript": "4.8.3"
|
package/scripts/install-npm.js
CHANGED
@@ -8,9 +8,10 @@ const createSymlink = (p) => {
|
|
8
8
|
const srcDir = path.resolve(`./cpp/${p}`);
|
9
9
|
const dstDir = path.resolve(`./android/cpp/${p}`);
|
10
10
|
|
11
|
-
if (
|
12
|
-
fs.
|
11
|
+
if (fs.existsSync(dstDir)) {
|
12
|
+
fs.unlinkSync(dstDir);
|
13
13
|
}
|
14
|
+
fs.symlinkSync(srcDir, dstDir, "junction");
|
14
15
|
};
|
15
16
|
|
16
17
|
// Copy common cpp files from the package root to the android folder
|
@@ -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
|
+
};
|
@@ -93,4 +93,11 @@ export interface SkImage extends SkJSIInstance<"Image">, JsiDisposable {
|
|
93
93
|
@return base64 encoded string of data
|
94
94
|
*/
|
95
95
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Returns raster image or lazy image. Copies SkImage backed by GPU texture
|
99
|
+
* into CPU memory if needed. Returns original SkImage if decoded in raster
|
100
|
+
* bitmap, or if encoded in a stream.
|
101
|
+
*/
|
102
|
+
makeNonTextureImage(): SkImage;
|
96
103
|
}
|
@@ -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
|
@@ -113,4 +113,11 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
113
113
|
dispose() {
|
114
114
|
this.ref.delete();
|
115
115
|
}
|
116
|
+
|
117
|
+
makeNonTextureImage(): SkImage {
|
118
|
+
return new JsiSkImage(
|
119
|
+
this.CanvasKit,
|
120
|
+
this.CanvasKit.MakeImageFromEncoded(this.encodeToBytes())!
|
121
|
+
);
|
122
|
+
}
|
116
123
|
}
|
@@ -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)
|