@shopify/react-native-skia 0.1.131 → 0.1.134
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +1 -1
- package/android/build.gradle +17 -2
- package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +5 -0
- package/cpp/api/JsiSkFont.h +6 -2
- package/cpp/api/JsiSkImage.h +2 -19
- package/cpp/api/JsiSkPaint.h +5 -32
- package/cpp/api/JsiSkPath.h +4 -4
- package/cpp/rnskia/RNSkValueApi.h +6 -6
- package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
- package/cpp/utils/RNSkLog.h +5 -0
- package/ios/RNSkia-iOS/SkiaManager.mm +1 -1
- package/lib/commonjs/mock/index.js +190 -0
- package/lib/commonjs/mock/index.js.map +1 -0
- package/lib/commonjs/skia/core/Data.js +33 -43
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Typeface.js +1 -1
- package/lib/commonjs/skia/core/Typeface.js.map +1 -1
- package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Image/Image.js +5 -5
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Paint/Paint.js +3 -3
- package/lib/commonjs/skia/types/Paint/Paint.js.map +1 -1
- package/lib/commonjs/skia/types/Path/Path.js +0 -1
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/types/Shader/Shader.js +1 -7
- package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.js +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +4 -2
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -2
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.js +10 -6
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.js +65 -52
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkShaderFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +23 -1
- package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +2 -2
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/values/api.js +3 -3
- package/lib/commonjs/values/api.js.map +1 -1
- package/lib/commonjs/values/api.web.js +3 -3
- package/lib/commonjs/values/api.web.js.map +1 -1
- package/lib/commonjs/values/hooks/index.js +4 -4
- package/lib/commonjs/values/hooks/index.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.js +32 -0
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -0
- package/lib/commonjs/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +4 -4
- package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -0
- package/lib/commonjs/values/web/api.js +3 -3
- package/lib/commonjs/values/web/api.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +4 -4
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/web/index.js +4 -2
- package/lib/commonjs/web/index.js.map +1 -1
- package/lib/module/mock/index.js +152 -0
- package/lib/module/mock/index.js.map +1 -0
- package/lib/module/skia/core/Data.js +32 -41
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Typeface.js +1 -1
- package/lib/module/skia/core/Typeface.js.map +1 -1
- package/lib/module/skia/types/Font/Font.js.map +1 -1
- package/lib/module/skia/types/Image/Image.js +5 -5
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/module/skia/types/Paint/Paint.js +3 -3
- package/lib/module/skia/types/Paint/Paint.js.map +1 -1
- package/lib/module/skia/types/Path/Path.js +0 -1
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/types/Shader/Shader.js +1 -7
- package/lib/module/skia/types/Shader/Shader.js.map +1 -1
- package/lib/module/skia/web/JsiSkCanvas.js +1 -1
- package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +5 -3
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkFontMgr.js +0 -2
- package/lib/module/skia/web/JsiSkFontMgr.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.js +10 -7
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/{JsiImageFilterFactory.js → JsiSkImageFilterFactory.js} +1 -1
- package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.js +65 -52
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/skia/web/JsiSkShaderFactory.js +1 -1
- package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkVerticesFactory.js +24 -1
- package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +1 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/values/api.js +1 -1
- package/lib/module/values/api.js.map +1 -1
- package/lib/module/values/api.web.js +1 -1
- package/lib/module/values/api.web.js.map +1 -1
- package/lib/module/values/hooks/index.js +1 -1
- package/lib/module/values/hooks/index.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.js +18 -0
- package/lib/module/values/hooks/useComputedValue.js.map +1 -0
- package/lib/module/values/web/{RNSkDerivedValue.js → RNSkComputedValue.js} +2 -2
- package/lib/module/values/web/RNSkComputedValue.js.map +1 -0
- package/lib/module/values/web/api.js +3 -3
- package/lib/module/values/web/api.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +4 -4
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/web/index.js +3 -1
- package/lib/module/web/index.js.map +1 -1
- package/lib/typescript/src/mock/index.d.ts +47 -0
- package/lib/typescript/src/skia/core/Data.d.ts +3 -3
- package/lib/typescript/src/skia/types/Font/Font.d.ts +8 -9
- package/lib/typescript/src/skia/types/Image/Image.d.ts +5 -5
- package/lib/typescript/src/skia/types/Paint/Paint.d.ts +3 -3
- package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -2
- package/lib/typescript/src/skia/types/RuntimeEffect/RuntimeEffect.d.ts +1 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +3 -3
- package/lib/typescript/src/skia/web/{JsiImageFilterFactory.d.ts → JsiSkImageFilterFactory.d.ts} +0 -0
- package/lib/typescript/src/skia/web/JsiSkPaint.d.ts +1 -1
- package/lib/typescript/src/values/api.d.ts +1 -1
- package/lib/typescript/src/values/api.web.d.ts +1 -1
- package/lib/typescript/src/values/hooks/index.d.ts +1 -1
- package/lib/typescript/src/values/hooks/{useDerivedValue.d.ts → useComputedValue.d.ts} +2 -1
- package/lib/typescript/src/values/types.d.ts +2 -2
- package/lib/typescript/src/values/web/{RNSkDerivedValue.d.ts → RNSkComputedValue.d.ts} +1 -1
- package/package.json +2 -1
- package/src/mock/index.ts +156 -0
- package/src/skia/core/Data.ts +67 -50
- package/src/skia/core/Typeface.ts +6 -1
- package/src/skia/types/Font/Font.ts +9 -14
- package/src/skia/types/Image/Image.ts +4 -4
- package/src/skia/types/Paint/Paint.ts +1 -1
- package/src/skia/types/Path/Path.ts +0 -1
- package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +1 -0
- package/src/skia/types/Shader/Shader.ts +3 -5
- package/src/skia/types/Skia.ts +1 -1
- package/src/skia/web/JsiSkCanvas.ts +2 -2
- package/src/skia/web/JsiSkFont.ts +7 -3
- package/src/skia/web/JsiSkFontMgr.ts +0 -4
- package/src/skia/web/JsiSkImage.ts +37 -16
- package/src/skia/web/{JsiImageFilterFactory.ts → JsiSkImageFilterFactory.ts} +0 -0
- package/src/skia/web/JsiSkPaint.ts +1 -1
- package/src/skia/web/JsiSkPath.ts +64 -47
- package/src/skia/web/JsiSkShaderFactory.ts +4 -1
- package/src/skia/web/JsiSkVerticesFactory.ts +15 -1
- package/src/skia/web/JsiSkia.ts +2 -2
- package/src/values/api.ts +1 -1
- package/src/values/api.web.ts +1 -1
- package/src/values/hooks/index.ts +1 -1
- package/src/values/hooks/{useDerivedValue.ts → useComputedValue.ts} +8 -3
- package/src/values/types.ts +2 -2
- package/src/values/web/{RNSkDerivedValue.ts → RNSkComputedValue.ts} +1 -1
- package/src/values/web/api.ts +3 -3
- package/src/views/SkiaView.web.tsx +9 -11
- package/src/web/index.ts +3 -1
- package/lib/commonjs/skia/web/JsiImageFilterFactory.js.map +0 -1
- package/lib/commonjs/values/hooks/useDerivedValue.js +0 -25
- package/lib/commonjs/values/hooks/useDerivedValue.js.map +0 -1
- package/lib/commonjs/values/web/RNSkDerivedValue.js.map +0 -1
- package/lib/module/skia/web/JsiImageFilterFactory.js.map +0 -1
- package/lib/module/values/hooks/useDerivedValue.js +0 -14
- package/lib/module/values/hooks/useDerivedValue.js.map +0 -1
- package/lib/module/values/web/RNSkDerivedValue.js.map +0 -1
@@ -16,9 +16,9 @@ export declare enum StrokeCap {
|
|
16
16
|
Square = 2
|
17
17
|
}
|
18
18
|
export declare enum StrokeJoin {
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
Miter = 0,
|
20
|
+
Round = 1,
|
21
|
+
Bevel = 2
|
22
22
|
}
|
23
23
|
export declare const isPaint: (obj: SkJSIInstance<string> | null) => obj is SkPaint;
|
24
24
|
export interface SkPaint extends SkJSIInstance<"Paint"> {
|
@@ -6,6 +6,7 @@ export interface SkSLUniform {
|
|
6
6
|
rows: number;
|
7
7
|
/** The index into the uniforms array that this uniform begins. */
|
8
8
|
slot: number;
|
9
|
+
isInteger: boolean;
|
9
10
|
}
|
10
11
|
export interface SkRuntimeShaderBuilder extends SkJSIInstance<"RuntimeShaderBuilder"> {
|
11
12
|
setUniform(name: string, value: readonly number[]): void;
|
@@ -39,7 +39,7 @@ export interface Skia {
|
|
39
39
|
PictureRecorder: () => SkPictureRecorder;
|
40
40
|
Picture: PictureFactory;
|
41
41
|
Path: PathFactory;
|
42
|
-
Matrix: (matrix?: number[]) => SkMatrix;
|
42
|
+
Matrix: (matrix?: readonly number[]) => SkMatrix;
|
43
43
|
ColorFilter: ColorFilterFactory;
|
44
44
|
Font: (typeface?: SkTypeface, size?: number) => SkFont;
|
45
45
|
Typeface: TypefaceFactory;
|
@@ -13,7 +13,7 @@ export declare class JsiSkFont extends HostObject<Font, "Font"> implements SkFon
|
|
13
13
|
bounds: JsiSkRect | undefined;
|
14
14
|
};
|
15
15
|
getGlyphIDs(str: string, numCodePoints?: number): number[];
|
16
|
-
getGlyphWidths(glyphs: number[], paint?: SkPaint | null):
|
16
|
+
getGlyphWidths(glyphs: number[], paint?: SkPaint | null): number[];
|
17
17
|
getGlyphIntercepts(glyphs: number[], positions: SkPoint[], top: number, bottom: number): number[];
|
18
18
|
getScaleX(): number;
|
19
19
|
getSize(): number;
|
@@ -5,8 +5,8 @@ export declare class JsiSkImage extends HostObject<Image, "Image"> implements Sk
|
|
5
5
|
constructor(CanvasKit: CanvasKit, ref: Image);
|
6
6
|
height(): number;
|
7
7
|
width(): number;
|
8
|
-
makeShaderOptions(
|
9
|
-
makeShaderCubic(
|
8
|
+
makeShaderOptions(tx: TileMode, ty: TileMode, fm: FilterMode, mm: MipmapMode, localMatrix?: SkMatrix): SkShader;
|
9
|
+
makeShaderCubic(tx: TileMode, ty: TileMode, B: number, C: number, localMatrix?: SkMatrix): SkShader;
|
10
10
|
encodeToBytes(fmt?: ImageFormat, quality?: number): Uint8Array;
|
11
|
-
encodeToBase64(
|
11
|
+
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
12
12
|
}
|
package/lib/typescript/src/skia/web/{JsiImageFilterFactory.d.ts → JsiSkImageFilterFactory.d.ts}
RENAMED
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { CanvasKit, Paint } from "canvaskit-wasm";
|
2
|
-
import type { BlendMode, SkColor, SkColorFilter, SkImageFilter, SkPaint, SkShader, StrokeCap,
|
2
|
+
import type { StrokeJoin, BlendMode, SkColor, SkColorFilter, SkImageFilter, SkPaint, SkShader, StrokeCap, PaintStyle, SkMaskFilter, SkPathEffect } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
4
|
export declare class JsiSkPaint extends HostObject<Paint, "Paint"> implements SkPaint {
|
5
5
|
constructor(CanvasKit: CanvasKit, ref: Paint);
|
@@ -3,4 +3,4 @@ declare global {
|
|
3
3
|
var SkiaValueApi: ISkiaValueApi;
|
4
4
|
}
|
5
5
|
export declare const ValueApi: ISkiaValueApi;
|
6
|
-
export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>,
|
6
|
+
export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>, createComputedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
|
@@ -1,2 +1,2 @@
|
|
1
1
|
export declare const ValueApi: import("./types").ISkiaValueApi;
|
2
|
-
export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>,
|
2
|
+
export declare const createValue: <T>(initialValue: T) => import("./types").SkiaMutableValue<T>, createComputedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
|
@@ -1,8 +1,9 @@
|
|
1
1
|
/**
|
2
|
-
* Creates a new
|
2
|
+
* Creates a new computed value - a value that will calculate its value depending
|
3
3
|
* on other values.
|
4
4
|
* @param cb Callback to calculate new value
|
5
5
|
* @param values Dependant values
|
6
6
|
* @returns A readonly value
|
7
7
|
*/
|
8
|
+
export declare const useComputedValue: <R>(cb: () => R, values: unknown[]) => import("..").SkiaValue<R>;
|
8
9
|
export declare const useDerivedValue: <R>(cb: () => R, values: unknown[]) => import("..").SkiaValue<R>;
|
@@ -41,10 +41,10 @@ export interface ISkiaValueApi {
|
|
41
41
|
*/
|
42
42
|
createValue: <T>(initialValue: T) => SkiaMutableValue<T>;
|
43
43
|
/**
|
44
|
-
* Creates a
|
44
|
+
* Creates a computed value. This is a calculated value that returns the result of
|
45
45
|
* a function that is called with the values of the dependencies.
|
46
46
|
*/
|
47
|
-
|
47
|
+
createComputedValue: <R>(cb: () => R, values: Array<SkiaValue<unknown>>) => SkiaValue<R>;
|
48
48
|
/**
|
49
49
|
* Creates a clock value where the value is the number of milliseconds elapsed
|
50
50
|
* since the clock was created
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { DependencyList } from "react";
|
2
2
|
import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
|
3
|
-
export declare class
|
3
|
+
export declare class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {
|
4
4
|
constructor(callback: () => T, dependencies: DependencyList);
|
5
5
|
private dependecyUpdated;
|
6
6
|
private _callback;
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"access": "public"
|
5
5
|
},
|
6
6
|
"title": "React Native Skia",
|
7
|
-
"version": "0.1.
|
7
|
+
"version": "0.1.134",
|
8
8
|
"description": "High-performance React Native Graphics using Skia",
|
9
9
|
"main": "lib/module/index.js",
|
10
10
|
"files": [
|
@@ -70,6 +70,7 @@
|
|
70
70
|
"@types/react-reconciler": "^0.26.4",
|
71
71
|
"eslint": "7.32.0",
|
72
72
|
"eslint-config-react-native-wcandillon": "^3.7.2",
|
73
|
+
"eslint-plugin-reanimated": "^1.2.6",
|
73
74
|
"jest": "^27.4.3",
|
74
75
|
"patch-package": "^6.4.7",
|
75
76
|
"react": "17.0.2",
|
@@ -0,0 +1,156 @@
|
|
1
|
+
/**
|
2
|
+
* Mock implementation for test runners.
|
3
|
+
*
|
4
|
+
* Example:
|
5
|
+
*
|
6
|
+
* ```js
|
7
|
+
* jest.mock('@shopify/react-native-skia', () => require('@shopify/react-native-skia/lib/commonjs/mock'));
|
8
|
+
* ```
|
9
|
+
*/
|
10
|
+
|
11
|
+
import type { Skia as SkiaApi, SkRect } from "../skia/types";
|
12
|
+
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
14
|
+
const MockJSIInstance: any = {};
|
15
|
+
const Noop = () => MockJSIInstance;
|
16
|
+
|
17
|
+
export const Skia: SkiaApi = {
|
18
|
+
Point: Noop,
|
19
|
+
XYWHRect: Noop,
|
20
|
+
RuntimeShaderBuilder: Noop,
|
21
|
+
RRectXY: Noop,
|
22
|
+
RSXform: Noop,
|
23
|
+
Color: Noop,
|
24
|
+
ContourMeasureIter: Noop,
|
25
|
+
Paint: Noop,
|
26
|
+
PictureRecorder: Noop,
|
27
|
+
Picture: {
|
28
|
+
MakePicture: Noop,
|
29
|
+
},
|
30
|
+
Path: {
|
31
|
+
Make: Noop,
|
32
|
+
MakeFromSVGString: Noop,
|
33
|
+
MakeFromOp: Noop,
|
34
|
+
MakeFromCmds: Noop,
|
35
|
+
MakeFromText: Noop,
|
36
|
+
},
|
37
|
+
Matrix: Noop,
|
38
|
+
ColorFilter: {
|
39
|
+
MakeMatrix: Noop,
|
40
|
+
MakeBlend: Noop,
|
41
|
+
MakeCompose: Noop,
|
42
|
+
MakeLerp: Noop,
|
43
|
+
MakeLinearToSRGBGamma: Noop,
|
44
|
+
MakeSRGBToLinearGamma: Noop,
|
45
|
+
MakeLumaColorFilter: Noop,
|
46
|
+
},
|
47
|
+
Font: Noop,
|
48
|
+
Typeface: {
|
49
|
+
MakeFreeTypeFaceFromData: Noop,
|
50
|
+
},
|
51
|
+
MaskFilter: {
|
52
|
+
MakeBlur: Noop,
|
53
|
+
},
|
54
|
+
RuntimeEffect: {
|
55
|
+
Make: Noop,
|
56
|
+
},
|
57
|
+
ImageFilter: {
|
58
|
+
MakeOffset: Noop,
|
59
|
+
MakeDisplacementMap: Noop,
|
60
|
+
MakeShader: Noop,
|
61
|
+
MakeBlur: Noop,
|
62
|
+
MakeColorFilter: Noop,
|
63
|
+
MakeCompose: Noop,
|
64
|
+
MakeDropShadow: Noop,
|
65
|
+
MakeDropShadowOnly: Noop,
|
66
|
+
MakeErode: Noop,
|
67
|
+
MakeDilate: Noop,
|
68
|
+
MakeBlend: Noop,
|
69
|
+
MakeRuntimeShader: Noop,
|
70
|
+
},
|
71
|
+
Shader: {
|
72
|
+
MakeLinearGradient: Noop,
|
73
|
+
MakeRadialGradient: Noop,
|
74
|
+
MakeTwoPointConicalGradient: Noop,
|
75
|
+
MakeSweepGradient: Noop,
|
76
|
+
MakeTurbulence: Noop,
|
77
|
+
MakeFractalNoise: Noop,
|
78
|
+
MakeBlend: Noop,
|
79
|
+
MakeColor: Noop,
|
80
|
+
},
|
81
|
+
PathEffect: {
|
82
|
+
MakeCorner: Noop,
|
83
|
+
MakeDash: Noop,
|
84
|
+
MakeDiscrete: Noop,
|
85
|
+
MakeCompose: Noop,
|
86
|
+
MakeSum: Noop,
|
87
|
+
MakeLine2D: Noop,
|
88
|
+
MakePath1D: Noop,
|
89
|
+
MakePath2D: Noop,
|
90
|
+
},
|
91
|
+
MakeVertices: Noop,
|
92
|
+
Data: {
|
93
|
+
fromURI: Noop,
|
94
|
+
fromBytes: Noop,
|
95
|
+
fromBase64: Noop,
|
96
|
+
},
|
97
|
+
Image: {
|
98
|
+
MakeImageFromEncoded: Noop,
|
99
|
+
MakeImage: Noop,
|
100
|
+
},
|
101
|
+
SVG: {
|
102
|
+
MakeFromData: Noop,
|
103
|
+
MakeFromString: Noop,
|
104
|
+
},
|
105
|
+
FontMgr: {
|
106
|
+
RefDefault: Noop,
|
107
|
+
},
|
108
|
+
TextBlob: {
|
109
|
+
MakeFromText: Noop,
|
110
|
+
MakeFromGlyphs: Noop,
|
111
|
+
MakeFromRSXform: Noop,
|
112
|
+
MakeFromRSXformGlyphs: Noop,
|
113
|
+
},
|
114
|
+
Surface: {
|
115
|
+
Make: Noop,
|
116
|
+
},
|
117
|
+
};
|
118
|
+
|
119
|
+
export const vec = (x: number, y: number) => ({ x, y });
|
120
|
+
|
121
|
+
export const rect = (x: number, y: number, width: number, height: number) => ({
|
122
|
+
x,
|
123
|
+
y,
|
124
|
+
width,
|
125
|
+
height,
|
126
|
+
});
|
127
|
+
|
128
|
+
export const rrect = (r: SkRect, rx: number, ry: number) => ({
|
129
|
+
rect: r,
|
130
|
+
rx,
|
131
|
+
ry,
|
132
|
+
});
|
133
|
+
|
134
|
+
export const useTouchHandler = Noop;
|
135
|
+
export const useComputedValue = Noop;
|
136
|
+
export const useValue = Noop;
|
137
|
+
export const useClockValue = Noop;
|
138
|
+
export const useValueEffect = Noop;
|
139
|
+
export const useTiming = Noop;
|
140
|
+
export const runTiming = Noop;
|
141
|
+
export const timing = Noop;
|
142
|
+
export const useSpring = Noop;
|
143
|
+
export const runSpring = Noop;
|
144
|
+
export const spring = Noop;
|
145
|
+
export const runDecay = Noop;
|
146
|
+
export const decay = Noop;
|
147
|
+
|
148
|
+
export const useSharedValueEffect = Noop;
|
149
|
+
|
150
|
+
export const useData = Noop;
|
151
|
+
export const useDataCollection = Noop;
|
152
|
+
export const useFont = Noop;
|
153
|
+
export const useImage = Noop;
|
154
|
+
export const usePicture = Noop;
|
155
|
+
export const useSVG = Noop;
|
156
|
+
export const useTypeface = Noop;
|
package/src/skia/core/Data.ts
CHANGED
@@ -11,71 +11,88 @@ const resolveAsset = (source: ReturnType<typeof require>) => {
|
|
11
11
|
: Image.resolveAssetSource(source).uri;
|
12
12
|
};
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
factory: (data: SkData
|
17
|
-
|
14
|
+
const factoryWrapper = <T>(
|
15
|
+
data2: SkData,
|
16
|
+
factory: (data: SkData) => T,
|
17
|
+
onError?: (err: Error) => void
|
18
18
|
) => {
|
19
|
-
const
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
});
|
27
|
-
Promise.all(
|
28
|
-
bytesOrURIs.map((bytesOrURI) =>
|
29
|
-
bytesOrURI instanceof Uint8Array
|
30
|
-
? Skia.Data.fromBytes(bytesOrURI)
|
31
|
-
: Skia.Data.fromURI(bytesOrURI)
|
32
|
-
)
|
33
|
-
).then((d) => setData(factory(d)));
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
35
|
-
}, deps);
|
36
|
-
return data;
|
19
|
+
const factoryResult = factory(data2);
|
20
|
+
if (factoryResult === null) {
|
21
|
+
onError && onError(new Error("Could not load data"));
|
22
|
+
return null;
|
23
|
+
} else {
|
24
|
+
return factoryResult;
|
25
|
+
}
|
37
26
|
};
|
38
27
|
|
39
|
-
|
40
|
-
|
28
|
+
const loadDataCollection = <T>(
|
29
|
+
sources: DataSource[],
|
30
|
+
factory: (data: SkData) => T,
|
31
|
+
onError?: (err: Error) => void
|
32
|
+
): Promise<(T | null)[]> =>
|
33
|
+
Promise.all(sources.map((source) => loadData(source, factory, onError)));
|
34
|
+
|
35
|
+
const loadData = <T>(
|
36
|
+
source: DataSource,
|
41
37
|
factory: (data: SkData) => T,
|
42
38
|
onError?: (err: Error) => void
|
39
|
+
): Promise<T | null> => {
|
40
|
+
if (source instanceof Uint8Array) {
|
41
|
+
return new Promise((resolve) =>
|
42
|
+
resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))
|
43
|
+
);
|
44
|
+
} else {
|
45
|
+
const uri = typeof source === "string" ? source : resolveAsset(source);
|
46
|
+
return Skia.Data.fromURI(uri).then((d) =>
|
47
|
+
factoryWrapper(d, factory, onError)
|
48
|
+
);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
type Source = DataSource | null | undefined;
|
53
|
+
|
54
|
+
const useLoading = <T>(
|
55
|
+
source: Source,
|
56
|
+
loader: () => Promise<T | null>,
|
57
|
+
deps: DependencyList = []
|
43
58
|
) => {
|
44
59
|
const [data, setData] = useState<T | null>(null);
|
45
|
-
const prevSourceRef = useRef<
|
60
|
+
const prevSourceRef = useRef<Source>();
|
46
61
|
useEffect(() => {
|
47
|
-
// Track to avoid re-fetching the same data
|
48
62
|
if (prevSourceRef.current !== source) {
|
49
63
|
prevSourceRef.current = source;
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if (factoryResult === null) {
|
54
|
-
onError && onError(new Error("Could not load data"));
|
55
|
-
setData(null);
|
56
|
-
} else {
|
57
|
-
setData(factoryResult);
|
58
|
-
}
|
59
|
-
};
|
60
|
-
if (source instanceof Uint8Array) {
|
61
|
-
factoryWrapper(Skia.Data.fromBytes(source));
|
62
|
-
} else {
|
63
|
-
const uri =
|
64
|
-
typeof source === "string" ? source : resolveAsset(source);
|
65
|
-
Skia.Data.fromURI(uri).then((d) => factoryWrapper(d));
|
66
|
-
}
|
67
|
-
} else {
|
68
|
-
// new source is null or undefined -> remove cached data
|
69
|
-
setData(null);
|
70
|
-
}
|
64
|
+
loader().then(setData);
|
65
|
+
} else {
|
66
|
+
setData(null);
|
71
67
|
}
|
72
|
-
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
69
|
+
}, deps);
|
73
70
|
return data;
|
74
71
|
};
|
75
72
|
|
73
|
+
export const useDataCollection = <T>(
|
74
|
+
sources: DataSource[],
|
75
|
+
factory: (data: SkData) => T,
|
76
|
+
onError?: (err: Error) => void,
|
77
|
+
deps?: DependencyList
|
78
|
+
) =>
|
79
|
+
useLoading(
|
80
|
+
sources,
|
81
|
+
() => loadDataCollection(sources, factory, onError),
|
82
|
+
deps
|
83
|
+
);
|
84
|
+
|
85
|
+
export const useRawData = <T>(
|
86
|
+
source: DataSource | null | undefined,
|
87
|
+
factory: (data: SkData) => T,
|
88
|
+
onError?: (err: Error) => void,
|
89
|
+
deps?: DependencyList
|
90
|
+
) => useLoading(source, () => loadData(source, factory, onError), deps);
|
91
|
+
|
76
92
|
const identity = (data: SkData) => data;
|
77
93
|
|
78
94
|
export const useData = (
|
79
95
|
source: DataSource | null | undefined,
|
80
|
-
onError?: (err: Error) => void
|
81
|
-
|
96
|
+
onError?: (err: Error) => void,
|
97
|
+
deps?: DependencyList
|
98
|
+
) => useRawData(source, identity, onError, deps);
|
@@ -8,4 +8,9 @@ import { useRawData } from "./Data";
|
|
8
8
|
export const useTypeface = (
|
9
9
|
source: DataSource | null | undefined,
|
10
10
|
onError?: (err: Error) => void
|
11
|
-
) =>
|
11
|
+
) =>
|
12
|
+
useRawData(
|
13
|
+
source,
|
14
|
+
Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface),
|
15
|
+
onError
|
16
|
+
);
|
@@ -12,6 +12,15 @@ export interface FontMetrics {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
export interface SkFont extends SkJSIInstance<"Font"> {
|
15
|
+
/**
|
16
|
+
* Retrieves the advanceX measurements for each glyph.
|
17
|
+
* If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
|
18
|
+
* One width per glyph is returned in the returned array.
|
19
|
+
* @param glyphs
|
20
|
+
* @param paint
|
21
|
+
*/
|
22
|
+
getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
|
23
|
+
|
15
24
|
/** Returns the advance width of text.
|
16
25
|
The advance is the normal distance to move before drawing additional text.
|
17
26
|
Returns the bounding box of text if bounds is not nullptr. The paint
|
@@ -39,20 +48,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
|
|
39
48
|
*/
|
40
49
|
getGlyphIDs(str: string, numCodePoints?: number): number[];
|
41
50
|
|
42
|
-
/**
|
43
|
-
* Retrieves the advanceX measurements for each glyph.
|
44
|
-
* If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
|
45
|
-
* One width per glyph is returned in the returned array.
|
46
|
-
* @param glyphs
|
47
|
-
* @param paint
|
48
|
-
* @param output - if provided, the results will be copied into this array.
|
49
|
-
*/
|
50
|
-
getGlyphWidths(
|
51
|
-
glyphs: number[],
|
52
|
-
paint?: SkPaint | null,
|
53
|
-
output?: Float32Array
|
54
|
-
): Float32Array;
|
55
|
-
|
56
51
|
/**
|
57
52
|
* Computes any intersections of a thick "line" and a run of positionsed glyphs.
|
58
53
|
* The thick line is represented as a top and bottom coordinate (positive for
|
@@ -4,8 +4,8 @@ import type { TileMode } from "../ImageFilter";
|
|
4
4
|
import type { SkShader } from "../Shader";
|
5
5
|
|
6
6
|
export enum FilterMode {
|
7
|
-
Linear,
|
8
7
|
Nearest,
|
8
|
+
Linear,
|
9
9
|
}
|
10
10
|
|
11
11
|
export enum MipmapMode {
|
@@ -15,9 +15,9 @@ export enum MipmapMode {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
export enum ImageFormat {
|
18
|
-
|
19
|
-
|
20
|
-
WEBP,
|
18
|
+
JPEG = 3,
|
19
|
+
PNG = 4,
|
20
|
+
WEBP = 6,
|
21
21
|
}
|
22
22
|
|
23
23
|
export interface SkImage extends SkJSIInstance<"Image"> {
|
@@ -40,11 +40,9 @@ export const processUniforms = (
|
|
40
40
|
if (value === undefined) {
|
41
41
|
throw new Error(`No value specified for uniform ${name}`);
|
42
42
|
}
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
47
|
-
result = processValue(value as UniformValue);
|
43
|
+
const result = Array.isArray(value)
|
44
|
+
? value.flatMap(processValue)
|
45
|
+
: processValue(value as UniformValue);
|
48
46
|
builder?.setUniform(name, typeof result === "number" ? [result] : result);
|
49
47
|
return result;
|
50
48
|
});
|
package/src/skia/types/Skia.ts
CHANGED
@@ -48,7 +48,7 @@ export interface Skia {
|
|
48
48
|
PictureRecorder: () => SkPictureRecorder;
|
49
49
|
Picture: PictureFactory;
|
50
50
|
Path: PathFactory;
|
51
|
-
Matrix: (matrix?: number[]) => SkMatrix;
|
51
|
+
Matrix: (matrix?: readonly number[]) => SkMatrix;
|
52
52
|
ColorFilter: ColorFilterFactory;
|
53
53
|
Font: (typeface?: SkTypeface, size?: number) => SkFont;
|
54
54
|
Typeface: TypefaceFactory;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Canvas, Image,
|
1
|
+
import type { Canvas, Image, CanvasKit, Paint } from "canvaskit-wasm";
|
2
2
|
|
3
3
|
import type {
|
4
4
|
BlendMode,
|
@@ -250,7 +250,7 @@ export class JsiSkCanvas
|
|
250
250
|
) {
|
251
251
|
this.ref.drawGlyphs(
|
252
252
|
glyphs,
|
253
|
-
|
253
|
+
positions.map((p) => [p.x, p.y]).flat(),
|
254
254
|
x,
|
255
255
|
y,
|
256
256
|
toValue(font),
|
@@ -10,7 +10,7 @@ import type {
|
|
10
10
|
SkTypeface,
|
11
11
|
} from "../types";
|
12
12
|
|
13
|
-
import { HostObject,
|
13
|
+
import { HostObject, toValue, ckEnum } from "./Host";
|
14
14
|
import { JsiSkRect } from "./JsiSkRect";
|
15
15
|
import { JsiSkTypeface } from "./JsiSkTypeface";
|
16
16
|
|
@@ -20,7 +20,11 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
measureText(_text: string, _paint?: SkPaint): SkRect {
|
23
|
-
|
23
|
+
console.warn(
|
24
|
+
`measureText() is deprecated an returns an empty rectangle on React Native Web.
|
25
|
+
Clients should use "Font.getGlyphWidths" instead (the latter does no shaping)`
|
26
|
+
);
|
27
|
+
return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
|
24
28
|
}
|
25
29
|
|
26
30
|
getMetrics() {
|
@@ -42,7 +46,7 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
|
42
46
|
|
43
47
|
// TODO: Fix return value in the C++ implementation, it return float32
|
44
48
|
getGlyphWidths(glyphs: number[], paint?: SkPaint | null) {
|
45
|
-
return this.ref.getGlyphWidths(glyphs, paint ? toValue(paint) : null);
|
49
|
+
return [...this.ref.getGlyphWidths(glyphs, paint ? toValue(paint) : null)];
|
46
50
|
}
|
47
51
|
|
48
52
|
getGlyphIntercepts(
|
@@ -9,10 +9,6 @@ export class JsiSkFontMgr
|
|
9
9
|
implements SkFontMgr
|
10
10
|
{
|
11
11
|
constructor(CanvasKit: CanvasKit) {
|
12
|
-
console.warn(
|
13
|
-
// eslint-disable-next-line max-len
|
14
|
-
"Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts"
|
15
|
-
);
|
16
12
|
super(CanvasKit, null, "FontMgr");
|
17
13
|
}
|
18
14
|
|