@shopify/react-native-skia 0.1.121 → 0.1.124
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +3 -1
- package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
- package/android/cpp/jni/JniSkiaManager.cpp +1 -1
- package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
- package/android/cpp/jni/include/JniSkiaManager.h +4 -4
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
- package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
- package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
- package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
- package/cpp/api/JsiSkApi.h +2 -0
- package/cpp/api/JsiSkColor.h +49 -0
- package/cpp/api/JsiSkPath.h +31 -2
- package/cpp/api/JsiSkPathFactory.h +96 -1
- package/cpp/api/third_party/CSSColorParser.h +324 -0
- package/cpp/rnskia/RNSkAnimation.h +3 -8
- package/cpp/rnskia/RNSkDrawView.cpp +84 -126
- package/cpp/rnskia/RNSkDrawView.h +7 -37
- package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
- package/cpp/rnskia/RNSkManager.cpp +2 -2
- package/cpp/rnskia/RNSkManager.h +2 -2
- package/cpp/rnskia/RNSkPlatformContext.h +1 -1
- package/cpp/rnskia/RNSkValueApi.h +6 -2
- package/cpp/rnskia/values/RNSkClockValue.h +21 -13
- package/cpp/rnskia/values/RNSkDerivedValue.h +13 -6
- package/cpp/rnskia/values/RNSkReadonlyValue.h +17 -16
- package/cpp/rnskia/values/RNSkValue.h +8 -3
- package/cpp/utils/RNSkTimingInfo.h +13 -1
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +8 -10
- package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
- package/ios/RNSkia-iOS/SkiaDrawView.mm +21 -16
- package/lib/commonjs/renderer/Canvas.js +17 -8
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Paint.js +1 -1
- package/lib/commonjs/renderer/components/Paint.js.map +1 -1
- package/lib/commonjs/renderer/components/colorFilters/Lerp.js +1 -1
- package/lib/commonjs/renderer/components/colorFilters/Lerp.js.map +1 -1
- package/lib/commonjs/renderer/components/shaders/Shader.js +2 -2
- package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/Path.js +10 -2
- package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
- package/lib/commonjs/renderer/nodes/Node.js +3 -3
- package/lib/commonjs/renderer/nodes/Node.js.map +1 -1
- package/lib/commonjs/renderer/processors/Circles.js +3 -2
- package/lib/commonjs/renderer/processors/Circles.js.map +1 -1
- package/lib/commonjs/renderer/processors/Font.js +1 -1
- package/lib/commonjs/renderer/processors/Font.js.map +1 -1
- package/lib/commonjs/renderer/processors/Paint.js +6 -1
- package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
- package/lib/commonjs/renderer/processors/Rects.js +6 -6
- package/lib/commonjs/renderer/processors/Rects.js.map +1 -1
- package/lib/commonjs/skia/Color.js +3 -25
- package/lib/commonjs/skia/Color.js.map +1 -1
- package/lib/commonjs/skia/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/Paint/Paint.js +13 -1
- package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
- package/lib/commonjs/skia/Paint/usePaint.js +2 -4
- package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
- package/lib/commonjs/skia/Path/Path.js +13 -1
- package/lib/commonjs/skia/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/Shader/Shader.js.map +1 -1
- package/lib/commonjs/skia/Skia.js +43 -3
- package/lib/commonjs/skia/Skia.js.map +1 -1
- package/lib/commonjs/values/animation/timing/functions/getResolvedParams.js +3 -3
- package/lib/commonjs/values/animation/timing/functions/getResolvedParams.js.map +1 -1
- package/lib/module/renderer/Canvas.js +12 -6
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Paint.js +2 -2
- package/lib/module/renderer/components/Paint.js.map +1 -1
- package/lib/module/renderer/components/colorFilters/Lerp.js +1 -1
- package/lib/module/renderer/components/colorFilters/Lerp.js.map +1 -1
- package/lib/module/renderer/components/shaders/Shader.js +3 -2
- package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
- package/lib/module/renderer/components/shapes/Path.js +10 -3
- package/lib/module/renderer/components/shapes/Path.js.map +1 -1
- package/lib/module/renderer/nodes/Node.js +3 -3
- package/lib/module/renderer/nodes/Node.js.map +1 -1
- package/lib/module/renderer/processors/Circles.js +3 -2
- package/lib/module/renderer/processors/Circles.js.map +1 -1
- package/lib/module/renderer/processors/Font.js +1 -1
- package/lib/module/renderer/processors/Font.js.map +1 -1
- package/lib/module/renderer/processors/Paint.js +6 -1
- package/lib/module/renderer/processors/Paint.js.map +1 -1
- package/lib/module/renderer/processors/Rects.js +5 -6
- package/lib/module/renderer/processors/Rects.js.map +1 -1
- package/lib/module/skia/Color.js +2 -21
- package/lib/module/skia/Color.js.map +1 -1
- package/lib/module/skia/Image/Image.js.map +1 -1
- package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/module/skia/Paint/Paint.js +6 -0
- package/lib/module/skia/Paint/Paint.js.map +1 -1
- package/lib/module/skia/Paint/usePaint.js +2 -3
- package/lib/module/skia/Paint/usePaint.js.map +1 -1
- package/lib/module/skia/Path/Path.js +11 -0
- package/lib/module/skia/Path/Path.js.map +1 -1
- package/lib/module/skia/Shader/Shader.js.map +1 -1
- package/lib/module/skia/Skia.js +45 -2
- package/lib/module/skia/Skia.js.map +1 -1
- package/lib/module/values/animation/timing/functions/getResolvedParams.js +3 -3
- package/lib/module/values/animation/timing/functions/getResolvedParams.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +6 -0
- package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
- package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
- package/lib/typescript/src/skia/Color.d.ts +0 -1
- package/lib/typescript/src/skia/Image/Image.d.ts +3 -3
- package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +2 -2
- package/lib/typescript/src/skia/Paint/Paint.d.ts +3 -2
- package/lib/typescript/src/skia/Path/Path.d.ts +13 -0
- package/lib/typescript/src/skia/Path/PathFactory.d.ts +7 -1
- package/lib/typescript/src/skia/Picture/Picture.d.ts +2 -2
- package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +3 -3
- package/lib/typescript/src/skia/Shader/Shader.d.ts +2 -2
- package/lib/typescript/src/skia/Shader/ShaderFactory.d.ts +9 -9
- package/lib/typescript/src/skia/Skia.d.ts +5 -3
- package/lib/typescript/src/values/animation/types.d.ts +5 -5
- package/package.json +1 -1
- package/scripts/install-npm.js +1 -1
- package/src/renderer/Canvas.tsx +13 -6
- package/src/renderer/components/Paint.tsx +2 -2
- package/src/renderer/components/colorFilters/Lerp.tsx +1 -1
- package/src/renderer/components/shaders/Shader.tsx +1 -1
- package/src/renderer/components/shapes/Path.tsx +12 -4
- package/src/renderer/nodes/Node.ts +3 -3
- package/src/renderer/processors/Circles.ts +2 -1
- package/src/renderer/processors/Font.ts +1 -1
- package/src/renderer/processors/Paint.ts +5 -0
- package/src/renderer/processors/Rects.ts +3 -2
- package/src/skia/Color.ts +3 -20
- package/src/skia/Image/Image.ts +3 -3
- package/src/skia/ImageFilter/ImageFilterFactory.ts +2 -2
- package/src/skia/Paint/Paint.ts +9 -2
- package/src/skia/Paint/usePaint.ts +2 -4
- package/src/skia/Path/Path.ts +16 -0
- package/src/skia/Path/PathFactory.ts +8 -1
- package/src/skia/Picture/Picture.ts +2 -2
- package/src/skia/RuntimeEffect/RuntimeEffect.ts +4 -4
- package/src/skia/Shader/Shader.ts +2 -2
- package/src/skia/Shader/ShaderFactory.ts +9 -9
- package/src/skia/Skia.ts +47 -3
- package/src/values/animation/timing/functions/getResolvedParams.ts +2 -2
- package/src/values/animation/types.ts +5 -5
@@ -10,8 +10,6 @@ import type { SkRect } from "./Rect";
|
|
10
10
|
import type { SkRRect } from "./RRect";
|
11
11
|
import type { RuntimeEffectFactory } from "./RuntimeEffect";
|
12
12
|
import type { ShaderFactory } from "./Shader";
|
13
|
-
import type { SkColor } from "./Color";
|
14
|
-
import { processColor } from "./Color";
|
15
13
|
import type { SkMatrix } from "./Matrix";
|
16
14
|
import type { PathEffectFactory } from "./PathEffect";
|
17
15
|
import type { SkPoint } from "./Point";
|
@@ -26,6 +24,7 @@ import type { SkRSXform } from "./RSXform";
|
|
26
24
|
import type { SkPath } from "./Path/Path";
|
27
25
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
28
26
|
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
27
|
+
import type { Color, SkColor } from "./Color";
|
29
28
|
/**
|
30
29
|
* Declares the interface for the native Skia API
|
31
30
|
*/
|
@@ -34,6 +33,8 @@ export interface Skia {
|
|
34
33
|
XYWHRect: (x: number, y: number, width: number, height: number) => SkRect;
|
35
34
|
RRectXY: (rect: SkRect, rx: number, ry: number) => SkRRect;
|
36
35
|
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
|
36
|
+
Color: (color: Color) => SkColor;
|
37
|
+
parseColorString: (color: string) => SkColor | undefined;
|
37
38
|
ContourMeasureIter: (path: SkPath, forceClosed: boolean, resScale: number) => SkContourMeasureIter;
|
38
39
|
Paint: () => SkPaint;
|
39
40
|
PictureRecorder: () => SkPictureRecorder;
|
@@ -97,7 +98,8 @@ export declare const Skia: {
|
|
97
98
|
Path: PathFactory;
|
98
99
|
ColorFilter: ColorFilterFactory;
|
99
100
|
ContourMeasureIter: (path: SkPath, forceClosed: boolean, resScale: number) => SkContourMeasureIter;
|
100
|
-
Color: (
|
101
|
+
Color: (cl: Color) => number;
|
102
|
+
parseColorString: (color: string) => SkColor | undefined;
|
101
103
|
RSXform: (scos: number, ssin: number, tx: number, ty: number) => SkRSXform;
|
102
104
|
MakeSurface: (width: number, height: number) => import("./Surface").ISurface | null;
|
103
105
|
MakeImageFromEncoded: (encoded: import("./Data").Data) => import("./Image").SkImage | null;
|
@@ -1,11 +1,11 @@
|
|
1
1
|
export interface SpringConfig {
|
2
|
-
mass
|
3
|
-
stiffness
|
4
|
-
damping
|
5
|
-
velocity
|
2
|
+
mass?: number;
|
3
|
+
stiffness?: number;
|
4
|
+
damping?: number;
|
5
|
+
velocity?: number;
|
6
6
|
}
|
7
7
|
export interface TimingConfig {
|
8
|
-
duration
|
8
|
+
duration?: number;
|
9
9
|
easing?: (t: number) => number;
|
10
10
|
}
|
11
11
|
export interface AnimationParams {
|
package/package.json
CHANGED
package/scripts/install-npm.js
CHANGED
@@ -9,7 +9,7 @@ const createSymlink = (p) => {
|
|
9
9
|
const dstDir = path.resolve(`./android/cpp/${p}`);
|
10
10
|
|
11
11
|
if (!fs.existsSync(dstDir) || !fs.lstatSync(dstDir).isSymbolicLink()) {
|
12
|
-
fs.symlinkSync(srcDir, dstDir, "
|
12
|
+
fs.symlinkSync(srcDir, dstDir, "junction");
|
13
13
|
}
|
14
14
|
};
|
15
15
|
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -23,6 +23,7 @@ import { Skia } from "../skia";
|
|
23
23
|
import type { FontMgr } from "../skia/FontMgr/FontMgr";
|
24
24
|
import { useValue } from "../values/hooks/useValue";
|
25
25
|
import type { SkiaReadonlyValue } from "../values/types";
|
26
|
+
import { SkiaPaint } from "../skia/Paint/Paint";
|
26
27
|
|
27
28
|
import { debug as hostDebug, skHostConfig } from "./HostConfig";
|
28
29
|
// import { debugTree } from "./nodes";
|
@@ -35,12 +36,19 @@ const CanvasContext = React.createContext<SkiaReadonlyValue<{
|
|
35
36
|
height: number;
|
36
37
|
}> | null>(null);
|
37
38
|
|
38
|
-
export const
|
39
|
-
const
|
40
|
-
if (!
|
39
|
+
export const useCanvas = () => {
|
40
|
+
const size = useContext(CanvasContext);
|
41
|
+
if (!size) {
|
41
42
|
throw new Error("Canvas context is not available");
|
42
43
|
}
|
43
|
-
return
|
44
|
+
return { size };
|
45
|
+
};
|
46
|
+
|
47
|
+
export const useCanvasSize = () => {
|
48
|
+
console.warn(
|
49
|
+
"useCanvasSize is deprecated, use the size member of useCanvas() instead."
|
50
|
+
);
|
51
|
+
return useCanvas().size;
|
44
52
|
};
|
45
53
|
|
46
54
|
export const skiaReconciler = ReactReconciler(skHostConfig);
|
@@ -112,8 +120,7 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
112
120
|
) {
|
113
121
|
canvasCtx.current = { width, height };
|
114
122
|
}
|
115
|
-
const paint =
|
116
|
-
paint.setAntiAlias(true);
|
123
|
+
const paint = SkiaPaint();
|
117
124
|
const ctx = {
|
118
125
|
width,
|
119
126
|
height,
|
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
|
|
2
2
|
import React, { useRef, useMemo, forwardRef, useImperativeHandle } from "react";
|
3
3
|
|
4
4
|
import type { SkPaint } from "../../skia";
|
5
|
-
import {
|
5
|
+
import { SkiaPaint } from "../../skia";
|
6
6
|
import type { CustomPaintProps, AnimatedProps } from "../processors";
|
7
7
|
import { processPaint } from "../processors";
|
8
8
|
import { createDeclaration } from "../nodes";
|
@@ -15,7 +15,7 @@ export interface PaintProps extends Omit<CustomPaintProps, "paint"> {
|
|
15
15
|
|
16
16
|
export const Paint = forwardRef<SkPaint, AnimatedProps<PaintProps>>(
|
17
17
|
(props, ref) => {
|
18
|
-
const paint = useMemo(() =>
|
18
|
+
const paint = useMemo(() => SkiaPaint(), []);
|
19
19
|
useImperativeHandle(ref, () => paint, [paint]);
|
20
20
|
const onDeclare = useMemo(
|
21
21
|
() =>
|
@@ -15,7 +15,7 @@ export interface LerpProps {
|
|
15
15
|
|
16
16
|
const onDeclare = createDeclaration<LerpProps>(({ t }, children) => {
|
17
17
|
const [src, dst] = children.filter(isColorFilter);
|
18
|
-
const cf = Skia.ColorFilter.MakeLerp(t,
|
18
|
+
const cf = Skia.ColorFilter.MakeLerp(t, src, dst);
|
19
19
|
return composeColorFilter(
|
20
20
|
cf,
|
21
21
|
children.filter((c) => c !== src && c !== dst)
|
@@ -7,8 +7,8 @@ import type { Vector, AnimatedProps, TransformProps } from "../../processors";
|
|
7
7
|
import { createDeclaration } from "../../nodes/Declaration";
|
8
8
|
import { localMatrix } from "../../processors";
|
9
9
|
|
10
|
-
// We need to use any here because hasOwnProperty doesn't work on JSI instances
|
11
10
|
const isVector = (obj: unknown): obj is Vector =>
|
11
|
+
// We have an issue to check property existence on JSI backed instances
|
12
12
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
13
13
|
(obj as any).x !== undefined && (obj as any).y !== undefined;
|
14
14
|
|
@@ -4,9 +4,11 @@ import type {
|
|
4
4
|
CustomPaintProps,
|
5
5
|
AnimatedProps,
|
6
6
|
PathDef,
|
7
|
+
SkEnum,
|
7
8
|
} from "../../processors";
|
8
9
|
import { createDrawing } from "../../nodes";
|
9
|
-
import { processPath } from "../../processors";
|
10
|
+
import { processPath, enumKey } from "../../processors";
|
11
|
+
import { FillType } from "../../../skia";
|
10
12
|
|
11
13
|
interface StrokeOpts {
|
12
14
|
width?: number;
|
@@ -19,16 +21,22 @@ export interface PathProps extends CustomPaintProps {
|
|
19
21
|
start: number;
|
20
22
|
end: number;
|
21
23
|
stroke?: StrokeOpts;
|
24
|
+
fillType?: SkEnum<typeof FillType>;
|
22
25
|
}
|
23
26
|
|
24
27
|
const onDraw = createDrawing<PathProps>(
|
25
|
-
({ canvas, paint }, { start, end, stroke, ...pathProps }) => {
|
28
|
+
({ canvas, paint }, { start, end, stroke, fillType, ...pathProps }) => {
|
26
29
|
const hasStartOffset = start !== 0;
|
27
|
-
const hasEndOffset =
|
30
|
+
const hasEndOffset = end !== 1;
|
28
31
|
const hasStrokeOptions = stroke !== undefined;
|
29
|
-
const
|
32
|
+
const hasFillType = !!fillType;
|
33
|
+
const willMutatePath =
|
34
|
+
hasStartOffset || hasEndOffset || hasStrokeOptions || hasFillType;
|
30
35
|
const pristinePath = processPath(pathProps.path);
|
31
36
|
const path = willMutatePath ? pristinePath.copy() : pristinePath;
|
37
|
+
if (hasFillType) {
|
38
|
+
path.setFillType(FillType[enumKey(fillType)]);
|
39
|
+
}
|
32
40
|
if (hasStrokeOptions) {
|
33
41
|
path.stroke(stroke);
|
34
42
|
}
|
@@ -40,7 +40,9 @@ export abstract class Node<P = unknown> {
|
|
40
40
|
visit(ctx: DrawingContext, children?: Node[]) {
|
41
41
|
const returnedValues: Exclude<DeclarationResult, null>[] = [];
|
42
42
|
(children ?? this.children).forEach((child) => {
|
43
|
-
if (
|
43
|
+
if (child.memoized && child.memoizable) {
|
44
|
+
returnedValues.push(child.memoized);
|
45
|
+
} else {
|
44
46
|
const ret = child.draw(ctx);
|
45
47
|
if (ret) {
|
46
48
|
returnedValues.push(ret);
|
@@ -48,8 +50,6 @@ export abstract class Node<P = unknown> {
|
|
48
50
|
child.memoized = ret;
|
49
51
|
}
|
50
52
|
}
|
51
|
-
} else {
|
52
|
-
returnedValues.push(child.memoized);
|
53
53
|
}
|
54
54
|
});
|
55
55
|
return returnedValues;
|
@@ -15,8 +15,9 @@ interface ScalarCircleDef {
|
|
15
15
|
export type CircleDef = PointCircleDef | ScalarCircleDef;
|
16
16
|
|
17
17
|
const isCircleScalarDef = (def: CircleDef): def is ScalarCircleDef =>
|
18
|
+
// We have an issue to check property existence on JSI backed instances
|
18
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
19
|
-
(def as any).cx;
|
20
|
+
(def as any).cx !== undefined;
|
20
21
|
export const processCircle = (def: CircleDef) => {
|
21
22
|
if (isCircleScalarDef(def)) {
|
22
23
|
return { c: vec(def.cx, def.cy), r: def.r };
|
@@ -5,7 +5,7 @@ import type { FontMgr } from "../../skia/FontMgr/FontMgr";
|
|
5
5
|
export type FontDef = { font: SkFont } | { familyName: string; size: number };
|
6
6
|
|
7
7
|
export const isFont = (fontDef: FontDef): fontDef is { font: SkFont } =>
|
8
|
-
// We
|
8
|
+
// We have an issue to check property existence on JSI backed instances
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
10
|
(fontDef as any).font !== undefined;
|
11
11
|
|
@@ -32,6 +32,7 @@ export interface CustomPaintProps extends ChildrenProps {
|
|
32
32
|
strokeCap?: SkEnum<typeof StrokeCap>;
|
33
33
|
strokeMiter?: number;
|
34
34
|
opacity?: number;
|
35
|
+
antiAlias?: boolean;
|
35
36
|
}
|
36
37
|
|
37
38
|
export const enumKey = <K extends string>(k: K) =>
|
@@ -50,6 +51,7 @@ export const processPaint = (
|
|
50
51
|
strokeCap,
|
51
52
|
strokeMiter,
|
52
53
|
opacity,
|
54
|
+
antiAlias,
|
53
55
|
}: CustomPaintProps,
|
54
56
|
children: DeclarationResult[]
|
55
57
|
) => {
|
@@ -85,6 +87,9 @@ export const processPaint = (
|
|
85
87
|
if (opacity !== undefined) {
|
86
88
|
paint.setAlphaf(opacity);
|
87
89
|
}
|
90
|
+
if (antiAlias !== undefined) {
|
91
|
+
paint.setAntiAlias(antiAlias);
|
92
|
+
}
|
88
93
|
children.forEach((child) => {
|
89
94
|
if (isShader(child)) {
|
90
95
|
paint.setShader(child);
|
@@ -1,5 +1,3 @@
|
|
1
|
-
// Here we use any because hasOwnProperty doesn't work on JSI instances not does the (key in obj) syntax
|
2
|
-
// And using Object.keys for such use-case is incredibly slow
|
3
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
4
2
|
import type { SkRect, SkRRect } from "../../skia";
|
5
3
|
|
@@ -47,10 +45,13 @@ export const center = (r: SkRect | SkRRect) =>
|
|
47
45
|
? vec(r.rect.x + r.rect.width / 2, r.rect.y + r.rect.height / 2)
|
48
46
|
: vec(r.x + r.width / 2, r.y + r.height / 2);
|
49
47
|
|
48
|
+
// We have an issue to check property existence on JSI backed instances
|
50
49
|
const isRRectCtor = (def: RRectDef): def is RRectCtor =>
|
51
50
|
(def as any).rect === undefined;
|
51
|
+
// We have an issue to check property existence on JSI backed instances
|
52
52
|
const isRectCtor = (def: RectDef): def is RectCtor =>
|
53
53
|
(def as any).rect === undefined;
|
54
|
+
// We have an issue to check property existence on JSI backed instances
|
54
55
|
export const isRRect = (def: SkRect | SkRRect): def is SkRRect =>
|
55
56
|
(def as any).rect !== undefined;
|
56
57
|
|
package/src/skia/Color.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import {
|
1
|
+
import { Skia } from "./Skia";
|
2
2
|
|
3
3
|
// This is the JSI color. Currently a number. This may change.
|
4
4
|
export type SkColor = number;
|
5
|
-
|
5
|
+
// Input colors can be string or number
|
6
6
|
export type Color = string | number;
|
7
7
|
|
8
8
|
export const alphaf = (c: number) => ((c >> 24) & 255) / 255;
|
@@ -14,25 +14,8 @@ export const rgbaColor = (r: number, g: number, b: number, af: number) => {
|
|
14
14
|
return ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
|
15
15
|
};
|
16
16
|
|
17
|
-
export const processColorAsInt = (color?: number | string): SkColor => {
|
18
|
-
let processedColor = processColorRN(color);
|
19
|
-
if (typeof processedColor !== "number") {
|
20
|
-
throw new Error(`Couldn't process color: ${color}`);
|
21
|
-
}
|
22
|
-
// On android we need to move the alpha byte to the start of the structure
|
23
|
-
if (Platform.OS === "android") {
|
24
|
-
processedColor = processedColor >>> 0;
|
25
|
-
const a = (processedColor >> 24) & 0xff;
|
26
|
-
const r = (processedColor >> 16) & 0xff;
|
27
|
-
const g = (processedColor >> 8) & 0xff;
|
28
|
-
const b = processedColor & 0xff;
|
29
|
-
processedColor = ((a << 24) | (r << 16) | (g << 8) | b) >>> 0;
|
30
|
-
}
|
31
|
-
return processedColor;
|
32
|
-
};
|
33
|
-
|
34
17
|
const processColorAsArray = (cl: Color) => {
|
35
|
-
const icl = typeof cl === "string" ?
|
18
|
+
const icl = typeof cl === "string" ? Skia.Color(cl) : cl;
|
36
19
|
const r = red(icl);
|
37
20
|
const g = green(icl);
|
38
21
|
const b = blue(icl);
|
package/src/skia/Image/Image.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { TileMode } from "../ImageFilter";
|
2
|
-
import type {
|
2
|
+
import type { SkShader } from "../Shader";
|
3
3
|
import type { SkMatrix } from "../Matrix";
|
4
4
|
import type { SkJSIInstance } from "../JsiInstance";
|
5
5
|
|
@@ -46,7 +46,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
46
46
|
fm: FilterMode,
|
47
47
|
mm: MipmapMode,
|
48
48
|
localMatrix?: SkMatrix
|
49
|
-
):
|
49
|
+
): SkShader;
|
50
50
|
|
51
51
|
/**
|
52
52
|
* Returns this image as a shader with the specified tiling. It will use cubic sampling.
|
@@ -62,7 +62,7 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
62
62
|
B: number,
|
63
63
|
C: number,
|
64
64
|
localMatrix?: SkMatrix
|
65
|
-
):
|
65
|
+
): SkShader;
|
66
66
|
|
67
67
|
/** Encodes Image pixels, returning result as UInt8Array. Returns existing
|
68
68
|
encoded data if present; otherwise, SkImage is encoded with
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { SkColor } from "../Color";
|
2
2
|
import type { SkColorFilter } from "../ColorFilter/ColorFilter";
|
3
|
-
import type {
|
3
|
+
import type { SkShader } from "../Shader/Shader";
|
4
4
|
import type { SkRect } from "../Rect";
|
5
5
|
import type { BlendMode } from "../Paint/BlendMode";
|
6
6
|
|
@@ -48,7 +48,7 @@ export interface ImageFilterFactory {
|
|
48
48
|
* @param shader - The Shader to be transformed
|
49
49
|
* @param input - if null, it will use the dynamic source image
|
50
50
|
*/
|
51
|
-
MakeShader(shader:
|
51
|
+
MakeShader(shader: SkShader, input: SkImageFilter | null): SkImageFilter;
|
52
52
|
/**
|
53
53
|
* Create a filter that blurs its input by the separate X and Y sigmas. The provided tile mode
|
54
54
|
* is used when the blur kernel goes outside the input image.
|
package/src/skia/Paint/Paint.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
import type { SkImageFilter } from "../ImageFilter";
|
2
2
|
import type { IMaskFilter } from "../MaskFilter";
|
3
3
|
import type { SkColorFilter } from "../ColorFilter";
|
4
|
-
import type {
|
4
|
+
import type { SkShader } from "../Shader";
|
5
5
|
import type { SkColor } from "../Color";
|
6
6
|
import type { IPathEffect } from "../PathEffect";
|
7
7
|
import type { SkJSIInstance } from "../JsiInstance";
|
8
|
+
import { Skia } from "../Skia";
|
8
9
|
|
9
10
|
import type { BlendMode } from "./BlendMode";
|
10
11
|
|
@@ -25,6 +26,12 @@ export enum StrokeJoin {
|
|
25
26
|
Round,
|
26
27
|
}
|
27
28
|
|
29
|
+
export const SkiaPaint = () => {
|
30
|
+
const paint = Skia.Paint();
|
31
|
+
paint.setAntiAlias(true);
|
32
|
+
return paint;
|
33
|
+
};
|
34
|
+
|
28
35
|
export const isPaint = (obj: SkJSIInstance<string> | null): obj is SkPaint =>
|
29
36
|
obj !== null && obj.__typename__ === "Paint";
|
30
37
|
|
@@ -119,7 +126,7 @@ export interface SkPaint extends SkJSIInstance<"Paint"> {
|
|
119
126
|
* Sets the current shader, replacing the existing one if there was one.
|
120
127
|
* @param shader
|
121
128
|
*/
|
122
|
-
setShader(shader:
|
129
|
+
setShader(shader: SkShader | null): void;
|
123
130
|
|
124
131
|
/**
|
125
132
|
* Sets the geometry drawn at the beginning and end of strokes.
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import type { DependencyList } from "react";
|
2
2
|
import { useMemo } from "react";
|
3
3
|
|
4
|
-
import {
|
5
|
-
|
4
|
+
import { SkiaPaint } from "./Paint";
|
6
5
|
import type { SkPaint } from "./Paint";
|
7
6
|
|
8
7
|
/**
|
@@ -13,8 +12,7 @@ export const usePaint = (
|
|
13
12
|
deps?: DependencyList
|
14
13
|
) =>
|
15
14
|
useMemo(() => {
|
16
|
-
const p =
|
17
|
-
p.setAntiAlias(true);
|
15
|
+
const p = SkiaPaint();
|
18
16
|
if (initializer) {
|
19
17
|
initializer(p);
|
20
18
|
}
|
package/src/skia/Path/Path.ts
CHANGED
@@ -38,6 +38,17 @@ export enum PathOp {
|
|
38
38
|
ReverseDifference,
|
39
39
|
}
|
40
40
|
|
41
|
+
export enum PathVerb {
|
42
|
+
Move,
|
43
|
+
Line,
|
44
|
+
Quad,
|
45
|
+
Conic,
|
46
|
+
Cubic,
|
47
|
+
Close,
|
48
|
+
}
|
49
|
+
|
50
|
+
export type PathCommand = number[];
|
51
|
+
|
41
52
|
export const isPath = (obj: SkJSIInstance<string> | null): obj is SkPath =>
|
42
53
|
obj !== null && obj.__typename__ === "Path";
|
43
54
|
|
@@ -535,4 +546,9 @@ export interface SkPath extends SkJSIInstance<"Path"> {
|
|
535
546
|
*
|
536
547
|
* */
|
537
548
|
isInterpolatable(compare: SkPath): boolean;
|
549
|
+
|
550
|
+
/**
|
551
|
+
* Serializes the contents of this path as a series of commands.
|
552
|
+
*/
|
553
|
+
toCmds(): PathCommand[];
|
538
554
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { SkPath, PathOp } from "./Path";
|
1
|
+
import type { SkPath, PathOp, PathCommand } from "./Path";
|
2
2
|
|
3
3
|
export interface PathFactory {
|
4
4
|
Make(): SkPath;
|
@@ -17,4 +17,11 @@ export interface PathFactory {
|
|
17
17
|
* @param op
|
18
18
|
*/
|
19
19
|
MakeFromOp(one: SkPath, two: SkPath, op: PathOp): SkPath | null;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Creates a new path from the given list of path commands. If this fails, null will be
|
23
|
+
* returned instead.
|
24
|
+
* @param cmds
|
25
|
+
*/
|
26
|
+
MakeFromCmds(cmds: PathCommand[]): SkPath | null;
|
20
27
|
}
|
@@ -2,7 +2,7 @@ import type { InputColorMatrix } from "../ColorFilter";
|
|
2
2
|
import type { FilterMode } from "../Image";
|
3
3
|
import type { TileMode } from "../ImageFilter";
|
4
4
|
import type { SkRect } from "../Rect";
|
5
|
-
import type {
|
5
|
+
import type { SkShader } from "../Shader";
|
6
6
|
|
7
7
|
export interface SkPicture {
|
8
8
|
/**
|
@@ -24,7 +24,7 @@ export interface SkPicture {
|
|
24
24
|
mode: FilterMode,
|
25
25
|
localMatrix?: InputColorMatrix,
|
26
26
|
tileRect?: SkRect
|
27
|
-
):
|
27
|
+
): SkShader;
|
28
28
|
|
29
29
|
/**
|
30
30
|
* Returns the serialized format of this SkPicture. The format may change at anytime and
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type {
|
1
|
+
import type { SkShader } from "../Shader";
|
2
2
|
import type { SkJSIInstance } from "../JsiInstance";
|
3
3
|
import type { SkMatrix } from "../Matrix";
|
4
4
|
|
@@ -21,7 +21,7 @@ export interface IRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
|
|
21
21
|
uniforms: number[],
|
22
22
|
isOpaque?: boolean,
|
23
23
|
localMatrix?: SkMatrix
|
24
|
-
):
|
24
|
+
): SkShader;
|
25
25
|
|
26
26
|
/**
|
27
27
|
* Returns a shader executed using the given uniform data and the children as inputs.
|
@@ -33,9 +33,9 @@ export interface IRuntimeEffect extends SkJSIInstance<"RuntimeEffect"> {
|
|
33
33
|
makeShaderWithChildren(
|
34
34
|
uniforms: number[],
|
35
35
|
isOpaque?: boolean,
|
36
|
-
children?:
|
36
|
+
children?: SkShader[],
|
37
37
|
localMatrix?: SkMatrix
|
38
|
-
):
|
38
|
+
): SkShader;
|
39
39
|
|
40
40
|
/**
|
41
41
|
* Returns the nth uniform from the effect.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { SkJSIInstance } from "../JsiInstance";
|
2
2
|
|
3
|
-
export const isShader = (obj: SkJSIInstance<string> | null): obj is
|
3
|
+
export const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>
|
4
4
|
obj !== null && obj.__typename__ === "Shader";
|
5
5
|
|
6
|
-
export type
|
6
|
+
export type SkShader = SkJSIInstance<"Shader">;
|
@@ -4,7 +4,7 @@ import type { SkMatrix } from "../Matrix";
|
|
4
4
|
import type { SkColor } from "../Color";
|
5
5
|
import type { BlendMode } from "../Paint/BlendMode";
|
6
6
|
|
7
|
-
import type {
|
7
|
+
import type { SkShader } from "./Shader";
|
8
8
|
|
9
9
|
export interface ShaderFactory {
|
10
10
|
/**
|
@@ -31,7 +31,7 @@ export interface ShaderFactory {
|
|
31
31
|
localMatrix?: SkMatrix,
|
32
32
|
flags?: number
|
33
33
|
// colorSpace: ColorSpace
|
34
|
-
):
|
34
|
+
): SkShader;
|
35
35
|
|
36
36
|
/**
|
37
37
|
* Returns a shader that generates a radial gradient given the center and radius.
|
@@ -54,7 +54,7 @@ export interface ShaderFactory {
|
|
54
54
|
localMatrix?: SkMatrix,
|
55
55
|
flags?: number
|
56
56
|
// colorSpace?: ColorSpace
|
57
|
-
):
|
57
|
+
): SkShader;
|
58
58
|
|
59
59
|
/**
|
60
60
|
* Returns a shader that generates a conical gradient given two circles.
|
@@ -80,7 +80,7 @@ export interface ShaderFactory {
|
|
80
80
|
localMatrix?: SkMatrix,
|
81
81
|
flags?: number
|
82
82
|
// colorSpace?: ColorSpace
|
83
|
-
):
|
83
|
+
): SkShader;
|
84
84
|
|
85
85
|
/**
|
86
86
|
* Returns a shader that generates a sweep gradient given a center.
|
@@ -107,7 +107,7 @@ export interface ShaderFactory {
|
|
107
107
|
startAngleInDegrees?: number,
|
108
108
|
endAngleInDegrees?: number
|
109
109
|
// colorSpace?: ColorSpace
|
110
|
-
):
|
110
|
+
): SkShader;
|
111
111
|
|
112
112
|
/**
|
113
113
|
* Returns a shader with Perlin Turbulence.
|
@@ -128,7 +128,7 @@ export interface ShaderFactory {
|
|
128
128
|
seed: number,
|
129
129
|
tileW: number,
|
130
130
|
tileH: number
|
131
|
-
):
|
131
|
+
): SkShader;
|
132
132
|
|
133
133
|
/**
|
134
134
|
* Returns a shader with Perlin Fractal Noise.
|
@@ -149,7 +149,7 @@ export interface ShaderFactory {
|
|
149
149
|
seed: number,
|
150
150
|
tileW: number,
|
151
151
|
tileH: number
|
152
|
-
):
|
152
|
+
): SkShader;
|
153
153
|
|
154
154
|
/**
|
155
155
|
* Returns a shader that combines the given shaders with a BlendMode.
|
@@ -157,7 +157,7 @@ export interface ShaderFactory {
|
|
157
157
|
* @param one
|
158
158
|
* @param two
|
159
159
|
*/
|
160
|
-
MakeBlend(mode: BlendMode, one:
|
160
|
+
MakeBlend(mode: BlendMode, one: SkShader, two: SkShader): SkShader;
|
161
161
|
|
162
162
|
/**
|
163
163
|
* Returns a shader with a given color and colorspace.
|
@@ -165,5 +165,5 @@ export interface ShaderFactory {
|
|
165
165
|
*/
|
166
166
|
MakeColor(
|
167
167
|
color: SkColor //,space: ColorSpace
|
168
|
-
):
|
168
|
+
): SkShader;
|
169
169
|
}
|