@shopify/react-native-skia 0.1.115 → 0.1.119
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/README.md +39 -2
- package/cpp/api/JsiSkApi.h +13 -9
- package/cpp/api/JsiSkCanvas.h +9 -1
- package/cpp/api/JsiSkPicture.h +71 -0
- package/cpp/api/JsiSkPictureFactory.h +50 -0
- package/cpp/api/JsiSkPictureRecorder.h +53 -0
- package/lib/commonjs/renderer/Canvas.js +22 -36
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/HostConfig.js +3 -25
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/renderer/components/{Defs.js → Drawing.js} +13 -12
- package/lib/commonjs/renderer/components/Drawing.js.map +1 -0
- package/lib/commonjs/renderer/components/Group.js +31 -20
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +1 -21
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/components/Picture.js +35 -0
- package/lib/commonjs/renderer/components/Picture.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +5 -34
- package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/commonjs/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +19 -8
- package/lib/commonjs/renderer/components/imageFilters/Shadow.js.map +1 -0
- package/lib/commonjs/renderer/components/imageFilters/index.js +4 -17
- package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/commonjs/renderer/components/index.js +17 -4
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/renderer/components/maskFilters/Blur.js +1 -1
- package/lib/commonjs/renderer/components/maskFilters/Blur.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Box.js +126 -0
- package/lib/commonjs/renderer/components/shapes/Box.js.map +1 -0
- package/lib/commonjs/renderer/components/shapes/FitBox.js +9 -5
- package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/index.js +13 -0
- package/lib/commonjs/renderer/components/shapes/index.js.map +1 -1
- package/lib/commonjs/renderer/index.js +13 -0
- package/lib/commonjs/renderer/index.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Declaration.js +12 -1
- package/lib/commonjs/renderer/nodes/Declaration.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Drawing.js +9 -24
- package/lib/commonjs/renderer/nodes/Drawing.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Node.js +9 -16
- package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
- package/lib/commonjs/renderer/processors/Paint.js +24 -26
- package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Math.js +19 -1
- package/lib/commonjs/renderer/processors/math/Math.js.map +1 -1
- package/lib/commonjs/renderer/processors/math/Matrix3.js +11 -5
- package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/commonjs/renderer/typeddash.js +26 -2
- package/lib/commonjs/renderer/typeddash.js.map +1 -1
- package/lib/commonjs/renderer/useContextBridge.js +35 -0
- package/lib/commonjs/renderer/useContextBridge.js.map +1 -0
- package/lib/commonjs/skia/Canvas.js.map +1 -1
- package/lib/commonjs/skia/Picture/Picture.js +6 -0
- package/lib/commonjs/skia/Picture/Picture.js.map +1 -0
- package/lib/commonjs/skia/Picture/PictureFactory.js +6 -0
- package/lib/commonjs/skia/Picture/PictureFactory.js.map +1 -0
- package/lib/commonjs/skia/Picture/PictureRecorder.js +6 -0
- package/lib/commonjs/skia/Picture/PictureRecorder.js.map +1 -0
- package/lib/commonjs/skia/Picture/index.js +58 -0
- package/lib/commonjs/skia/Picture/index.js.map +1 -0
- package/lib/commonjs/skia/Picture/usePicture.js +30 -0
- package/lib/commonjs/skia/Picture/usePicture.js.map +1 -0
- package/lib/commonjs/skia/Skia.js +2 -0
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/commonjs/skia/index.js +28 -0
- package/lib/commonjs/skia/index.js.map +1 -1
- package/lib/commonjs/values/hooks/useDerivedValue.js +2 -2
- package/lib/commonjs/values/hooks/useDerivedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +6 -44
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.js +20 -32
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +2 -24
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/renderer/components/Drawing.js +17 -0
- package/lib/module/renderer/components/Drawing.js.map +1 -0
- package/lib/module/renderer/components/Group.js +32 -22
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +2 -22
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/components/Picture.js +21 -0
- package/lib/module/renderer/components/Picture.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/InnerShadow.js +4 -26
- package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
- package/lib/module/renderer/components/imageFilters/{DropShadow.js → Shadow.js} +16 -6
- package/lib/module/renderer/components/imageFilters/Shadow.js.map +1 -0
- package/lib/module/renderer/components/imageFilters/index.js +1 -2
- package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
- package/lib/module/renderer/components/index.js +2 -1
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/renderer/components/maskFilters/Blur.js +1 -1
- package/lib/module/renderer/components/maskFilters/Blur.js.map +1 -1
- package/lib/module/renderer/components/shapes/Box.js +102 -0
- package/lib/module/renderer/components/shapes/Box.js.map +1 -0
- package/lib/module/renderer/components/shapes/FitBox.js +5 -4
- package/lib/module/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/module/renderer/components/shapes/index.js +1 -0
- package/lib/module/renderer/components/shapes/index.js.map +1 -1
- package/lib/module/renderer/index.js +1 -0
- package/lib/module/renderer/index.js.map +1 -1
- package/lib/module/renderer/nodes/Declaration.js +4 -0
- package/lib/module/renderer/nodes/Declaration.js.map +1 -1
- package/lib/module/renderer/nodes/Drawing.js +8 -21
- package/lib/module/renderer/nodes/Drawing.js.map +1 -1
- package/lib/module/renderer/nodes/Node.js +9 -15
- package/lib/module/renderer/nodes/Node.js.map +1 -1
- package/lib/module/renderer/processors/Paint.js +22 -21
- package/lib/module/renderer/processors/Paint.js.map +1 -1
- package/lib/module/renderer/processors/math/Math.js +15 -0
- package/lib/module/renderer/processors/math/Math.js.map +1 -1
- package/lib/module/renderer/processors/math/Matrix3.js +6 -2
- package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
- package/lib/module/renderer/typeddash.js +21 -0
- package/lib/module/renderer/typeddash.js.map +1 -1
- package/lib/module/renderer/useContextBridge.js +21 -0
- package/lib/module/renderer/useContextBridge.js.map +1 -0
- package/lib/module/skia/Canvas.js.map +1 -1
- package/lib/module/skia/Picture/Picture.js +2 -0
- package/lib/module/skia/Picture/Picture.js.map +1 -0
- package/lib/module/skia/Picture/PictureFactory.js +2 -0
- package/lib/module/skia/Picture/PictureFactory.js.map +1 -0
- package/lib/module/skia/Picture/PictureRecorder.js +2 -0
- package/lib/module/skia/Picture/PictureRecorder.js.map +1 -0
- package/lib/module/skia/Picture/index.js +5 -0
- package/lib/module/skia/Picture/index.js.map +1 -0
- package/lib/module/skia/Picture/usePicture.js +19 -0
- package/lib/module/skia/Picture/usePicture.js.map +1 -0
- package/lib/module/skia/Skia.js +2 -0
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/module/skia/index.js +2 -0
- package/lib/module/skia/index.js.map +1 -1
- package/lib/module/values/hooks/useDerivedValue.js +1 -1
- package/lib/module/values/hooks/useDerivedValue.js.map +1 -1
- package/lib/module/views/SkiaView.js +6 -44
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +5 -10
- package/lib/typescript/src/renderer/components/Drawing.d.ts +7 -0
- package/lib/typescript/src/renderer/components/Picture.d.ts +6 -0
- package/lib/typescript/src/renderer/components/imageFilters/InnerShadow.d.ts +3 -12
- package/lib/typescript/src/renderer/components/imageFilters/{DropShadow.d.ts → Shadow.d.ts} +3 -2
- package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -2
- package/lib/typescript/src/renderer/components/index.d.ts +2 -1
- package/lib/typescript/src/renderer/components/shapes/Box.d.ts +23 -0
- package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +9 -0
- package/lib/typescript/src/renderer/components/shapes/index.d.ts +1 -0
- package/lib/typescript/src/renderer/index.d.ts +1 -0
- package/lib/typescript/src/renderer/nodes/Declaration.d.ts +3 -0
- package/lib/typescript/src/renderer/nodes/Drawing.d.ts +2 -2
- package/lib/typescript/src/renderer/nodes/Node.d.ts +2 -2
- package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -2
- package/lib/typescript/src/renderer/processors/math/Math.d.ts +14 -0
- package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -0
- package/lib/typescript/src/renderer/typeddash.d.ts +1 -0
- package/lib/typescript/src/renderer/useContextBridge.d.ts +5 -0
- package/lib/typescript/src/skia/Canvas.d.ts +6 -0
- package/lib/typescript/src/skia/Picture/Picture.d.ts +26 -0
- package/lib/typescript/src/skia/Picture/PictureFactory.d.ts +8 -0
- package/lib/typescript/src/skia/Picture/PictureRecorder.d.ts +15 -0
- package/lib/typescript/src/skia/Picture/index.d.ts +4 -0
- package/lib/typescript/src/skia/Picture/usePicture.d.ts +11 -0
- package/lib/typescript/src/skia/Skia.d.ts +5 -0
- package/lib/typescript/src/skia/index.d.ts +2 -0
- package/lib/typescript/src/views/SkiaView.d.ts +28 -13
- package/lib/typescript/src/views/types.d.ts +0 -23
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
- package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
- package/libs/ios/libsvg.xcframework/Info.plist +5 -5
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
- package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
- package/package.json +7 -7
- package/src/renderer/Canvas.tsx +14 -30
- package/src/renderer/HostConfig.ts +2 -20
- package/src/renderer/components/Drawing.tsx +16 -0
- package/src/renderer/components/Group.tsx +44 -27
- package/src/renderer/components/Paint.tsx +5 -35
- package/src/renderer/components/Picture.tsx +17 -0
- package/src/renderer/components/imageFilters/InnerShadow.tsx +33 -47
- package/src/renderer/components/imageFilters/Shadow.tsx +39 -0
- package/src/renderer/components/imageFilters/index.ts +1 -2
- package/src/renderer/components/index.ts +2 -1
- package/src/renderer/components/maskFilters/Blur.tsx +1 -1
- package/src/renderer/components/shapes/Box.tsx +98 -0
- package/src/renderer/components/shapes/FitBox.tsx +6 -4
- package/src/renderer/components/shapes/index.ts +1 -0
- package/src/renderer/index.ts +1 -0
- package/src/renderer/nodes/Declaration.tsx +14 -0
- package/src/renderer/nodes/Drawing.tsx +16 -26
- package/src/renderer/nodes/Node.ts +9 -12
- package/src/renderer/processors/Paint.ts +34 -31
- package/src/renderer/processors/math/Math.ts +16 -0
- package/src/renderer/processors/math/Matrix3.ts +35 -31
- package/src/renderer/typeddash.ts +18 -0
- package/src/renderer/useContextBridge.tsx +21 -0
- package/src/skia/Canvas.ts +7 -0
- package/src/skia/Picture/Picture.ts +34 -0
- package/src/skia/Picture/PictureFactory.ts +9 -0
- package/src/skia/Picture/PictureRecorder.ts +18 -0
- package/src/skia/Picture/index.ts +4 -0
- package/src/skia/Picture/usePicture.ts +28 -0
- package/src/skia/Skia.ts +5 -0
- package/src/skia/index.ts +2 -0
- package/src/values/hooks/useDerivedValue.ts +1 -1
- package/src/views/SkiaView.tsx +31 -41
- package/src/views/types.ts +0 -24
- package/lib/commonjs/renderer/components/Defs.js.map +0 -1
- package/lib/commonjs/renderer/components/imageFilters/DropShadow.js.map +0 -1
- package/lib/module/renderer/components/Defs.js +0 -16
- package/lib/module/renderer/components/Defs.js.map +0 -1
- package/lib/module/renderer/components/imageFilters/DropShadow.js.map +0 -1
- package/lib/typescript/src/renderer/components/Defs.d.ts +0 -5
- package/src/renderer/components/Defs.tsx +0 -19
- package/src/renderer/components/imageFilters/DropShadow.tsx +0 -31
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode, RefObject } from "react";
|
|
2
2
|
import { BlendMode, PaintStyle, StrokeJoin, StrokeCap } from "../../skia";
|
|
3
3
|
import type { SkPaint, Color } from "../../skia";
|
|
4
|
+
import type { DeclarationResult } from "../nodes";
|
|
4
5
|
export declare type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
|
|
5
6
|
export interface ChildrenProps {
|
|
6
7
|
children?: ReactNode | ReactNode[];
|
|
@@ -17,5 +18,4 @@ export interface CustomPaintProps extends ChildrenProps {
|
|
|
17
18
|
opacity?: number;
|
|
18
19
|
}
|
|
19
20
|
export declare const enumKey: <K extends string>(k: K) => Capitalize<K>;
|
|
20
|
-
export declare const processPaint: (paint: SkPaint, currentOpacity: number, { color, blendMode, style, strokeWidth, strokeJoin, strokeCap, strokeMiter, opacity, }: CustomPaintProps) =>
|
|
21
|
-
export declare const selectPaint: (currentPaint: SkPaint, { paint, color: cl, blendMode, style: paintStyle, strokeWidth, strokeJoin, strokeCap, strokeMiter, opacity, }: CustomPaintProps) => SkPaint;
|
|
21
|
+
export declare const processPaint: (paint: SkPaint, currentOpacity: number, { paint: paintRef, color, blendMode, style, strokeWidth, strokeJoin, strokeCap, strokeMiter, opacity, }: CustomPaintProps, children: DeclarationResult[]) => SkPaint;
|
|
@@ -1 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Linear interpolation
|
|
3
|
+
* @param value
|
|
4
|
+
* @param x
|
|
5
|
+
* @param y
|
|
6
|
+
*/
|
|
1
7
|
export declare const mix: (value: number, x: number, y: number) => number;
|
|
8
|
+
/**
|
|
9
|
+
* @summary Clamps a node with a lower and upper bound.
|
|
10
|
+
* @example
|
|
11
|
+
clamp(-1, 0, 100); // 0
|
|
12
|
+
clamp(1, 0, 100); // 1
|
|
13
|
+
clamp(101, 0, 100); // 100
|
|
14
|
+
*/
|
|
15
|
+
export declare const clamp: (value: number, lowerBound: number, upperBound: number) => number;
|
|
@@ -9,5 +9,6 @@ declare type Transformations = {
|
|
|
9
9
|
readonly [Name in Transform2dName]: number;
|
|
10
10
|
};
|
|
11
11
|
export declare type Transforms2d = readonly (Pick<Transformations, "translateX"> | Pick<Transformations, "translateY"> | Pick<Transformations, "scale"> | Pick<Transformations, "scaleX"> | Pick<Transformations, "scaleY"> | Pick<Transformations, "skewX"> | Pick<Transformations, "skewY"> | Pick<Transformations, "rotate">)[];
|
|
12
|
+
export declare const matrixVecMul3: (m: Matrix3, v: Vec3) => readonly [number, number, number];
|
|
12
13
|
export declare const processTransform2d: (transforms: Transforms2d) => SkMatrix;
|
|
13
14
|
export {};
|
|
@@ -12,6 +12,7 @@ import type { SkMatrix } from "./Matrix";
|
|
|
12
12
|
import type { SkImageFilter } from "./ImageFilter";
|
|
13
13
|
import type { SkVertices } from "./Vertices";
|
|
14
14
|
import type { SkTextBlob } from "./TextBlob";
|
|
15
|
+
import type { SkPicture } from "./Picture";
|
|
15
16
|
export declare enum ClipOp {
|
|
16
17
|
Difference = 0,
|
|
17
18
|
Intersect = 1
|
|
@@ -372,4 +373,9 @@ export interface SkCanvas {
|
|
|
372
373
|
* @param m
|
|
373
374
|
*/
|
|
374
375
|
concat(m: SkMatrix): void;
|
|
376
|
+
/**
|
|
377
|
+
* Draws the given picture using the current clip, current matrix, and the provided paint.
|
|
378
|
+
* @param skp
|
|
379
|
+
*/
|
|
380
|
+
drawPicture(skp: SkPicture): void;
|
|
375
381
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { InputColorMatrix } from "../ColorFilter";
|
|
2
|
+
import type { FilterMode } from "../Image";
|
|
3
|
+
import type { TileMode } from "../ImageFilter";
|
|
4
|
+
import type { SkRect } from "../Rect";
|
|
5
|
+
import type { IShader } from "../Shader";
|
|
6
|
+
export interface SkPicture {
|
|
7
|
+
/**
|
|
8
|
+
* Returns a new shader that will draw with this picture.
|
|
9
|
+
*
|
|
10
|
+
* @param tmx The tiling mode to use when sampling in the x-direction.
|
|
11
|
+
* @param tmy The tiling mode to use when sampling in the y-direction.
|
|
12
|
+
* @param mode How to filter the tiles
|
|
13
|
+
* @param localMatrix Optional matrix used when sampling
|
|
14
|
+
* @param tileRect The tile rectangle in picture coordinates: this represents the subset
|
|
15
|
+
* (or superset) of the picture used when building a tile. It is not
|
|
16
|
+
* affected by localMatrix and does not imply scaling (only translation
|
|
17
|
+
* and cropping). If null, the tile rect is considered equal to the picture
|
|
18
|
+
* bounds.
|
|
19
|
+
*/
|
|
20
|
+
makeShader(tmx: TileMode, tmy: TileMode, mode: FilterMode, localMatrix?: InputColorMatrix, tileRect?: SkRect): IShader;
|
|
21
|
+
/**
|
|
22
|
+
* Returns the serialized format of this SkPicture. The format may change at anytime and
|
|
23
|
+
* no promises are made for backwards or forward compatibility.
|
|
24
|
+
*/
|
|
25
|
+
serialize(): Uint8Array | null;
|
|
26
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SkCanvas } from "../Canvas";
|
|
2
|
+
import type { SkRect } from "../Rect";
|
|
3
|
+
import type { SkPicture } from "./Picture";
|
|
4
|
+
export interface SkPictureRecorder {
|
|
5
|
+
/**
|
|
6
|
+
* Returns a canvas on which to draw. When done drawing, call finishRecordingAsPicture()
|
|
7
|
+
*
|
|
8
|
+
* @param bounds - a rect to cull the results.
|
|
9
|
+
*/
|
|
10
|
+
beginRecording(bounds: SkRect): SkCanvas;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the captured draw commands as a picture and invalidates the canvas returned earlier.
|
|
13
|
+
*/
|
|
14
|
+
finishRecordingAsPicture(): SkPicture;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DependencyList } from "react";
|
|
2
|
+
import type { SkCanvas } from "../Canvas";
|
|
3
|
+
import type { SkRect } from "../Rect";
|
|
4
|
+
import type { SkPicture } from "./Picture";
|
|
5
|
+
/**
|
|
6
|
+
* Memoizes and returns an SkPicture that can be drawn to another canvas.
|
|
7
|
+
* @param rect Picture bounds
|
|
8
|
+
* @param cb Callback for drawing to the canvas
|
|
9
|
+
* @returns SkPicture
|
|
10
|
+
*/
|
|
11
|
+
export declare const usePicture: (rect: SkRect, cb: (canvas: SkCanvas) => void, deps?: DependencyList) => SkPicture;
|
|
@@ -25,6 +25,7 @@ import "./NativeSetup";
|
|
|
25
25
|
import type { SkRSXform } from "./RSXform";
|
|
26
26
|
import type { SkPath } from "./Path/Path";
|
|
27
27
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
28
|
+
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
|
28
29
|
/**
|
|
29
30
|
* Declares the interface for the native Skia API
|
|
30
31
|
*/
|
|
@@ -35,6 +36,8 @@ export interface Skia {
|
|
|
35
36
|
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
|
|
36
37
|
ContourMeasureIter: (path: SkPath, forceClosed: boolean, resScale: number) => SkContourMeasureIter;
|
|
37
38
|
Paint: () => SkPaint;
|
|
39
|
+
PictureRecorder: () => SkPictureRecorder;
|
|
40
|
+
Picture: PictureFactory;
|
|
38
41
|
Path: PathFactory;
|
|
39
42
|
Matrix: () => SkMatrix;
|
|
40
43
|
ColorFilter: ColorFilterFactory;
|
|
@@ -89,6 +92,8 @@ export declare const Skia: {
|
|
|
89
92
|
XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
|
|
90
93
|
RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
|
|
91
94
|
Paint: () => SkPaint;
|
|
95
|
+
PictureRecorder: () => SkPictureRecorder;
|
|
96
|
+
Picture: PictureFactory;
|
|
92
97
|
Path: PathFactory;
|
|
93
98
|
ColorFilter: ColorFilterFactory;
|
|
94
99
|
ContourMeasureIter: (path: SkPath, forceClosed: boolean, resScale: number) => SkContourMeasureIter;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { ViewProps } from "react-native";
|
|
2
3
|
import type { SkImage, SkRect } from "../skia";
|
|
3
4
|
import type { SkiaReadonlyValue } from "../values";
|
|
4
|
-
import type { DrawMode, RNSkiaDrawCallback
|
|
5
|
+
import type { DrawMode, RNSkiaDrawCallback } from "./types";
|
|
5
6
|
declare global {
|
|
6
7
|
var SkiaViewApi: {
|
|
7
8
|
invalidateSkiaView: (nativeId: number) => void;
|
|
@@ -11,12 +12,34 @@ declare global {
|
|
|
11
12
|
registerValuesInView: (nativeId: number, values: SkiaReadonlyValue<unknown>[]) => () => void;
|
|
12
13
|
};
|
|
13
14
|
}
|
|
14
|
-
export
|
|
15
|
-
|
|
15
|
+
export interface SkiaViewProps extends ViewProps {
|
|
16
|
+
/**
|
|
17
|
+
* Sets the drawing mode for the skia view. There are two drawing
|
|
18
|
+
* modes, "continuous" and "default", where the continuous mode will
|
|
19
|
+
* continuously redraw the view, and the default mode will only
|
|
20
|
+
* redraw when any of the regular react properties are changed like
|
|
21
|
+
* sizes and margins.
|
|
22
|
+
*/
|
|
23
|
+
mode?: DrawMode;
|
|
24
|
+
/**
|
|
25
|
+
* When set to true the view will display information about the
|
|
26
|
+
* average time it takes to render.
|
|
27
|
+
*/
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Draw callback. Will be called whenever the view is invalidated and
|
|
31
|
+
* needs to redraw. This is either caused by a change in a react
|
|
32
|
+
* property, a touch event, or a call to redraw. If the view is in
|
|
33
|
+
* continuous mode the callback will be called 60 frames per second
|
|
34
|
+
* by the native view.
|
|
35
|
+
*/
|
|
36
|
+
onDraw?: RNSkiaDrawCallback;
|
|
37
|
+
}
|
|
38
|
+
export declare class SkiaView extends React.Component<SkiaViewProps> {
|
|
39
|
+
constructor(props: SkiaViewProps);
|
|
16
40
|
private _nativeId;
|
|
17
|
-
private _animatingValues;
|
|
18
41
|
get nativeId(): number;
|
|
19
|
-
componentDidUpdate(prevProps:
|
|
42
|
+
componentDidUpdate(prevProps: SkiaViewProps): void;
|
|
20
43
|
/**
|
|
21
44
|
* Creates a snapshot from the canvas in the surface
|
|
22
45
|
* @param rect Rect to use as bounds. Optional.
|
|
@@ -43,13 +66,5 @@ export declare class SkiaView extends React.Component<RNSkiaViewProps> {
|
|
|
43
66
|
* @param values Values to register
|
|
44
67
|
*/
|
|
45
68
|
registerValues(values: SkiaReadonlyValue<unknown>[]): () => void;
|
|
46
|
-
/**
|
|
47
|
-
* Increases the number of animations active in the view.
|
|
48
|
-
*/
|
|
49
|
-
addAnimation(owner: unknown): void;
|
|
50
|
-
/**
|
|
51
|
-
* Decreases the number of animations active in the view.
|
|
52
|
-
*/
|
|
53
|
-
removeAnimation(owner: unknown): void;
|
|
54
69
|
render(): JSX.Element;
|
|
55
70
|
}
|
|
@@ -35,29 +35,6 @@ export declare type TouchHandlers = {
|
|
|
35
35
|
};
|
|
36
36
|
export declare type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;
|
|
37
37
|
export declare type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;
|
|
38
|
-
export declare type RNSkiaViewProps = ViewProps & {
|
|
39
|
-
/**
|
|
40
|
-
* Sets the drawing mode for the skia view. There are two drawing
|
|
41
|
-
* modes, "continuous" and "default", where the continuous mode will
|
|
42
|
-
* continuously redraw the view, and the default mode will only
|
|
43
|
-
* redraw when any of the regular react properties are changed like
|
|
44
|
-
* sizes and margins.
|
|
45
|
-
*/
|
|
46
|
-
mode?: DrawMode;
|
|
47
|
-
/**
|
|
48
|
-
* When set to true the view will display information about the
|
|
49
|
-
* average time it takes to render.
|
|
50
|
-
*/
|
|
51
|
-
debug?: boolean;
|
|
52
|
-
/**
|
|
53
|
-
* Draw callback. Will be called whenever the view is invalidated and
|
|
54
|
-
* needs to redraw. This is either caused by a change in a react
|
|
55
|
-
* property, a touch event, or a call to redraw. If the view is in
|
|
56
|
-
* continuous mode the callback will be called 60 frames per second
|
|
57
|
-
* by the native view.
|
|
58
|
-
*/
|
|
59
|
-
onDraw?: RNSkiaDrawCallback;
|
|
60
|
-
};
|
|
61
38
|
/**
|
|
62
39
|
* Listener interface for value changes
|
|
63
40
|
*/
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -6,32 +6,32 @@
|
|
|
6
6
|
<array>
|
|
7
7
|
<dict>
|
|
8
8
|
<key>LibraryIdentifier</key>
|
|
9
|
-
<string>ios-
|
|
9
|
+
<string>ios-arm64_arm64e</string>
|
|
10
10
|
<key>LibraryPath</key>
|
|
11
11
|
<string>libsvg.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-
|
|
22
|
+
<string>ios-arm64_arm64e_x86_64-simulator</string>
|
|
26
23
|
<key>LibraryPath</key>
|
|
27
24
|
<string>libsvg.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>
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -4,12 +4,9 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "React Native Skia",
|
|
7
|
-
"version": "0.1.
|
|
8
|
-
"description": "
|
|
7
|
+
"version": "0.1.119",
|
|
8
|
+
"description": "High-performance React Native Graphics using Skia",
|
|
9
9
|
"main": "lib/module/index.js",
|
|
10
|
-
"types": "lib/typescript/index.d.ts",
|
|
11
|
-
"react-native": "lib/module/index.js",
|
|
12
|
-
"module": "lib/module/index.js",
|
|
13
10
|
"files": [
|
|
14
11
|
"src",
|
|
15
12
|
"lib",
|
|
@@ -38,7 +35,7 @@
|
|
|
38
35
|
"tsc": "tsc --noEmit",
|
|
39
36
|
"lint": "eslint . --ext .ts,.tsx --max-warnings 0",
|
|
40
37
|
"test": "jest",
|
|
41
|
-
"postinstall": "
|
|
38
|
+
"postinstall": "node scripts/install-npm.js",
|
|
42
39
|
"build": "bob build"
|
|
43
40
|
},
|
|
44
41
|
"repository": {
|
|
@@ -96,5 +93,8 @@
|
|
|
96
93
|
"module",
|
|
97
94
|
"typescript"
|
|
98
95
|
]
|
|
99
|
-
}
|
|
96
|
+
},
|
|
97
|
+
"types": "lib/typescript/index.d.ts",
|
|
98
|
+
"module": "lib/module/index.js",
|
|
99
|
+
"react-native": "lib/module/index.js"
|
|
100
100
|
}
|
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -11,8 +11,6 @@ import type {
|
|
|
11
11
|
RefObject,
|
|
12
12
|
ReactNode,
|
|
13
13
|
ComponentProps,
|
|
14
|
-
Context,
|
|
15
|
-
ReactElement,
|
|
16
14
|
MutableRefObject,
|
|
17
15
|
ForwardedRef,
|
|
18
16
|
} from "react";
|
|
@@ -23,6 +21,8 @@ import { SkiaView, useDrawCallback } from "../views";
|
|
|
23
21
|
import type { TouchHandler } from "../views";
|
|
24
22
|
import { Skia } from "../skia";
|
|
25
23
|
import type { FontMgr } from "../skia/FontMgr/FontMgr";
|
|
24
|
+
import { useValue } from "../values/hooks/useValue";
|
|
25
|
+
import type { SkiaReadonlyValue } from "../values/types";
|
|
26
26
|
|
|
27
27
|
import { debug as hostDebug, skHostConfig } from "./HostConfig";
|
|
28
28
|
// import { debugTree } from "./nodes";
|
|
@@ -30,33 +30,12 @@ import { vec } from "./processors";
|
|
|
30
30
|
import { Container } from "./nodes";
|
|
31
31
|
import { DependencyManager } from "./DependencyManager";
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
export const useContextBridge = (...contexts: Context<any>[]) => {
|
|
36
|
-
const values =
|
|
37
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
38
|
-
contexts.map((context) => useContext(context));
|
|
39
|
-
return useMemo(
|
|
40
|
-
() =>
|
|
41
|
-
({ children }: { children: ReactNode }) =>
|
|
42
|
-
contexts.reduceRight(
|
|
43
|
-
(acc, Context, i) => (
|
|
44
|
-
<Context.Provider value={values[i]} children={acc} />
|
|
45
|
-
),
|
|
46
|
-
children
|
|
47
|
-
) as ReactElement,
|
|
48
|
-
[contexts, values]
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
interface CanvasContext {
|
|
33
|
+
const CanvasContext = React.createContext<SkiaReadonlyValue<{
|
|
53
34
|
width: number;
|
|
54
35
|
height: number;
|
|
55
|
-
}
|
|
36
|
+
}> | null>(null);
|
|
56
37
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
export const useCanvas = () => {
|
|
38
|
+
export const useCanvasSize = () => {
|
|
60
39
|
const canvas = useContext(CanvasContext);
|
|
61
40
|
if (!canvas) {
|
|
62
41
|
throw new Error("Canvas context is not available");
|
|
@@ -93,6 +72,7 @@ const defaultFontMgr = Skia.FontMgr.RefDefault();
|
|
|
93
72
|
|
|
94
73
|
export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
95
74
|
({ children, style, debug, mode, onTouch, fontMgr }, forwardedRef) => {
|
|
75
|
+
const canvasCtx = useValue({ width: 0, height: 0 });
|
|
96
76
|
const innerRef = useCanvasRef();
|
|
97
77
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
|
98
78
|
const [tick, setTick] = useState(0);
|
|
@@ -103,7 +83,6 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
|
103
83
|
[redraw, ref]
|
|
104
84
|
);
|
|
105
85
|
|
|
106
|
-
const canvasCtx = useRef({ width: 0, height: 0 });
|
|
107
86
|
const root = useMemo(
|
|
108
87
|
() => skiaReconciler.createContainer(container, 0, false, null),
|
|
109
88
|
[container]
|
|
@@ -111,13 +90,13 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
|
111
90
|
// Render effect
|
|
112
91
|
useEffect(() => {
|
|
113
92
|
render(
|
|
114
|
-
<CanvasContext.Provider value={canvasCtx
|
|
93
|
+
<CanvasContext.Provider value={canvasCtx}>
|
|
115
94
|
{children}
|
|
116
95
|
</CanvasContext.Provider>,
|
|
117
96
|
root,
|
|
118
97
|
container
|
|
119
98
|
);
|
|
120
|
-
}, [children, root, redraw, container]);
|
|
99
|
+
}, [children, root, redraw, container, canvasCtx]);
|
|
121
100
|
|
|
122
101
|
// Draw callback
|
|
123
102
|
const onDraw = useDrawCallback(
|
|
@@ -127,6 +106,12 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
|
127
106
|
if (onTouch) {
|
|
128
107
|
onTouch(info.touches);
|
|
129
108
|
}
|
|
109
|
+
if (
|
|
110
|
+
width !== canvasCtx.current.width ||
|
|
111
|
+
height !== canvasCtx.current.height
|
|
112
|
+
) {
|
|
113
|
+
canvasCtx.current = { width, height };
|
|
114
|
+
}
|
|
130
115
|
const paint = Skia.Paint();
|
|
131
116
|
paint.setAntiAlias(true);
|
|
132
117
|
const ctx = {
|
|
@@ -140,7 +125,6 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
|
140
125
|
center: vec(width / 2, height / 2),
|
|
141
126
|
fontMgr: fontMgr ?? defaultFontMgr,
|
|
142
127
|
};
|
|
143
|
-
canvasCtx.current = ctx;
|
|
144
128
|
container.draw(ctx);
|
|
145
129
|
},
|
|
146
130
|
[tick, onTouch]
|
|
@@ -3,7 +3,7 @@ import type { HostConfig } from "react-reconciler";
|
|
|
3
3
|
|
|
4
4
|
import type { Node, Container, DeclarationProps, DrawingProps } from "./nodes";
|
|
5
5
|
import { DeclarationNode, DrawingNode, NodeType } from "./nodes";
|
|
6
|
-
import { exhaustiveCheck,
|
|
6
|
+
import { exhaustiveCheck, shallowEq } from "./typeddash";
|
|
7
7
|
|
|
8
8
|
const DEBUG = false;
|
|
9
9
|
export const debug = (...args: Parameters<typeof console.log>) => {
|
|
@@ -53,24 +53,6 @@ type SkiaHostConfig = HostConfig<
|
|
|
53
53
|
NoTimeout
|
|
54
54
|
>;
|
|
55
55
|
|
|
56
|
-
// Shallow eq on props (without children)
|
|
57
|
-
const shallowEq = <P extends Props>(p1: P, p2: P): boolean => {
|
|
58
|
-
const keys1 = mapKeys(p1);
|
|
59
|
-
const keys2 = mapKeys(p2);
|
|
60
|
-
if (keys1.length !== keys2.length) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
for (const key of keys1) {
|
|
64
|
-
if (key === "children") {
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
if (p1[key] !== p2[key]) {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
56
|
const allChildrenAreMemoized = (node: Instance) => {
|
|
75
57
|
if (!node.memoizable) {
|
|
76
58
|
return false;
|
|
@@ -87,7 +69,7 @@ const bustBranchMemoization = (parent: Node) => {
|
|
|
87
69
|
if (parent.memoizable) {
|
|
88
70
|
let ancestor: Node | undefined = parent;
|
|
89
71
|
while (ancestor) {
|
|
90
|
-
ancestor.memoized =
|
|
72
|
+
ancestor.memoized = null;
|
|
91
73
|
ancestor = ancestor.parent;
|
|
92
74
|
}
|
|
93
75
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import type { DrawingContext } from "../DrawingContext";
|
|
4
|
+
import { createDrawing } from "../nodes/Drawing";
|
|
5
|
+
|
|
6
|
+
interface DrawingProps {
|
|
7
|
+
drawing: (ctx: DrawingContext) => void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const onDraw = createDrawing<DrawingProps>((ctx, { drawing }) => {
|
|
11
|
+
drawing(ctx);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const Drawing = (props: DrawingProps) => {
|
|
15
|
+
return <skDrawing onDraw={onDraw} skipProcessing {...props} />;
|
|
16
|
+
};
|
|
@@ -3,19 +3,15 @@ import type { RefObject } from "react";
|
|
|
3
3
|
|
|
4
4
|
import type { SkPaint } from "../../skia";
|
|
5
5
|
import { ClipOp } from "../../skia";
|
|
6
|
-
import {
|
|
7
|
-
processTransform,
|
|
8
|
-
selectPaint,
|
|
9
|
-
processPaint,
|
|
10
|
-
processClip,
|
|
11
|
-
} from "../processors";
|
|
6
|
+
import { processTransform, processPaint, processClip } from "../processors";
|
|
12
7
|
import type {
|
|
13
8
|
CustomPaintProps,
|
|
14
9
|
TransformProps,
|
|
15
10
|
AnimatedProps,
|
|
16
11
|
ClipDef,
|
|
17
12
|
} from "../processors";
|
|
18
|
-
import { createDrawing } from "../nodes";
|
|
13
|
+
import { createDrawing, DrawingNode } from "../nodes";
|
|
14
|
+
import { isDeclarationNode } from "../nodes/Declaration";
|
|
19
15
|
|
|
20
16
|
const isSkPaint = (obj: RefObject<SkPaint> | SkPaint): obj is SkPaint =>
|
|
21
17
|
"__typename__" in obj && obj.__typename__ === "Paint";
|
|
@@ -29,30 +25,51 @@ export interface GroupProps extends CustomPaintProps, TransformProps {
|
|
|
29
25
|
const onDraw = createDrawing<GroupProps>(
|
|
30
26
|
(ctx, { layer, clip, invertClip, ...groupProps }, node) => {
|
|
31
27
|
const { canvas, opacity } = ctx;
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
const declarations = node.children
|
|
29
|
+
.filter(isDeclarationNode)
|
|
30
|
+
.map((child) => child.draw(ctx));
|
|
31
|
+
|
|
32
|
+
const drawings = node.children.filter(
|
|
33
|
+
(child) => child instanceof DrawingNode
|
|
34
|
+
);
|
|
35
|
+
const paint = processPaint(
|
|
36
|
+
ctx.paint.copy(),
|
|
37
|
+
opacity,
|
|
38
|
+
groupProps,
|
|
39
|
+
declarations
|
|
40
|
+
);
|
|
41
|
+
const hasTransform = !!groupProps.transform || !!groupProps.matrix;
|
|
42
|
+
const hasClip = !!clip;
|
|
43
|
+
const shouldSave = hasTransform || hasClip || !!layer;
|
|
44
|
+
if (shouldSave) {
|
|
45
|
+
if (layer) {
|
|
46
|
+
if (typeof layer === "boolean") {
|
|
47
|
+
canvas.saveLayer();
|
|
48
|
+
} else if (isSkPaint(layer)) {
|
|
49
|
+
canvas.saveLayer(layer);
|
|
50
|
+
} else {
|
|
51
|
+
canvas.saveLayer(layer.current ?? undefined);
|
|
52
|
+
}
|
|
39
53
|
} else {
|
|
40
|
-
canvas.
|
|
54
|
+
canvas.save();
|
|
55
|
+
}
|
|
56
|
+
processTransform(ctx, groupProps);
|
|
57
|
+
if (clip) {
|
|
58
|
+
const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;
|
|
59
|
+
processClip(canvas, clip, op);
|
|
41
60
|
}
|
|
42
|
-
} else {
|
|
43
|
-
canvas.save();
|
|
44
61
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
62
|
+
node.visit(
|
|
63
|
+
{
|
|
64
|
+
...ctx,
|
|
65
|
+
paint,
|
|
66
|
+
opacity: groupProps.opacity ? groupProps.opacity * opacity : opacity,
|
|
67
|
+
},
|
|
68
|
+
drawings
|
|
69
|
+
);
|
|
70
|
+
if (shouldSave) {
|
|
71
|
+
canvas.restore();
|
|
49
72
|
}
|
|
50
|
-
node.visit({
|
|
51
|
-
...ctx,
|
|
52
|
-
paint,
|
|
53
|
-
opacity: groupProps.opacity ? groupProps.opacity * opacity : opacity,
|
|
54
|
-
});
|
|
55
|
-
canvas.restore();
|
|
56
73
|
}
|
|
57
74
|
);
|
|
58
75
|
|