@shopify/react-native-skia 0.1.133 → 0.1.137
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -47
- package/android/CMakeLists.txt +1 -1
- package/android/build.gradle +17 -2
- package/cpp/api/JsiSkFont.h +25 -1
- package/cpp/api/JsiSkMatrix.h +12 -0
- package/cpp/rnskia/RNSkValueApi.h +6 -6
- package/cpp/rnskia/values/{RNSkDerivedValue.h → RNSkComputedValue.h} +7 -7
- package/ios/RNSkia-iOS/SkiaManager.mm +1 -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 +134 -0
- package/lib/commonjs/mock/index.js.map +1 -0
- package/lib/commonjs/renderer/components/Group.js +1 -1
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/processors/Transform.js +8 -15
- package/lib/commonjs/renderer/processors/Transform.js.map +1 -1
- 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/Matrix.js +17 -2
- package/lib/commonjs/skia/types/Matrix.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/skia/web/JsiSkMatrix.js +4 -0
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.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/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 +18 -18
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/web/LoadSkiaWeb.js +25 -0
- package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/WithSkiaWeb.js +38 -0
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -0
- package/lib/commonjs/web/index.js +22 -12
- package/lib/commonjs/web/index.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 +108 -0
- package/lib/module/mock/index.js.map +1 -0
- package/lib/module/renderer/components/Group.js +1 -1
- package/lib/module/renderer/components/Group.js.map +1 -1
- package/lib/module/renderer/processors/Transform.js +8 -15
- package/lib/module/renderer/processors/Transform.js.map +1 -1
- 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/Matrix.js +11 -1
- package/lib/module/skia/types/Matrix.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/skia/web/JsiSkMatrix.js +4 -0
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.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/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 +18 -18
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/web/LoadSkiaWeb.js +12 -0
- package/lib/module/web/LoadSkiaWeb.js.map +1 -0
- package/lib/module/web/WithSkiaWeb.js +22 -0
- package/lib/module/web/WithSkiaWeb.js.map +1 -0
- package/lib/module/web/index.js +2 -9
- package/lib/module/web/index.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 +16 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -1
- package/lib/typescript/src/renderer/processors/Transform.d.ts +2 -2
- package/lib/typescript/src/skia/core/Data.d.ts +3 -3
- package/lib/typescript/src/skia/types/Font/Font.d.ts +6 -0
- package/lib/typescript/src/skia/types/Matrix.d.ts +5 -1
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +1 -0
- package/lib/typescript/src/values/api.d.ts +0 -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/lib/typescript/src/views/SkiaView.web.d.ts +2 -2
- package/lib/typescript/src/web/LoadSkiaWeb.d.ts +6 -0
- package/lib/typescript/src/web/WithSkiaWeb.d.ts +10 -0
- package/lib/typescript/src/web/index.d.ts +2 -5
- package/package.json +8 -3
- package/scripts/setup-canvaskit.js +74 -0
- 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 +110 -0
- package/src/renderer/components/Group.tsx +1 -1
- package/src/renderer/processors/Transform.ts +7 -10
- package/src/skia/core/Data.ts +67 -50
- package/src/skia/core/Typeface.ts +6 -1
- package/src/skia/types/Font/Font.ts +7 -0
- package/src/skia/types/Matrix.ts +18 -2
- package/src/skia/types/Skia.ts +1 -1
- package/src/skia/web/JsiSkFont.ts +6 -0
- package/src/skia/web/JsiSkMatrix.ts +4 -0
- package/src/skia/web/JsiSkia.ts +1 -1
- package/src/values/api.ts +0 -2
- package/src/values/api.web.ts +1 -1
- package/src/values/hooks/index.ts +1 -1
- package/src/values/hooks/useComputedValue.ts +23 -0
- 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 +27 -24
- package/src/web/LoadSkiaWeb.tsx +18 -0
- package/src/web/WithSkiaWeb.tsx +32 -0
- package/src/web/index.ts +2 -15
- 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/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
- package/src/values/hooks/useDerivedValue.ts +0 -18
@@ -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/skia/web/JsiSkia.ts
CHANGED
@@ -63,7 +63,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
63
63
|
new JsiSkPictureRecorder(CanvasKit, new CanvasKit.PictureRecorder()),
|
64
64
|
Picture: new JsiSkPictureFactory(CanvasKit),
|
65
65
|
Path: new JsiSkPathFactory(CanvasKit),
|
66
|
-
Matrix: (matrix?: number[]) =>
|
66
|
+
Matrix: (matrix?: readonly number[]) =>
|
67
67
|
new JsiSkMatrix(
|
68
68
|
CanvasKit,
|
69
69
|
matrix
|
package/src/values/api.ts
CHANGED
package/src/values/api.web.ts
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
import { useMemo } from "react";
|
2
|
+
|
3
|
+
import { ValueApi } from "../api";
|
4
|
+
import { isValue } from "../../renderer/processors/Animations";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Creates a new computed value - a value that will calculate its value depending
|
8
|
+
* on other values.
|
9
|
+
* @param cb Callback to calculate new value
|
10
|
+
* @param values Dependant values
|
11
|
+
* @returns A readonly value
|
12
|
+
*/
|
13
|
+
export const useComputedValue = <R>(cb: () => R, values: unknown[]) =>
|
14
|
+
useMemo(
|
15
|
+
() => ValueApi.createComputedValue<R>(cb, values.filter(isValue)),
|
16
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
17
|
+
values
|
18
|
+
);
|
19
|
+
|
20
|
+
export const useDerivedValue = <R>(cb: () => R, values: unknown[]) => {
|
21
|
+
console.warn("useDerivedValue is deprecated. Use useComputedValue instead.");
|
22
|
+
return useComputedValue(cb, values);
|
23
|
+
};
|
package/src/values/types.ts
CHANGED
@@ -46,10 +46,10 @@ export interface ISkiaValueApi {
|
|
46
46
|
*/
|
47
47
|
createValue: <T>(initialValue: T) => SkiaMutableValue<T>;
|
48
48
|
/**
|
49
|
-
* Creates a
|
49
|
+
* Creates a computed value. This is a calculated value that returns the result of
|
50
50
|
* a function that is called with the values of the dependencies.
|
51
51
|
*/
|
52
|
-
|
52
|
+
createComputedValue: <R>(
|
53
53
|
cb: () => R,
|
54
54
|
values: Array<SkiaValue<unknown>>
|
55
55
|
) => SkiaValue<R>;
|
@@ -2,7 +2,7 @@ import type { DependencyList } from "react";
|
|
2
2
|
|
3
3
|
import { RNSkReadonlyValue } from "./RNSkReadonlyValue";
|
4
4
|
|
5
|
-
export class
|
5
|
+
export class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {
|
6
6
|
constructor(callback: () => T, dependencies: DependencyList) {
|
7
7
|
// Initialize dependencies - we can't call this yet, since
|
8
8
|
// super if not called and it requires a start value to be set.
|
package/src/values/web/api.ts
CHANGED
@@ -9,18 +9,18 @@ import type {
|
|
9
9
|
|
10
10
|
import { RNSkAnimation } from "./RNSkAnimation";
|
11
11
|
import { RNSkClockValue } from "./RNSkClockValue";
|
12
|
-
import {
|
12
|
+
import { RNSkComputedValue } from "./RNSkComputedValue";
|
13
13
|
import { RNSkValue } from "./RNSkValue";
|
14
14
|
|
15
15
|
export const ValueApi: ISkiaValueApi = {
|
16
16
|
createValue: function <T>(initialValue: T): SkiaMutableValue<T> {
|
17
17
|
return new RNSkValue(initialValue);
|
18
18
|
},
|
19
|
-
|
19
|
+
createComputedValue: function <R>(
|
20
20
|
cb: () => R,
|
21
21
|
values: SkiaValue<unknown>[]
|
22
22
|
): SkiaValue<R> {
|
23
|
-
return new
|
23
|
+
return new RNSkComputedValue(cb, values);
|
24
24
|
},
|
25
25
|
createClockValue: function (): SkiaClockValue {
|
26
26
|
return new RNSkClockValue(requestAnimationFrame.bind(window));
|
@@ -36,29 +36,32 @@ 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.redraw();
|
56
|
+
}
|
57
|
+
}
|
55
58
|
}
|
56
|
-
|
59
|
+
);
|
57
60
|
}
|
58
61
|
|
59
62
|
componentDidMount() {
|
60
63
|
// Start render loop
|
61
|
-
this.
|
64
|
+
this.tick();
|
62
65
|
}
|
63
66
|
|
64
67
|
componentWillUnmount() {
|
@@ -80,7 +83,7 @@ export class SkiaView extends React.Component<
|
|
80
83
|
/**
|
81
84
|
* Sends a redraw request to the native SkiaView.
|
82
85
|
*/
|
83
|
-
private
|
86
|
+
private tick() {
|
84
87
|
if (this._mode === "continuous" || this._redrawRequests > 0) {
|
85
88
|
this._redrawRequests = 0;
|
86
89
|
if (
|
@@ -103,11 +106,11 @@ export class SkiaView extends React.Component<
|
|
103
106
|
}
|
104
107
|
// Always request a new redraw as long as we're not unmounted
|
105
108
|
if (!this._unmounted) {
|
106
|
-
requestAnimationFrame(this.
|
109
|
+
requestAnimationFrame(this.tick.bind(this));
|
107
110
|
}
|
108
111
|
}
|
109
112
|
|
110
|
-
public
|
113
|
+
public redraw() {
|
111
114
|
this._redrawRequests++;
|
112
115
|
}
|
113
116
|
|
@@ -122,7 +125,7 @@ export class SkiaView extends React.Component<
|
|
122
125
|
*/
|
123
126
|
public setDrawMode(mode: DrawMode) {
|
124
127
|
this._mode = mode;
|
125
|
-
this.
|
128
|
+
this.tick();
|
126
129
|
}
|
127
130
|
|
128
131
|
/**
|
@@ -137,7 +140,7 @@ export class SkiaView extends React.Component<
|
|
137
140
|
_values.forEach((v) => {
|
138
141
|
this._unsubscriptions.push(
|
139
142
|
v.addListener(() => {
|
140
|
-
this.
|
143
|
+
this.redraw();
|
141
144
|
})
|
142
145
|
);
|
143
146
|
});
|
@@ -152,7 +155,7 @@ export class SkiaView extends React.Component<
|
|
152
155
|
type: touchType,
|
153
156
|
timestamp: Date.now(),
|
154
157
|
});
|
155
|
-
this.
|
158
|
+
this.redraw();
|
156
159
|
}
|
157
160
|
|
158
161
|
handleTouchStart(evt: PointerEvent) {
|
@@ -0,0 +1,18 @@
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2
|
+
// @ts-expect-error
|
3
|
+
import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
|
4
|
+
import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
|
5
|
+
|
6
|
+
declare global {
|
7
|
+
var CanvasKit: CanvasKitType;
|
8
|
+
}
|
9
|
+
|
10
|
+
export const LoadSkiaWeb = async () => {
|
11
|
+
const CanvasKit = await CanvasKitInit();
|
12
|
+
// The CanvasKit API is stored on the global object and used
|
13
|
+
// to create the JsiSKApi in the Skia.web.ts file.
|
14
|
+
global.CanvasKit = CanvasKit;
|
15
|
+
};
|
16
|
+
|
17
|
+
// We keep this function for backward compatibility
|
18
|
+
export const LoadSkia = LoadSkiaWeb;
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type { ComponentProps, ComponentType } from "react";
|
2
|
+
import React, { useMemo, lazy, Suspense } from "react";
|
3
|
+
import { Platform } from "react-native";
|
4
|
+
|
5
|
+
import { LoadSkiaWeb } from "./LoadSkiaWeb";
|
6
|
+
|
7
|
+
interface WithSkiaProps {
|
8
|
+
fallback: ComponentProps<typeof Suspense>["fallback"];
|
9
|
+
getComponent: () => Promise<{ default: ComponentType }>;
|
10
|
+
}
|
11
|
+
|
12
|
+
export const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {
|
13
|
+
const Inner = useMemo(
|
14
|
+
() =>
|
15
|
+
lazy(async () => {
|
16
|
+
if (Platform.OS === "web") {
|
17
|
+
await LoadSkiaWeb();
|
18
|
+
} else {
|
19
|
+
console.warn(
|
20
|
+
"<WithSkiaWeb /> is only necessary on web. Consider not using on native."
|
21
|
+
);
|
22
|
+
}
|
23
|
+
return getComponent();
|
24
|
+
}),
|
25
|
+
[getComponent]
|
26
|
+
);
|
27
|
+
return (
|
28
|
+
<Suspense fallback={fallback}>
|
29
|
+
<Inner />
|
30
|
+
</Suspense>
|
31
|
+
);
|
32
|
+
};
|
package/src/web/index.ts
CHANGED
@@ -1,15 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
|
4
|
-
import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
|
5
|
-
|
6
|
-
declare global {
|
7
|
-
var CanvasKit: CanvasKitType;
|
8
|
-
}
|
9
|
-
|
10
|
-
export const LoadSkia = async () => {
|
11
|
-
const CanvasKit = await CanvasKitInit();
|
12
|
-
// The CanvasKit API is stored on the global object and used
|
13
|
-
// to create the JsiSKApi in the Skia.web.ts file.
|
14
|
-
global.CanvasKit = CanvasKit;
|
15
|
-
};
|
1
|
+
export * from "./LoadSkiaWeb";
|
2
|
+
export * from "./WithSkiaWeb";
|
@@ -1,25 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.useDerivedValue = void 0;
|
7
|
-
|
8
|
-
var _react = require("react");
|
9
|
-
|
10
|
-
var _api = require("../api");
|
11
|
-
|
12
|
-
var _processors = require("../../renderer/processors");
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Creates a new derived value - a value that will calculate its value depending
|
16
|
-
* on other values.
|
17
|
-
* @param cb Callback to calculate new value
|
18
|
-
* @param values Dependant values
|
19
|
-
* @returns A readonly value
|
20
|
-
*/
|
21
|
-
const useDerivedValue = (cb, values) => (0, _react.useMemo)(() => _api.ValueApi.createDerivedValue(cb, values.filter(_processors.isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
|
22
|
-
values);
|
23
|
-
|
24
|
-
exports.useDerivedValue = useDerivedValue;
|
25
|
-
//# sourceMappingURL=useDerivedValue.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["useDerivedValue.ts"],"names":["useDerivedValue","cb","values","ValueApi","createDerivedValue","filter","isValue"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,eAAe,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC7B,oBACE,MAAMC,cAASC,kBAAT,CAA+BH,EAA/B,EAAmCC,MAAM,CAACG,MAAP,CAAcC,mBAAd,CAAnC,CADR,EAEE;AACAJ,MAHF,CADK","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors\";\n\n/**\n * Creates a new derived value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["RNSkDerivedValue.ts"],"names":["RNSkDerivedValue","RNSkReadonlyValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;;;;;;AAEA;;;;AAEO,MAAMA,gBAAN,SAAkCC,oCAAlC,CAAuD;AAC5DC,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC2D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import { useMemo } from "react";
|
2
|
-
import { ValueApi } from "../api";
|
3
|
-
import { isValue } from "../../renderer/processors";
|
4
|
-
/**
|
5
|
-
* Creates a new derived value - a value that will calculate its value depending
|
6
|
-
* on other values.
|
7
|
-
* @param cb Callback to calculate new value
|
8
|
-
* @param values Dependant values
|
9
|
-
* @returns A readonly value
|
10
|
-
*/
|
11
|
-
|
12
|
-
export const useDerivedValue = (cb, values) => useMemo(() => ValueApi.createDerivedValue(cb, values.filter(isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
|
13
|
-
values);
|
14
|
-
//# sourceMappingURL=useDerivedValue.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["useDerivedValue.ts"],"names":["useMemo","ValueApi","isValue","useDerivedValue","cb","values","createDerivedValue","filter"],"mappings":"AAAA,SAASA,OAAT,QAAwB,OAAxB;AAEA,SAASC,QAAT,QAAyB,QAAzB;AACA,SAASC,OAAT,QAAwB,2BAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,eAAe,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC7BL,OAAO,CACL,MAAMC,QAAQ,CAACK,kBAAT,CAA+BF,EAA/B,EAAmCC,MAAM,CAACE,MAAP,CAAcL,OAAd,CAAnC,CADD,EAEL;AACAG,MAHK,CADF","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors\";\n\n/**\n * Creates a new derived value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["RNSkDerivedValue.ts"],"names":["RNSkReadonlyValue","RNSkDerivedValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;AAEA,SAASA,iBAAT,QAAkC,qBAAlC;AAEA,OAAO,MAAMC,gBAAN,SAAkCD,iBAAlC,CAAuD;AAC5DE,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC2D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkDerivedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import { useMemo } from "react";
|
2
|
-
|
3
|
-
import { ValueApi } from "../api";
|
4
|
-
import { isValue } from "../../renderer/processors";
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Creates a new derived value - a value that will calculate its value depending
|
8
|
-
* on other values.
|
9
|
-
* @param cb Callback to calculate new value
|
10
|
-
* @param values Dependant values
|
11
|
-
* @returns A readonly value
|
12
|
-
*/
|
13
|
-
export const useDerivedValue = <R>(cb: () => R, values: unknown[]) =>
|
14
|
-
useMemo(
|
15
|
-
() => ValueApi.createDerivedValue<R>(cb, values.filter(isValue)),
|
16
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
17
|
-
values
|
18
|
-
);
|