@shopify/react-native-skia 0.1.134 → 0.1.136
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkFont.h +25 -1
- package/jestSetup.js +5 -0
- package/lib/commonjs/animation/functions/interpolate.js +3 -2
- package/lib/commonjs/animation/functions/interpolate.js.map +1 -1
- package/lib/commonjs/animation/functions/interpolateColors.js +2 -2
- package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -1
- package/lib/commonjs/animation/functions/interpolatePaths.js +45 -11
- package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
- package/lib/commonjs/mock/index.js +121 -177
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +6 -0
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/values/api.js +1 -7
- package/lib/commonjs/values/api.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.js +2 -2
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +11 -11
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/module/animation/functions/interpolate.js +2 -2
- package/lib/module/animation/functions/interpolate.js.map +1 -1
- package/lib/module/animation/functions/interpolateColors.js +1 -1
- package/lib/module/animation/functions/interpolateColors.js.map +1 -1
- package/lib/module/animation/functions/interpolatePaths.js +44 -11
- package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
- package/lib/module/mock/index.js +103 -147
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/types/Font/Font.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +6 -0
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/values/api.js +0 -4
- package/lib/module/values/api.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.js +1 -1
- package/lib/module/values/hooks/useComputedValue.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +11 -11
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/typescript/jestSetup.d.ts +1 -0
- package/lib/typescript/src/animation/functions/interpolate.d.ts +6 -0
- package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +3 -1
- package/lib/typescript/src/mock/index.d.ts +11 -42
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
- package/lib/typescript/src/skia/types/Font/Font.d.ts +6 -0
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -0
- package/lib/typescript/src/values/api.d.ts +0 -1
- package/package.json +3 -3
- package/src/animation/functions/interpolate.ts +4 -2
- package/src/animation/functions/interpolateColors.ts +1 -1
- package/src/animation/functions/interpolatePaths.ts +59 -10
- package/src/mock/index.ts +103 -149
- package/src/skia/types/Font/Font.ts +7 -0
- package/src/skia/web/JsiSkFont.ts +6 -0
- package/src/values/api.ts +0 -2
- package/src/values/hooks/useComputedValue.ts +1 -1
- package/src/views/SkiaView.web.tsx +20 -17
@@ -1,47 +1,16 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
*
|
6
|
-
|
7
|
-
* jest.mock('@shopify/react-native-skia', () => require('@shopify/react-native-skia/lib/commonjs/mock'));
|
8
|
-
* ```
|
9
|
-
*/
|
10
|
-
import type { Skia as SkiaApi, SkRect } from "../skia/types";
|
1
|
+
import type { Skia as SkiaApi } from "../skia/types";
|
2
|
+
import type * as SkiaExports from "../skia";
|
3
|
+
import type * as ExternalExports from "../external";
|
4
|
+
import type * as ValueExports from "../values";
|
5
|
+
import type * as AnimationExports from "../animation";
|
6
|
+
import { ShaderLib } from "../renderer/components/shaders/ShaderLib";
|
11
7
|
export declare const Skia: SkiaApi;
|
12
|
-
export declare const vec: (x
|
8
|
+
export declare const vec: (x?: number | undefined, y?: number | undefined) => {
|
13
9
|
x: number;
|
14
10
|
y: number;
|
15
11
|
};
|
16
|
-
export declare const
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
height: number;
|
21
|
-
};
|
22
|
-
export declare const rrect: (r: SkRect, rx: number, ry: number) => {
|
23
|
-
rect: SkRect;
|
24
|
-
rx: number;
|
25
|
-
ry: number;
|
12
|
+
export declare const Mock: typeof SkiaExports & typeof ExternalExports & typeof ValueExports & typeof AnimationExports & {
|
13
|
+
createDrawing: () => any;
|
14
|
+
createDeclaration: () => any;
|
15
|
+
ShaderLib: typeof ShaderLib;
|
26
16
|
};
|
27
|
-
export declare const useTouchHandler: () => any;
|
28
|
-
export declare const useComputedValue: () => any;
|
29
|
-
export declare const useValue: () => any;
|
30
|
-
export declare const useClockValue: () => any;
|
31
|
-
export declare const useValueEffect: () => any;
|
32
|
-
export declare const useTiming: () => any;
|
33
|
-
export declare const runTiming: () => any;
|
34
|
-
export declare const timing: () => any;
|
35
|
-
export declare const useSpring: () => any;
|
36
|
-
export declare const runSpring: () => any;
|
37
|
-
export declare const spring: () => any;
|
38
|
-
export declare const runDecay: () => any;
|
39
|
-
export declare const decay: () => any;
|
40
|
-
export declare const useSharedValueEffect: () => any;
|
41
|
-
export declare const useData: () => any;
|
42
|
-
export declare const useDataCollection: () => any;
|
43
|
-
export declare const useFont: () => any;
|
44
|
-
export declare const useImage: () => any;
|
45
|
-
export declare const usePicture: () => any;
|
46
|
-
export declare const useSVG: () => any;
|
47
|
-
export declare const useTypeface: () => any;
|
@@ -13,4 +13,4 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
|
|
13
13
|
onTouch?: TouchHandler;
|
14
14
|
fontMgr?: SkFontMgr;
|
15
15
|
}
|
16
|
-
export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "
|
16
|
+
export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "testID" | "nativeID" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "fontMgr" | "onTouch"> & React.RefAttributes<SkiaView>>;
|
@@ -10,6 +10,12 @@ export interface FontMetrics {
|
|
10
10
|
bounds?: SkRect;
|
11
11
|
}
|
12
12
|
export interface SkFont extends SkJSIInstance<"Font"> {
|
13
|
+
/**
|
14
|
+
* Retrieves the total width of the provided text
|
15
|
+
* @param text
|
16
|
+
* @param paint
|
17
|
+
*/
|
18
|
+
getTextWidth(text: string, paint?: SkPaint): number;
|
13
19
|
/**
|
14
20
|
* Retrieves the advanceX measurements for each glyph.
|
15
21
|
* If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
|
@@ -6,6 +6,7 @@ import { JsiSkTypeface } from "./JsiSkTypeface";
|
|
6
6
|
export declare class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
7
7
|
constructor(CanvasKit: CanvasKit, ref: Font);
|
8
8
|
measureText(_text: string, _paint?: SkPaint): SkRect;
|
9
|
+
getTextWidth(text: string, paint?: SkPaint | undefined): number;
|
9
10
|
getMetrics(): {
|
10
11
|
ascent: number;
|
11
12
|
descent: number;
|
@@ -3,4 +3,3 @@ 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>, createComputedValue: <R>(cb: () => R, values: import("./types").SkiaValue<unknown>[]) => import("./types").SkiaValue<R>;
|
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.136",
|
8
8
|
"description": "High-performance React Native Graphics using Skia",
|
9
9
|
"main": "lib/module/index.js",
|
10
10
|
"files": [
|
@@ -21,6 +21,7 @@
|
|
21
21
|
"android/src/**",
|
22
22
|
"libs/android/**",
|
23
23
|
"index.js",
|
24
|
+
"jestSetup.js",
|
24
25
|
"cpp/**/*.{h,cpp}",
|
25
26
|
"ios",
|
26
27
|
"libs/ios/libskia.xcframework",
|
@@ -72,7 +73,6 @@
|
|
72
73
|
"eslint-config-react-native-wcandillon": "^3.7.2",
|
73
74
|
"eslint-plugin-reanimated": "^1.2.6",
|
74
75
|
"jest": "^27.4.3",
|
75
|
-
"patch-package": "^6.4.7",
|
76
76
|
"react": "17.0.2",
|
77
77
|
"react-native": "0.66.2",
|
78
78
|
"react-native-builder-bob": "^0.18.2",
|
@@ -80,7 +80,7 @@
|
|
80
80
|
"typescript": "^4.6.4"
|
81
81
|
},
|
82
82
|
"dependencies": {
|
83
|
-
"canvaskit-wasm": "^0.
|
83
|
+
"canvaskit-wasm": "^0.35.0",
|
84
84
|
"react-reconciler": "^0.26.2"
|
85
85
|
},
|
86
86
|
"eslintIgnore": [
|
@@ -60,7 +60,9 @@ function isExtrapolate(value: string): value is Extrapolate {
|
|
60
60
|
|
61
61
|
// validates extrapolations type
|
62
62
|
// if type is correct, converts it to ExtrapolationConfig
|
63
|
-
function
|
63
|
+
export function validateInterpolationOptions(
|
64
|
+
type: ExtrapolationType
|
65
|
+
): RequiredExtrapolationConfig {
|
64
66
|
// initialize extrapolationConfig with default extrapolation
|
65
67
|
const extrapolationConfig: RequiredExtrapolationConfig = {
|
66
68
|
extrapolateLeft: Extrapolate.EXTEND,
|
@@ -151,7 +153,7 @@ export function interpolate(
|
|
151
153
|
);
|
152
154
|
}
|
153
155
|
|
154
|
-
const extrapolationConfig =
|
156
|
+
const extrapolationConfig = validateInterpolationOptions(type);
|
155
157
|
const { length } = input;
|
156
158
|
const narrowedInput: InterpolationNarrowedInput = {
|
157
159
|
leftEdgeInput: input[0],
|
@@ -1,10 +1,26 @@
|
|
1
1
|
import type { SkPath } from "../../skia/types";
|
2
|
+
import { exhaustiveCheck } from "../../renderer/typeddash";
|
3
|
+
|
4
|
+
import type { ExtrapolationType } from "./interpolate";
|
5
|
+
import { validateInterpolationOptions, Extrapolate } from "./interpolate";
|
6
|
+
|
7
|
+
const lerp = (
|
8
|
+
value: number,
|
9
|
+
from: number,
|
10
|
+
to: number,
|
11
|
+
p1: SkPath,
|
12
|
+
p2: SkPath
|
13
|
+
) => {
|
14
|
+
const t = (value - from) / (to - from);
|
15
|
+
return p2.interpolate(p1, t)!;
|
16
|
+
};
|
2
17
|
|
3
18
|
/**
|
4
19
|
* Maps an input value within a range to an output path within a path range.
|
5
20
|
* @param value - The input value.
|
6
21
|
* @param inputRange - The range of the input value.
|
7
22
|
* @param outputRange - The range of the output path.
|
23
|
+
* @param options - Extrapolation options
|
8
24
|
* @returns The output path.
|
9
25
|
* @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>
|
10
26
|
* const path1 = new Path();
|
@@ -18,21 +34,54 @@ import type { SkPath } from "../../skia/types";
|
|
18
34
|
export const interpolatePaths = (
|
19
35
|
value: number,
|
20
36
|
input: number[],
|
21
|
-
outputRange: SkPath[]
|
37
|
+
outputRange: SkPath[],
|
38
|
+
options?: ExtrapolationType
|
22
39
|
) => {
|
40
|
+
const extrapolation = validateInterpolationOptions(options);
|
41
|
+
if (value < input[0]) {
|
42
|
+
switch (extrapolation.extrapolateLeft) {
|
43
|
+
case Extrapolate.CLAMP:
|
44
|
+
return outputRange[0];
|
45
|
+
case Extrapolate.EXTEND:
|
46
|
+
return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);
|
47
|
+
case Extrapolate.IDENTITY:
|
48
|
+
throw new Error(
|
49
|
+
"Identity is not a supported extrapolation type for interpolatePaths()"
|
50
|
+
);
|
51
|
+
default:
|
52
|
+
exhaustiveCheck(extrapolation.extrapolateLeft);
|
53
|
+
}
|
54
|
+
} else if (value > input[input.length - 1]) {
|
55
|
+
switch (extrapolation.extrapolateRight) {
|
56
|
+
case Extrapolate.CLAMP:
|
57
|
+
return outputRange[outputRange.length - 1];
|
58
|
+
case Extrapolate.EXTEND:
|
59
|
+
return lerp(
|
60
|
+
value,
|
61
|
+
input[input.length - 2],
|
62
|
+
input[input.length - 1],
|
63
|
+
outputRange[input.length - 2],
|
64
|
+
outputRange[input.length - 1]
|
65
|
+
);
|
66
|
+
case Extrapolate.IDENTITY:
|
67
|
+
throw new Error(
|
68
|
+
"Identity is not a supported extrapolation type for interpolatePaths()"
|
69
|
+
);
|
70
|
+
default:
|
71
|
+
exhaustiveCheck(extrapolation.extrapolateRight);
|
72
|
+
}
|
73
|
+
}
|
23
74
|
let i = 0;
|
24
75
|
for (; i <= input.length - 1; i++) {
|
25
76
|
if (value >= input[i] && value <= input[i + 1]) {
|
26
77
|
break;
|
27
78
|
}
|
28
|
-
if (i === input.length - 1) {
|
29
|
-
if (value < input[0]) {
|
30
|
-
return outputRange[0];
|
31
|
-
} else {
|
32
|
-
return outputRange[i];
|
33
|
-
}
|
34
|
-
}
|
35
79
|
}
|
36
|
-
|
37
|
-
|
80
|
+
return lerp(
|
81
|
+
value,
|
82
|
+
input[i],
|
83
|
+
input[i + 1],
|
84
|
+
outputRange[i],
|
85
|
+
outputRange[i + 1]
|
86
|
+
);
|
38
87
|
};
|
package/src/mock/index.ts
CHANGED
@@ -1,156 +1,110 @@
|
|
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
|
-
*/
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
10
2
|
|
11
|
-
import type { Skia as SkiaApi, SkRect } from "../skia/types";
|
3
|
+
import type { Color, Skia as SkiaApi, SkRect, Vector } from "../skia/types";
|
4
|
+
import * as Values from "../values/web";
|
5
|
+
import * as ValuesHooks from "../values/hooks";
|
6
|
+
import * as BaseSkia from "../skia/types";
|
7
|
+
import type * as SkiaExports from "../skia";
|
8
|
+
import type * as ExternalExports from "../external";
|
9
|
+
import type * as ValueExports from "../values";
|
10
|
+
import type * as AnimationExports from "../animation";
|
11
|
+
import { useSharedValueEffect } from "../external/reanimated/useSharedValueEffect";
|
12
|
+
import * as timingFunctions from "../animation/timing";
|
13
|
+
import * as springFunctions from "../animation/spring";
|
14
|
+
import * as decayFunctions from "../animation/decay";
|
15
|
+
import * as interpolateFn from "../animation/functions/interpolate";
|
16
|
+
import * as interpolatePathFn from "../animation/functions/interpolatePaths";
|
17
|
+
import * as interpolateVectorFn from "../animation/functions/interpolateVector";
|
18
|
+
import { ShaderLib } from "../renderer/components/shaders/ShaderLib";
|
12
19
|
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
class Stub {
|
21
|
+
constructor() {
|
22
|
+
return new Proxy(() => {}, {
|
23
|
+
get: () => new Stub(),
|
24
|
+
apply: () => new Stub(),
|
25
|
+
set: () => true,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
}
|
16
29
|
|
17
|
-
|
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 });
|
30
|
+
const Noop: () => any = () => {};
|
120
31
|
|
121
|
-
export const
|
122
|
-
x,
|
123
|
-
y,
|
124
|
-
width,
|
125
|
-
height,
|
126
|
-
});
|
32
|
+
export const Skia: SkiaApi = new Stub() as any;
|
127
33
|
|
128
|
-
export const
|
129
|
-
rect: r,
|
130
|
-
rx,
|
131
|
-
ry,
|
132
|
-
});
|
34
|
+
export const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });
|
133
35
|
|
134
|
-
export const
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
36
|
+
export const Mock: typeof SkiaExports &
|
37
|
+
typeof ExternalExports &
|
38
|
+
typeof ValueExports &
|
39
|
+
typeof AnimationExports & {
|
40
|
+
createDrawing: () => any;
|
41
|
+
createDeclaration: () => any;
|
42
|
+
ShaderLib: typeof ShaderLib;
|
43
|
+
} = {
|
44
|
+
// SkiaExports
|
45
|
+
// 1. Skia API. BaseSkia contains the enums, and functions like isPaint etc
|
46
|
+
Skia,
|
47
|
+
...BaseSkia,
|
48
|
+
// 2. Hooks
|
49
|
+
useDataCollection: Noop,
|
50
|
+
useRawData: Noop,
|
51
|
+
useData: Noop,
|
52
|
+
useFont: Noop,
|
53
|
+
useTypeface: Noop,
|
54
|
+
useImage: Noop,
|
55
|
+
usePath: Noop,
|
56
|
+
useSVG: Noop,
|
57
|
+
useTextPath: Noop,
|
58
|
+
usePaint: Noop,
|
59
|
+
usePicture: Noop,
|
60
|
+
useSvgPath: Noop,
|
61
|
+
// 3. Point/Rect/Transform utilities
|
62
|
+
vec,
|
63
|
+
rect: (x: number, y: number, width: number, height: number) => ({
|
64
|
+
x,
|
65
|
+
y,
|
66
|
+
width,
|
67
|
+
height,
|
68
|
+
}),
|
69
|
+
rrect: (r: SkRect, rx: number, ry: number) => ({
|
70
|
+
rect: r,
|
71
|
+
rx,
|
72
|
+
ry,
|
73
|
+
}),
|
74
|
+
point: vec,
|
75
|
+
add: (a: Vector, b: Vector) => vec(a.x + b.x, a.y + b.y),
|
76
|
+
sub: (a: Vector, b: Vector) => vec(a.x - b.x, a.y - b.y),
|
77
|
+
neg: (a: Vector) => vec(-a.x, -a.y),
|
78
|
+
dist: (a: Vector, b: Vector) => Math.hypot(a.x - b.x, a.y - b.y),
|
79
|
+
translate: ({ x, y }: Vector) =>
|
80
|
+
[{ translateX: x }, { translateY: y }] as const,
|
147
81
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
82
|
+
bounds: Noop,
|
83
|
+
topLeft: Noop,
|
84
|
+
topRight: Noop,
|
85
|
+
bottomLeft: Noop,
|
86
|
+
bottomRight: Noop,
|
87
|
+
center: Noop,
|
88
|
+
processTransform2d: Noop,
|
89
|
+
// ExternalExports
|
90
|
+
useSharedValueEffect,
|
91
|
+
// ValueExports
|
92
|
+
...Values,
|
93
|
+
...ValuesHooks,
|
94
|
+
// Animations
|
95
|
+
...timingFunctions,
|
96
|
+
...springFunctions,
|
97
|
+
...decayFunctions,
|
98
|
+
...interpolateFn,
|
99
|
+
...interpolatePathFn,
|
100
|
+
...interpolateVectorFn,
|
101
|
+
interpolateColors: (
|
102
|
+
_value: number,
|
103
|
+
_inputRange: number[],
|
104
|
+
_outputRange: Color[]
|
105
|
+
) => Float32Array.of(0, 0, 0, 0),
|
106
|
+
mixColors: (_v: number, _x: Color, _y: Color) => Float32Array.of(0, 0, 0, 0),
|
107
|
+
ShaderLib,
|
108
|
+
createDrawing: Noop,
|
109
|
+
createDeclaration: Noop,
|
110
|
+
};
|
@@ -12,6 +12,13 @@ export interface FontMetrics {
|
|
12
12
|
}
|
13
13
|
|
14
14
|
export interface SkFont extends SkJSIInstance<"Font"> {
|
15
|
+
/**
|
16
|
+
* Retrieves the total width of the provided text
|
17
|
+
* @param text
|
18
|
+
* @param paint
|
19
|
+
*/
|
20
|
+
getTextWidth(text: string, paint?: SkPaint): number;
|
21
|
+
|
15
22
|
/**
|
16
23
|
* Retrieves the advanceX measurements for each glyph.
|
17
24
|
* If paint is not null, its stroking, PathEffect, and MaskFilter fields are respected.
|
@@ -27,6 +27,12 @@ Clients should use "Font.getGlyphWidths" instead (the latter does no shaping)`
|
|
27
27
|
return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
|
28
28
|
}
|
29
29
|
|
30
|
+
getTextWidth(text: string, paint?: SkPaint | undefined) {
|
31
|
+
const ids = this.getGlyphIDs(text);
|
32
|
+
const widths = this.getGlyphWidths(ids, paint);
|
33
|
+
return widths.reduce((a, b) => a + b, 0);
|
34
|
+
}
|
35
|
+
|
30
36
|
getMetrics() {
|
31
37
|
const result = this.ref.getMetrics();
|
32
38
|
return {
|
package/src/values/api.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { useMemo } from "react";
|
2
2
|
|
3
3
|
import { ValueApi } from "../api";
|
4
|
-
import { isValue } from "../../renderer/processors";
|
4
|
+
import { isValue } from "../../renderer/processors/Animations";
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Creates a new computed value - a value that will calculate its value depending
|
@@ -36,24 +36,27 @@ export class SkiaView extends React.Component<
|
|
36
36
|
}
|
37
37
|
|
38
38
|
private onLayout(evt: LayoutChangeEvent) {
|
39
|
-
this.setState(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
39
|
+
this.setState(
|
40
|
+
{
|
41
|
+
width: evt.nativeEvent.layout.width,
|
42
|
+
height: evt.nativeEvent.layout.height,
|
43
|
+
},
|
44
|
+
() => {
|
45
|
+
// Reset canvas / surface on layout change
|
46
|
+
if (this._canvasRef.current) {
|
47
|
+
// Create surface
|
48
|
+
this._surface = new JsiSkSurface(
|
49
|
+
global.CanvasKit,
|
50
|
+
global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!
|
51
|
+
);
|
52
|
+
// Get canvas and repaint
|
53
|
+
if (this._surface) {
|
54
|
+
this._canvas = this._surface.getCanvas();
|
55
|
+
this.requestRedraw();
|
56
|
+
}
|
57
|
+
}
|
55
58
|
}
|
56
|
-
|
59
|
+
);
|
57
60
|
}
|
58
61
|
|
59
62
|
componentDidMount() {
|