@shopify/react-native-skia 0.1.214 → 0.1.215
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/api/JsiSkMatrix.h +31 -0
- package/cpp/api/JsiSkPath.h +15 -7
- package/lib/commonjs/animation/functions/interpolatePaths.d.ts +1 -1
- package/lib/commonjs/animation/functions/interpolatePaths.js +4 -4
- package/lib/commonjs/animation/functions/interpolatePaths.js.map +1 -1
- package/lib/commonjs/external/reanimated/index.d.ts +2 -1
- package/lib/commonjs/external/reanimated/index.js +17 -4
- package/lib/commonjs/external/reanimated/index.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.d.ts +9 -0
- package/lib/commonjs/external/reanimated/interpolators.js +56 -0
- package/lib/commonjs/external/reanimated/interpolators.js.map +1 -0
- package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +8 -6
- package/lib/commonjs/external/reanimated/moduleWrapper.js +6 -11
- package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +2 -0
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +53 -0
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -0
- package/lib/commonjs/external/reanimated/useDerivedValueOnJS.d.ts +1 -2
- package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js +2 -1
- package/lib/commonjs/external/reanimated/useDerivedValueOnJS.js.map +1 -1
- package/lib/commonjs/mock/index.js +8 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/HostConfig.js +5 -5
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.d.ts +0 -1
- package/lib/commonjs/skia/core/AnimatedImage.js +1 -45
- package/lib/commonjs/skia/core/AnimatedImage.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.d.ts +4 -0
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Path/Path.d.ts +10 -9
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +6 -0
- package/lib/commonjs/skia/web/JsiSkMatrix.js +33 -5
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.d.ts +9 -9
- package/lib/commonjs/skia/web/JsiSkPath.js +15 -2
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/animation/functions/interpolatePaths.d.ts +1 -1
- package/lib/module/animation/functions/interpolatePaths.js +4 -4
- package/lib/module/animation/functions/interpolatePaths.js.map +1 -1
- package/lib/module/external/reanimated/index.d.ts +2 -1
- package/lib/module/external/reanimated/index.js +2 -1
- package/lib/module/external/reanimated/index.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.d.ts +9 -0
- package/lib/module/external/reanimated/interpolators.js +34 -0
- package/lib/module/external/reanimated/interpolators.js.map +1 -0
- package/lib/module/external/reanimated/moduleWrapper.d.ts +8 -6
- package/lib/module/external/reanimated/moduleWrapper.js +4 -7
- package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +2 -0
- package/lib/module/external/reanimated/useAnimatedImageValue.js +41 -0
- package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -0
- package/lib/module/external/reanimated/useDerivedValueOnJS.d.ts +1 -2
- package/lib/module/external/reanimated/useDerivedValueOnJS.js +3 -2
- package/lib/module/external/reanimated/useDerivedValueOnJS.js.map +1 -1
- package/lib/module/mock/index.js +8 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +1 -1
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/skia/core/AnimatedImage.d.ts +0 -1
- package/lib/module/skia/core/AnimatedImage.js +0 -40
- package/lib/module/skia/core/AnimatedImage.js.map +1 -1
- package/lib/module/skia/types/Matrix.d.ts +4 -0
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/Path/Path.d.ts +10 -9
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.d.ts +6 -0
- package/lib/module/skia/web/JsiSkMatrix.js +33 -5
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.d.ts +9 -9
- package/lib/module/skia/web/JsiSkPath.js +15 -2
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/typescript/jestEnv.d.mts +5 -0
- package/lib/typescript/jestSetup.d.mts +1 -0
- package/lib/typescript/src/animation/functions/interpolatePaths.d.ts +1 -1
- package/lib/typescript/src/external/reanimated/index.d.ts +2 -1
- package/lib/typescript/src/external/reanimated/interpolators.d.ts +9 -0
- package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +8 -6
- package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +2 -0
- package/lib/typescript/src/external/reanimated/useDerivedValueOnJS.d.ts +1 -2
- package/lib/typescript/src/skia/core/AnimatedImage.d.ts +0 -1
- package/lib/typescript/src/skia/types/Matrix.d.ts +4 -0
- package/lib/typescript/src/skia/types/Path/Path.d.ts +10 -9
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +6 -0
- package/lib/typescript/src/skia/web/JsiSkPath.d.ts +9 -9
- package/package.json +4 -3
- package/src/animation/functions/interpolatePaths.ts +7 -4
- package/src/external/reanimated/index.ts +2 -1
- package/src/external/reanimated/interpolators.ts +89 -0
- package/src/external/reanimated/moduleWrapper.ts +33 -16
- package/src/external/reanimated/renderHelpers.ts +2 -2
- package/src/external/reanimated/useAnimatedImageValue.ts +51 -0
- package/src/external/reanimated/useDerivedValueOnJS.ts +4 -3
- package/src/mock/index.ts +5 -0
- package/src/renderer/HostConfig.ts +1 -1
- package/src/skia/core/AnimatedImage.ts +0 -47
- package/src/skia/types/Matrix.ts +4 -0
- package/src/skia/types/Path/Path.ts +10 -9
- package/src/skia/web/JsiSkMatrix.ts +33 -27
- package/src/skia/web/JsiSkPath.ts +15 -2
- package/globalJestSetup.js +0 -6
- package/lib/commonjs/external/reanimated/useSharedValueEffect.d.ts +0 -8
- package/lib/commonjs/external/reanimated/useSharedValueEffect.js +0 -49
- package/lib/commonjs/external/reanimated/useSharedValueEffect.js.map +0 -1
- package/lib/module/external/reanimated/useSharedValueEffect.d.ts +0 -8
- package/lib/module/external/reanimated/useSharedValueEffect.js +0 -39
- package/lib/module/external/reanimated/useSharedValueEffect.js.map +0 -1
- package/lib/typescript/globalJestSetup.d.ts +0 -2
- package/lib/typescript/src/external/reanimated/useSharedValueEffect.d.ts +0 -8
- package/src/external/reanimated/useSharedValueEffect.ts +0 -55
package/cpp/api/JsiSkMatrix.h
CHANGED
|
@@ -53,6 +53,13 @@ public:
|
|
|
53
53
|
return thisValue.asObject(runtime);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
JSI_HOST_FUNCTION(postTranslate) {
|
|
57
|
+
auto x = arguments[0].asNumber();
|
|
58
|
+
auto y = arguments[1].asNumber();
|
|
59
|
+
getObject()->postTranslate(x, y);
|
|
60
|
+
return thisValue.asObject(runtime);
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
JSI_HOST_FUNCTION(scale) {
|
|
57
64
|
auto x = arguments[0].asNumber();
|
|
58
65
|
auto y = count > 1 ? arguments[1].asNumber() : 1;
|
|
@@ -60,6 +67,13 @@ public:
|
|
|
60
67
|
return thisValue.asObject(runtime);
|
|
61
68
|
}
|
|
62
69
|
|
|
70
|
+
JSI_HOST_FUNCTION(postScale) {
|
|
71
|
+
auto x = arguments[0].asNumber();
|
|
72
|
+
auto y = count > 1 ? arguments[1].asNumber() : 1;
|
|
73
|
+
getObject()->postScale(x, y);
|
|
74
|
+
return thisValue.asObject(runtime);
|
|
75
|
+
}
|
|
76
|
+
|
|
63
77
|
JSI_HOST_FUNCTION(skew) {
|
|
64
78
|
auto x = arguments[0].asNumber();
|
|
65
79
|
auto y = arguments[1].asNumber();
|
|
@@ -67,12 +81,25 @@ public:
|
|
|
67
81
|
return thisValue.asObject(runtime);
|
|
68
82
|
}
|
|
69
83
|
|
|
84
|
+
JSI_HOST_FUNCTION(postSkew) {
|
|
85
|
+
auto x = arguments[0].asNumber();
|
|
86
|
+
auto y = arguments[1].asNumber();
|
|
87
|
+
getObject()->postSkew(x, y);
|
|
88
|
+
return thisValue.asObject(runtime);
|
|
89
|
+
}
|
|
90
|
+
|
|
70
91
|
JSI_HOST_FUNCTION(rotate) {
|
|
71
92
|
auto a = arguments[0].asNumber();
|
|
72
93
|
getObject()->preRotate(SkRadiansToDegrees(a));
|
|
73
94
|
return thisValue.asObject(runtime);
|
|
74
95
|
}
|
|
75
96
|
|
|
97
|
+
JSI_HOST_FUNCTION(postRotate) {
|
|
98
|
+
auto a = arguments[0].asNumber();
|
|
99
|
+
getObject()->postRotate(SkRadiansToDegrees(a));
|
|
100
|
+
return thisValue.asObject(runtime);
|
|
101
|
+
}
|
|
102
|
+
|
|
76
103
|
JSI_HOST_FUNCTION(identity) {
|
|
77
104
|
getObject()->setIdentity();
|
|
78
105
|
return thisValue.asObject(runtime);
|
|
@@ -90,9 +117,13 @@ public:
|
|
|
90
117
|
|
|
91
118
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkMatrix, concat),
|
|
92
119
|
JSI_EXPORT_FUNC(JsiSkMatrix, translate),
|
|
120
|
+
JSI_EXPORT_FUNC(JsiSkMatrix, postTranslate),
|
|
93
121
|
JSI_EXPORT_FUNC(JsiSkMatrix, scale),
|
|
122
|
+
JSI_EXPORT_FUNC(JsiSkMatrix, postScale),
|
|
94
123
|
JSI_EXPORT_FUNC(JsiSkMatrix, skew),
|
|
124
|
+
JSI_EXPORT_FUNC(JsiSkMatrix, postSkew),
|
|
95
125
|
JSI_EXPORT_FUNC(JsiSkMatrix, rotate),
|
|
126
|
+
JSI_EXPORT_FUNC(JsiSkMatrix, postRotate),
|
|
96
127
|
JSI_EXPORT_FUNC(JsiSkMatrix, identity),
|
|
97
128
|
JSI_EXPORT_FUNC(JsiSkMatrix, get),
|
|
98
129
|
JSI_EXPORT_FUNC(JsiSkMatrix, dispose))
|
package/cpp/api/JsiSkPath.h
CHANGED
|
@@ -108,7 +108,7 @@ public:
|
|
|
108
108
|
direction = SkPathDirection::kCCW;
|
|
109
109
|
}
|
|
110
110
|
getObject()->addRect(*rect, direction);
|
|
111
|
-
return
|
|
111
|
+
return thisValue.getObject(runtime);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
JSI_HOST_FUNCTION(addRRect) {
|
|
@@ -246,14 +246,14 @@ public:
|
|
|
246
246
|
JSI_HOST_FUNCTION(setFillType) {
|
|
247
247
|
auto ft = (SkPathFillType)arguments[0].asNumber();
|
|
248
248
|
getObject()->setFillType(ft);
|
|
249
|
-
return
|
|
249
|
+
return thisValue.getObject(runtime);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// TODO-API: Property?
|
|
253
253
|
JSI_HOST_FUNCTION(setIsVolatile) {
|
|
254
254
|
auto v = arguments[0].getBool();
|
|
255
255
|
getObject()->setIsVolatile(v);
|
|
256
|
-
return
|
|
256
|
+
return thisValue.getObject(runtime);
|
|
257
257
|
}
|
|
258
258
|
|
|
259
259
|
JSI_HOST_FUNCTION(isVolatile) {
|
|
@@ -263,7 +263,7 @@ public:
|
|
|
263
263
|
JSI_HOST_FUNCTION(transform) {
|
|
264
264
|
auto m3 = *JsiSkMatrix::fromValue(runtime, arguments[0]);
|
|
265
265
|
getObject()->transform(m3);
|
|
266
|
-
return
|
|
266
|
+
return thisValue.getObject(runtime);
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
JSI_HOST_FUNCTION(stroke) {
|
|
@@ -407,12 +407,12 @@ public:
|
|
|
407
407
|
|
|
408
408
|
JSI_HOST_FUNCTION(reset) {
|
|
409
409
|
getObject()->reset();
|
|
410
|
-
return
|
|
410
|
+
return thisValue.getObject(runtime);
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
JSI_HOST_FUNCTION(rewind) {
|
|
414
414
|
getObject()->rewind();
|
|
415
|
-
return
|
|
415
|
+
return thisValue.getObject(runtime);
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
JSI_HOST_FUNCTION(quadTo) {
|
|
@@ -452,7 +452,7 @@ public:
|
|
|
452
452
|
|
|
453
453
|
JSI_HOST_FUNCTION(close) {
|
|
454
454
|
getObject()->close();
|
|
455
|
-
return
|
|
455
|
+
return thisValue.getObject(runtime);
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
JSI_HOST_FUNCTION(simplify) {
|
|
@@ -494,6 +494,14 @@ public:
|
|
|
494
494
|
JSI_HOST_FUNCTION(interpolate) {
|
|
495
495
|
auto path2 = JsiSkPath::fromValue(runtime, arguments[0]);
|
|
496
496
|
auto weight = arguments[1].asNumber();
|
|
497
|
+
if (count > 2) {
|
|
498
|
+
auto path3 = JsiSkPath::fromValue(runtime, arguments[2]);
|
|
499
|
+
auto succeed = getObject()->interpolate(*path2, weight, path3.get());
|
|
500
|
+
if (!succeed) {
|
|
501
|
+
return nullptr;
|
|
502
|
+
}
|
|
503
|
+
return arguments[2].asObject(runtime);
|
|
504
|
+
}
|
|
497
505
|
SkPath result;
|
|
498
506
|
auto succeed = getObject()->interpolate(*path2, weight, &result);
|
|
499
507
|
if (!succeed) {
|
|
@@ -16,4 +16,4 @@ import type { ExtrapolationType } from "./interpolate";
|
|
|
16
16
|
* path2.lineTo(0, 100);
|
|
17
17
|
* const path = interpolatePath(0.5, [0, 1], [path1, path2]);
|
|
18
18
|
*/
|
|
19
|
-
export declare const interpolatePaths: (value: number, input: number[], outputRange: SkPath[], options?: ExtrapolationType) => SkPath;
|
|
19
|
+
export declare const interpolatePaths: (value: number, input: number[], outputRange: SkPath[], options?: ExtrapolationType, output?: SkPath) => SkPath;
|
|
@@ -9,11 +9,11 @@ var _typeddash = require("../../renderer/typeddash");
|
|
|
9
9
|
|
|
10
10
|
var _interpolate = require("./interpolate");
|
|
11
11
|
|
|
12
|
-
const lerp = (value, from, to, p1, p2) => {
|
|
12
|
+
const lerp = (value, from, to, p1, p2, output) => {
|
|
13
13
|
"worklet";
|
|
14
14
|
|
|
15
15
|
const t = (value - from) / (to - from);
|
|
16
|
-
return p2.interpolate(p1, t);
|
|
16
|
+
return p2.interpolate(p1, t, output);
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Maps an input value within a range to an output path within a path range.
|
|
@@ -33,7 +33,7 @@ const lerp = (value, from, to, p1, p2) => {
|
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
const interpolatePaths = (value, input, outputRange, options) => {
|
|
36
|
+
const interpolatePaths = (value, input, outputRange, options, output) => {
|
|
37
37
|
"worklet";
|
|
38
38
|
|
|
39
39
|
const extrapolation = (0, _interpolate.validateInterpolationOptions)(options);
|
|
@@ -76,7 +76,7 @@ const interpolatePaths = (value, input, outputRange, options) => {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
return lerp(value, input[i], input[i + 1], outputRange[i], outputRange[i + 1]);
|
|
79
|
+
return lerp(value, input[i], input[i + 1], outputRange[i], outputRange[i + 1], output);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
exports.interpolatePaths = interpolatePaths;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["lerp","value","from","to","p1","p2","t","interpolate","interpolatePaths","input","outputRange","options","extrapolation","validateInterpolationOptions","extrapolateLeft","Extrapolate","CLAMP","EXTEND","IDENTITY","Error","exhaustiveCheck","length","extrapolateRight","i"],"sources":["interpolatePaths.ts"],"sourcesContent":["import type { SkPath } from \"../../skia/types\";\nimport { exhaustiveCheck } from \"../../renderer/typeddash\";\n\nimport type { ExtrapolationType } from \"./interpolate\";\nimport { validateInterpolationOptions, Extrapolate } from \"./interpolate\";\n\nconst lerp = (\n value: number,\n from: number,\n to: number,\n p1: SkPath,\n p2: SkPath\n) => {\n \"worklet\";\n const t = (value - from) / (to - from);\n return p2.interpolate(p1, t)!;\n};\n\n/**\n * Maps an input value within a range to an output path within a path range.\n * @param value - The input value.\n * @param inputRange - The range of the input value.\n * @param outputRange - The range of the output path.\n * @param options - Extrapolation options\n * @returns The output path.\n * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>\n * const path1 = new Path();\n * path1.moveTo(0, 0);\n * path1.lineTo(100, 0);\n * const path2 = new Path();\n * path2.moveTo(0, 0);\n * path2.lineTo(0, 100);\n * const path = interpolatePath(0.5, [0, 1], [path1, path2]);\n */\nexport const interpolatePaths = (\n value: number,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType\n) => {\n \"worklet\";\n const extrapolation = validateInterpolationOptions(options);\n if (value < input[0]) {\n switch (extrapolation.extrapolateLeft) {\n case Extrapolate.CLAMP:\n return outputRange[0];\n case Extrapolate.EXTEND:\n return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateLeft);\n }\n } else if (value > input[input.length - 1]) {\n switch (extrapolation.extrapolateRight) {\n case Extrapolate.CLAMP:\n return outputRange[outputRange.length - 1];\n case Extrapolate.EXTEND:\n return lerp(\n value,\n input[input.length - 2],\n input[input.length - 1],\n outputRange[input.length - 2],\n outputRange[input.length - 1]\n );\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateRight);\n }\n }\n let i = 0;\n for (; i <= input.length - 1; i++) {\n if (value >= input[i] && value <= input[i + 1]) {\n break;\n }\n }\n return lerp(\n value,\n input[i],\n input[i + 1],\n outputRange[i],\n outputRange[i + 1]\n );\n};\n"],"mappings":";;;;;;;AACA;;AAGA;;AAEA,MAAMA,IAAI,GAAG,CACXC,KADW,EAEXC,IAFW,EAGXC,EAHW,EAIXC,EAJW,EAKXC,EALW,
|
|
1
|
+
{"version":3,"names":["lerp","value","from","to","p1","p2","output","t","interpolate","interpolatePaths","input","outputRange","options","extrapolation","validateInterpolationOptions","extrapolateLeft","Extrapolate","CLAMP","EXTEND","IDENTITY","Error","exhaustiveCheck","length","extrapolateRight","i"],"sources":["interpolatePaths.ts"],"sourcesContent":["import type { SkPath } from \"../../skia/types\";\nimport { exhaustiveCheck } from \"../../renderer/typeddash\";\n\nimport type { ExtrapolationType } from \"./interpolate\";\nimport { validateInterpolationOptions, Extrapolate } from \"./interpolate\";\n\nconst lerp = (\n value: number,\n from: number,\n to: number,\n p1: SkPath,\n p2: SkPath,\n output?: SkPath\n) => {\n \"worklet\";\n const t = (value - from) / (to - from);\n return p2.interpolate(p1, t, output)!;\n};\n\n/**\n * Maps an input value within a range to an output path within a path range.\n * @param value - The input value.\n * @param inputRange - The range of the input value.\n * @param outputRange - The range of the output path.\n * @param options - Extrapolation options\n * @returns The output path.\n * @example <caption>Map a value between 0 and 1 to a path between two paths.</caption>\n * const path1 = new Path();\n * path1.moveTo(0, 0);\n * path1.lineTo(100, 0);\n * const path2 = new Path();\n * path2.moveTo(0, 0);\n * path2.lineTo(0, 100);\n * const path = interpolatePath(0.5, [0, 1], [path1, path2]);\n */\nexport const interpolatePaths = (\n value: number,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType,\n output?: SkPath\n) => {\n \"worklet\";\n const extrapolation = validateInterpolationOptions(options);\n if (value < input[0]) {\n switch (extrapolation.extrapolateLeft) {\n case Extrapolate.CLAMP:\n return outputRange[0];\n case Extrapolate.EXTEND:\n return lerp(value, input[0], input[1], outputRange[0], outputRange[1]);\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateLeft);\n }\n } else if (value > input[input.length - 1]) {\n switch (extrapolation.extrapolateRight) {\n case Extrapolate.CLAMP:\n return outputRange[outputRange.length - 1];\n case Extrapolate.EXTEND:\n return lerp(\n value,\n input[input.length - 2],\n input[input.length - 1],\n outputRange[input.length - 2],\n outputRange[input.length - 1]\n );\n case Extrapolate.IDENTITY:\n throw new Error(\n \"Identity is not a supported extrapolation type for interpolatePaths()\"\n );\n default:\n exhaustiveCheck(extrapolation.extrapolateRight);\n }\n }\n let i = 0;\n for (; i <= input.length - 1; i++) {\n if (value >= input[i] && value <= input[i + 1]) {\n break;\n }\n }\n return lerp(\n value,\n input[i],\n input[i + 1],\n outputRange[i],\n outputRange[i + 1],\n output\n );\n};\n"],"mappings":";;;;;;;AACA;;AAGA;;AAEA,MAAMA,IAAI,GAAG,CACXC,KADW,EAEXC,IAFW,EAGXC,EAHW,EAIXC,EAJW,EAKXC,EALW,EAMXC,MANW,KAOR;EACH;;EACA,MAAMC,CAAC,GAAG,CAACN,KAAK,GAAGC,IAAT,KAAkBC,EAAE,GAAGD,IAAvB,CAAV;EACA,OAAOG,EAAE,CAACG,WAAH,CAAeJ,EAAf,EAAmBG,CAAnB,EAAsBD,MAAtB,CAAP;AACD,CAXD;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMG,gBAAgB,GAAG,CAC9BR,KAD8B,EAE9BS,KAF8B,EAG9BC,WAH8B,EAI9BC,OAJ8B,EAK9BN,MAL8B,KAM3B;EACH;;EACA,MAAMO,aAAa,GAAG,IAAAC,yCAAA,EAA6BF,OAA7B,CAAtB;;EACA,IAAIX,KAAK,GAAGS,KAAK,CAAC,CAAD,CAAjB,EAAsB;IACpB,QAAQG,aAAa,CAACE,eAAtB;MACE,KAAKC,wBAAA,CAAYC,KAAjB;QACE,OAAON,WAAW,CAAC,CAAD,CAAlB;;MACF,KAAKK,wBAAA,CAAYE,MAAjB;QACE,OAAOlB,IAAI,CAACC,KAAD,EAAQS,KAAK,CAAC,CAAD,CAAb,EAAkBA,KAAK,CAAC,CAAD,CAAvB,EAA4BC,WAAW,CAAC,CAAD,CAAvC,EAA4CA,WAAW,CAAC,CAAD,CAAvD,CAAX;;MACF,KAAKK,wBAAA,CAAYG,QAAjB;QACE,MAAM,IAAIC,KAAJ,CACJ,uEADI,CAAN;;MAGF;QACE,IAAAC,0BAAA,EAAgBR,aAAa,CAACE,eAA9B;IAVJ;EAYD,CAbD,MAaO,IAAId,KAAK,GAAGS,KAAK,CAACA,KAAK,CAACY,MAAN,GAAe,CAAhB,CAAjB,EAAqC;IAC1C,QAAQT,aAAa,CAACU,gBAAtB;MACE,KAAKP,wBAAA,CAAYC,KAAjB;QACE,OAAON,WAAW,CAACA,WAAW,CAACW,MAAZ,GAAqB,CAAtB,CAAlB;;MACF,KAAKN,wBAAA,CAAYE,MAAjB;QACE,OAAOlB,IAAI,CACTC,KADS,EAETS,KAAK,CAACA,KAAK,CAACY,MAAN,GAAe,CAAhB,CAFI,EAGTZ,KAAK,CAACA,KAAK,CAACY,MAAN,GAAe,CAAhB,CAHI,EAITX,WAAW,CAACD,KAAK,CAACY,MAAN,GAAe,CAAhB,CAJF,EAKTX,WAAW,CAACD,KAAK,CAACY,MAAN,GAAe,CAAhB,CALF,CAAX;;MAOF,KAAKN,wBAAA,CAAYG,QAAjB;QACE,MAAM,IAAIC,KAAJ,CACJ,uEADI,CAAN;;MAGF;QACE,IAAAC,0BAAA,EAAgBR,aAAa,CAACU,gBAA9B;IAhBJ;EAkBD;;EACD,IAAIC,CAAC,GAAG,CAAR;;EACA,OAAOA,CAAC,IAAId,KAAK,CAACY,MAAN,GAAe,CAA3B,EAA8BE,CAAC,EAA/B,EAAmC;IACjC,IAAIvB,KAAK,IAAIS,KAAK,CAACc,CAAD,CAAd,IAAqBvB,KAAK,IAAIS,KAAK,CAACc,CAAC,GAAG,CAAL,CAAvC,EAAgD;MAC9C;IACD;EACF;;EACD,OAAOxB,IAAI,CACTC,KADS,EAETS,KAAK,CAACc,CAAD,CAFI,EAGTd,KAAK,CAACc,CAAC,GAAG,CAAL,CAHI,EAITb,WAAW,CAACa,CAAD,CAJF,EAKTb,WAAW,CAACa,CAAC,GAAG,CAAL,CALF,EAMTlB,MANS,CAAX;AAQD,CAxDM"}
|
|
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _useAnimatedImageValue = require("./useAnimatedImageValue");
|
|
8
8
|
|
|
9
|
-
Object.keys(
|
|
9
|
+
Object.keys(_useAnimatedImageValue).forEach(function (key) {
|
|
10
10
|
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] ===
|
|
11
|
+
if (key in exports && exports[key] === _useAnimatedImageValue[key]) return;
|
|
12
12
|
Object.defineProperty(exports, key, {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _useAnimatedImageValue[key];
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
});
|
|
@@ -42,4 +42,17 @@ Object.keys(_renderHelpers).forEach(function (key) {
|
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
});
|
|
45
|
+
|
|
46
|
+
var _interpolators = require("./interpolators");
|
|
47
|
+
|
|
48
|
+
Object.keys(_interpolators).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _interpolators[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _interpolators[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
45
58
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./useAnimatedImageValue\";\nexport * from \"./useDerivedValueOnJS\";\nexport * from \"./renderHelpers\";\nexport * from \"./interpolators\";\n"],"mappings":";;;;;;AAAA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ExtrapolationType, SharedValue } from "react-native-reanimated";
|
|
2
|
+
import type { SkPath, SkPoint } from "../../skia/types";
|
|
3
|
+
export declare const notifyChange: (value: SharedValue<unknown>) => void;
|
|
4
|
+
export declare const useClock: () => SharedValue<number>;
|
|
5
|
+
export declare const usePathInterpolation: (value: SharedValue<number>, input: number[], outputRange: SkPath[], options?: ExtrapolationType) => SharedValue<SkPath>;
|
|
6
|
+
export declare const useVectorInterpolation: (value: SharedValue<number>, input: number[], outputRange: SkPoint[], options?: ExtrapolationType) => SharedValue<{
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useVectorInterpolation = exports.usePathInterpolation = exports.useClock = exports.notifyChange = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _animation = require("../../animation");
|
|
11
|
+
|
|
12
|
+
var _skia = require("../../skia");
|
|
13
|
+
|
|
14
|
+
var _moduleWrapper = require("./moduleWrapper");
|
|
15
|
+
|
|
16
|
+
const notifyChange = value => {
|
|
17
|
+
"worklet"; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
|
|
19
|
+
value._value = value.value;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.notifyChange = notifyChange;
|
|
23
|
+
|
|
24
|
+
const useClock = () => {
|
|
25
|
+
const clock = (0, _moduleWrapper.useSharedValue)(0);
|
|
26
|
+
(0, _moduleWrapper.useFrameCallback)(info => {
|
|
27
|
+
clock.value = info.timeSinceFirstFrame;
|
|
28
|
+
});
|
|
29
|
+
return clock;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* @worklet
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
exports.useClock = useClock;
|
|
37
|
+
|
|
38
|
+
const useInterpolator = (factory, value, interpolator, input, output, options) => {
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
const init = (0, _react.useMemo)(() => factory(), []);
|
|
41
|
+
const result = (0, _moduleWrapper.useSharedValue)(init);
|
|
42
|
+
(0, _moduleWrapper.useAnimatedReaction)(() => value.value, val => {
|
|
43
|
+
result.value = interpolator(val, input, output, options, result.value);
|
|
44
|
+
notifyChange(result);
|
|
45
|
+
}, [input, output, options]);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const usePathInterpolation = (value, input, outputRange, options) => useInterpolator(() => _skia.Skia.Path.Make(), value, _animation.interpolatePaths, input, outputRange, options);
|
|
50
|
+
|
|
51
|
+
exports.usePathInterpolation = usePathInterpolation;
|
|
52
|
+
|
|
53
|
+
const useVectorInterpolation = (value, input, outputRange, options) => useInterpolator(() => _skia.Skia.Point(0, 0), value, _animation.interpolateVector, input, outputRange, options);
|
|
54
|
+
|
|
55
|
+
exports.useVectorInterpolation = useVectorInterpolation;
|
|
56
|
+
//# sourceMappingURL=interpolators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["notifyChange","value","_value","useClock","clock","useSharedValue","useFrameCallback","info","timeSinceFirstFrame","useInterpolator","factory","interpolator","input","output","options","init","useMemo","result","useAnimatedReaction","val","usePathInterpolation","outputRange","Skia","Path","Make","interpolatePaths","useVectorInterpolation","Point","interpolateVector"],"sources":["interpolators.ts"],"sourcesContent":["import type { ExtrapolationType, SharedValue } from \"react-native-reanimated\";\nimport { useMemo } from \"react\";\n\nimport type { SkPath, SkPoint } from \"../../skia/types\";\nimport { interpolatePaths, interpolateVector } from \"../../animation\";\nimport { Skia } from \"../../skia\";\n\nimport {\n useAnimatedReaction,\n useFrameCallback,\n useSharedValue,\n} from \"./moduleWrapper\";\n\nexport const notifyChange = (value: SharedValue<unknown>) => {\n \"worklet\";\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (value as any)._value = value.value;\n};\n\nexport const useClock = () => {\n const clock = useSharedValue(0);\n useFrameCallback((info) => {\n clock.value = info.timeSinceFirstFrame;\n });\n return clock;\n};\n\n/**\n * @worklet\n */\ntype Interpolator<T> = (\n value: number,\n input: number[],\n output: T[],\n options: ExtrapolationType,\n result: T\n) => T;\n\nconst useInterpolator = <T>(\n factory: () => T,\n value: SharedValue<number>,\n interpolator: Interpolator<T>,\n input: number[],\n output: T[],\n options?: ExtrapolationType\n) => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const init = useMemo(() => factory(), []);\n const result = useSharedValue(init);\n useAnimatedReaction(\n () => value.value,\n (val) => {\n result.value = interpolator(val, input, output, options, result.value);\n notifyChange(result);\n },\n [input, output, options]\n );\n return result;\n};\n\nexport const usePathInterpolation = (\n value: SharedValue<number>,\n input: number[],\n outputRange: SkPath[],\n options?: ExtrapolationType\n) =>\n useInterpolator(\n () => Skia.Path.Make(),\n value,\n interpolatePaths,\n input,\n outputRange,\n options\n );\n\nexport const useVectorInterpolation = (\n value: SharedValue<number>,\n input: number[],\n outputRange: SkPoint[],\n options?: ExtrapolationType\n) =>\n useInterpolator(\n () => Skia.Point(0, 0),\n value,\n interpolateVector,\n input,\n outputRange,\n options\n );\n"],"mappings":";;;;;;;AACA;;AAGA;;AACA;;AAEA;;AAMO,MAAMA,YAAY,GAAIC,KAAD,IAAiC;EAC3D,UAD2D,CAE3D;;EACCA,KAAD,CAAeC,MAAf,GAAwBD,KAAK,CAACA,KAA9B;AACD,CAJM;;;;AAMA,MAAME,QAAQ,GAAG,MAAM;EAC5B,MAAMC,KAAK,GAAG,IAAAC,6BAAA,EAAe,CAAf,CAAd;EACA,IAAAC,+BAAA,EAAkBC,IAAD,IAAU;IACzBH,KAAK,CAACH,KAAN,GAAcM,IAAI,CAACC,mBAAnB;EACD,CAFD;EAGA,OAAOJ,KAAP;AACD,CANM;AAQP;AACA;AACA;;;;;AASA,MAAMK,eAAe,GAAG,CACtBC,OADsB,EAEtBT,KAFsB,EAGtBU,YAHsB,EAItBC,KAJsB,EAKtBC,MALsB,EAMtBC,OANsB,KAOnB;EACH;EACA,MAAMC,IAAI,GAAG,IAAAC,cAAA,EAAQ,MAAMN,OAAO,EAArB,EAAyB,EAAzB,CAAb;EACA,MAAMO,MAAM,GAAG,IAAAZ,6BAAA,EAAeU,IAAf,CAAf;EACA,IAAAG,kCAAA,EACE,MAAMjB,KAAK,CAACA,KADd,EAEGkB,GAAD,IAAS;IACPF,MAAM,CAAChB,KAAP,GAAeU,YAAY,CAACQ,GAAD,EAAMP,KAAN,EAAaC,MAAb,EAAqBC,OAArB,EAA8BG,MAAM,CAAChB,KAArC,CAA3B;IACAD,YAAY,CAACiB,MAAD,CAAZ;EACD,CALH,EAME,CAACL,KAAD,EAAQC,MAAR,EAAgBC,OAAhB,CANF;EAQA,OAAOG,MAAP;AACD,CApBD;;AAsBO,MAAMG,oBAAoB,GAAG,CAClCnB,KADkC,EAElCW,KAFkC,EAGlCS,WAHkC,EAIlCP,OAJkC,KAMlCL,eAAe,CACb,MAAMa,UAAA,CAAKC,IAAL,CAAUC,IAAV,EADO,EAEbvB,KAFa,EAGbwB,2BAHa,EAIbb,KAJa,EAKbS,WALa,EAMbP,OANa,CANV;;;;AAeA,MAAMY,sBAAsB,GAAG,CACpCzB,KADoC,EAEpCW,KAFoC,EAGpCS,WAHoC,EAIpCP,OAJoC,KAMpCL,eAAe,CACb,MAAMa,UAAA,CAAKK,KAAL,CAAW,CAAX,EAAc,CAAd,CADO,EAEb1B,KAFa,EAGb2B,4BAHa,EAIbhB,KAJa,EAKbS,WALa,EAMbP,OANa,CANV"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DependencyList } from "react";
|
|
2
|
+
import type { FrameCallback, FrameInfo, SharedValue } from "react-native-reanimated";
|
|
2
3
|
export declare const HAS_REANIMATED2: boolean;
|
|
3
4
|
export declare const HAS_REANIMATED3: boolean;
|
|
4
5
|
export declare function throwOnMissingReanimated(): void;
|
|
5
|
-
export declare const useSharedValue:
|
|
6
|
-
export declare const useFrameCallback: (
|
|
7
|
-
export declare const startMapper:
|
|
8
|
-
export declare const stopMapper:
|
|
6
|
+
export declare const useSharedValue: <T>(init: T, oneWayReadsOnly?: boolean) => SharedValue<T>;
|
|
7
|
+
export declare const useFrameCallback: (callback: (frameInfo: FrameInfo) => void, autostart?: boolean) => FrameCallback;
|
|
8
|
+
export declare const startMapper: (worklet: () => void, inputs?: unknown[], outputs?: unknown[]) => number;
|
|
9
|
+
export declare const stopMapper: (mapperID: number) => void;
|
|
9
10
|
export declare const runOnJS: any;
|
|
10
|
-
export declare const
|
|
11
|
+
export declare const useAnimatedReaction: <T>(prepare: () => T, react: (v: T) => void, dependencies?: DependencyList) => void;
|
|
12
|
+
export declare const isSharedValue: <T>(value: unknown) => value is SharedValue<T>;
|
|
@@ -5,14 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.stopMapper = exports.startMapper = exports.runOnJS = exports.isSharedValue = exports.HAS_REANIMATED3 = exports.HAS_REANIMATED2 = void 0;
|
|
7
7
|
exports.throwOnMissingReanimated = throwOnMissingReanimated;
|
|
8
|
-
exports.useSharedValue = exports.useFrameCallback = void 0;
|
|
8
|
+
exports.useSharedValue = exports.useFrameCallback = exports.useAnimatedReaction = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _Reanimated, _Reanimated2, _Reanimated3, _Reanimated4, _Reanimated5, _Reanimated6;
|
|
11
11
|
|
|
12
|
-
var _Reanimated, _Reanimated2, _Reanimated3, _Reanimated4, _Reanimated5;
|
|
13
12
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
-
|
|
15
|
-
|
|
16
13
|
// This one is needed for the deprecated useSharedValue function
|
|
17
14
|
// We can remove it once we remove the deprecation
|
|
18
15
|
let Reanimated2;
|
|
@@ -21,8 +18,7 @@ let reanimatedVersion;
|
|
|
21
18
|
|
|
22
19
|
try {
|
|
23
20
|
Reanimated2 = require("react-native-reanimated");
|
|
24
|
-
reanimatedVersion =
|
|
25
|
-
require("react-native-reanimated/package.json").version;
|
|
21
|
+
reanimatedVersion = require("react-native-reanimated/package.json").version;
|
|
26
22
|
|
|
27
23
|
if (reanimatedVersion && (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))) {
|
|
28
24
|
Reanimated3 = Reanimated2;
|
|
@@ -41,10 +37,7 @@ function throwOnMissingReanimated() {
|
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
const useSharedValue = ((_Reanimated = Reanimated2) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) ||
|
|
45
|
-
value
|
|
46
|
-
}), [value]));
|
|
47
|
-
|
|
40
|
+
const useSharedValue = ((_Reanimated = Reanimated2) === null || _Reanimated === void 0 ? void 0 : _Reanimated.useSharedValue) || throwOnMissingReanimated;
|
|
48
41
|
exports.useSharedValue = useSharedValue;
|
|
49
42
|
const useFrameCallback = ((_Reanimated2 = Reanimated2) === null || _Reanimated2 === void 0 ? void 0 : _Reanimated2.useFrameCallback) || throwOnMissingReanimated;
|
|
50
43
|
exports.useFrameCallback = useFrameCallback;
|
|
@@ -54,6 +47,8 @@ const stopMapper = ((_Reanimated4 = Reanimated2) === null || _Reanimated4 === vo
|
|
|
54
47
|
exports.stopMapper = stopMapper;
|
|
55
48
|
const runOnJS = ((_Reanimated5 = Reanimated2) === null || _Reanimated5 === void 0 ? void 0 : _Reanimated5.runOnJS) || throwOnMissingReanimated;
|
|
56
49
|
exports.runOnJS = runOnJS;
|
|
50
|
+
const useAnimatedReaction = ((_Reanimated6 = Reanimated2) === null || _Reanimated6 === void 0 ? void 0 : _Reanimated6.useAnimatedReaction) || throwOnMissingReanimated;
|
|
51
|
+
exports.useAnimatedReaction = useAnimatedReaction;
|
|
57
52
|
|
|
58
53
|
const isSharedValue = value => {
|
|
59
54
|
return !!value && (Reanimated3 ? Reanimated3.isSharedValue(value) : value.value !== undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Reanimated2","Reanimated3","reanimatedVersion","require","version","includes","e","HAS_REANIMATED2","HAS_REANIMATED3","throwOnMissingReanimated","Error","useSharedValue","
|
|
1
|
+
{"version":3,"names":["Reanimated2","Reanimated3","reanimatedVersion","require","version","includes","e","HAS_REANIMATED2","HAS_REANIMATED3","throwOnMissingReanimated","Error","useSharedValue","useFrameCallback","startMapper","stopMapper","runOnJS","useAnimatedReaction","isSharedValue","value","undefined"],"sources":["moduleWrapper.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport type { DependencyList } from \"react\";\nimport type {\n FrameCallback,\n FrameInfo,\n SharedValue,\n} from \"react-native-reanimated\";\n\n// This one is needed for the deprecated useSharedValue function\n// We can remove it once we remove the deprecation\n\nlet Reanimated2: any;\n\nlet Reanimated3: any;\nlet reanimatedVersion: string;\n\ntry {\n Reanimated2 = require(\"react-native-reanimated\");\n reanimatedVersion = require(\"react-native-reanimated/package.json\").version;\n if (\n reanimatedVersion &&\n (reanimatedVersion >= \"3.0.0\" || reanimatedVersion.includes(\"3.0.0-\"))\n ) {\n Reanimated3 = Reanimated2;\n }\n} catch (e) {}\n\nexport const HAS_REANIMATED2 = !!Reanimated2;\nexport const HAS_REANIMATED3 = !!Reanimated3;\n\nexport function throwOnMissingReanimated() {\n if (!HAS_REANIMATED2) {\n throw new Error(\n \"Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \\\n react-native-skia's integration layer API.\"\n );\n }\n}\n\nexport const useSharedValue: <T>(\n init: T,\n oneWayReadsOnly?: boolean\n) => SharedValue<T> = Reanimated2?.useSharedValue || throwOnMissingReanimated;\n\nexport const useFrameCallback: (\n callback: (frameInfo: FrameInfo) => void,\n autostart?: boolean\n) => FrameCallback = Reanimated2?.useFrameCallback || throwOnMissingReanimated;\n\nexport const startMapper: (\n worklet: () => void,\n inputs?: unknown[],\n outputs?: unknown[]\n) => number = Reanimated2?.startMapper || throwOnMissingReanimated;\n\nexport const stopMapper: (mapperID: number) => void =\n Reanimated2?.stopMapper || throwOnMissingReanimated;\n\nexport const runOnJS = Reanimated2?.runOnJS || throwOnMissingReanimated;\n\nexport const useAnimatedReaction: <T>(\n prepare: () => T,\n react: (v: T) => void,\n dependencies?: DependencyList\n) => void = Reanimated2?.useAnimatedReaction || throwOnMissingReanimated;\n\nexport const isSharedValue = <T>(value: unknown): value is SharedValue<T> => {\n return (\n !!value &&\n (Reanimated3\n ? Reanimated3.isSharedValue(value)\n : (value as any).value !== undefined)\n );\n};\n"],"mappings":";;;;;;;;;;;AAAA;AAQA;AACA;AAEA,IAAIA,WAAJ;AAEA,IAAIC,WAAJ;AACA,IAAIC,iBAAJ;;AAEA,IAAI;EACFF,WAAW,GAAGG,OAAO,CAAC,yBAAD,CAArB;EACAD,iBAAiB,GAAGC,OAAO,CAAC,sCAAD,CAAP,CAAgDC,OAApE;;EACA,IACEF,iBAAiB,KAChBA,iBAAiB,IAAI,OAArB,IAAgCA,iBAAiB,CAACG,QAAlB,CAA2B,QAA3B,CADhB,CADnB,EAGE;IACAJ,WAAW,GAAGD,WAAd;EACD;AACF,CATD,CASE,OAAOM,CAAP,EAAU,CAAE;;AAEP,MAAMC,eAAe,GAAG,CAAC,CAACP,WAA1B;;AACA,MAAMQ,eAAe,GAAG,CAAC,CAACP,WAA1B;;;AAEA,SAASQ,wBAAT,GAAoC;EACzC,IAAI,CAACF,eAAL,EAAsB;IACpB,MAAM,IAAIG,KAAJ,CACJ;AACN,iDAFU,CAAN;EAID;AACF;;AAEM,MAAMC,cAGM,GAAG,gBAAAX,WAAW,UAAX,kDAAaW,cAAb,KAA+BF,wBAH9C;;AAKA,MAAMG,gBAGK,GAAG,iBAAAZ,WAAW,UAAX,oDAAaY,gBAAb,KAAiCH,wBAH/C;;AAKA,MAAMI,WAIF,GAAG,iBAAAb,WAAW,UAAX,oDAAaa,WAAb,KAA4BJ,wBAJnC;;AAMA,MAAMK,UAAsC,GACjD,iBAAAd,WAAW,UAAX,oDAAac,UAAb,KAA2BL,wBADtB;;AAGA,MAAMM,OAAO,GAAG,iBAAAf,WAAW,UAAX,oDAAae,OAAb,KAAwBN,wBAAxC;;AAEA,MAAMO,mBAIJ,GAAG,iBAAAhB,WAAW,UAAX,oDAAagB,mBAAb,KAAoCP,wBAJzC;;;AAMA,MAAMQ,aAAa,GAAOC,KAAJ,IAAgD;EAC3E,OACE,CAAC,CAACA,KAAF,KACCjB,WAAW,GACRA,WAAW,CAACgB,aAAZ,CAA0BC,KAA1B,CADQ,GAEPA,KAAD,CAAeA,KAAf,KAAyBC,SAH7B,CADF;AAMD,CAPM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_bindings","WeakMap","extractReanimatedProps","props","HAS_REANIMATED3","HAS_REANIMATED2","reanimatedProps","otherProps","propName","propValue","isSharedValue","value","bindReanimatedProps2","container","node","sharedValues","Object","values","previousMapperId","get","undefined","stopMapper","length","viewId","getNativeId","SkiaViewApi","global","updateProps","setProp","requestRedraw","redraw","mapperId","startMapper","runOnJS","set","bindReanimatedProps"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable reanimated/js-function-in-worklet */\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport {\n startMapper,\n stopMapper,\n isSharedValue,\n HAS_REANIMATED3,\n HAS_REANIMATED2,\n runOnJS,\n} from \"./moduleWrapper\";\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED3 && !HAS_REANIMATED2) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nfunction bindReanimatedProps2(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const updateProps = () => {\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n };\n const mapperId = startMapper(() => {\n \"worklet\";\n runOnJS(updateProps)();\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (HAS_REANIMATED2) {\n return bindReanimatedProps2(container, node, reanimatedProps);\n }\n if (!HAS_REANIMATED3) {\n return;\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = startMapper(() => {\n \"worklet\";\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":";;;;;;;;AAMA;;AANA;;AACA;AAcA,MAAMA,SAAS,GAAG,IAAIC,OAAJ,EAAlB;;AAEO,SAASC,sBAAT,CAAgCC,KAAhC,EAA2D;EAChE,IAAI,CAACC,8BAAD,IAAoB,CAACC,8BAAzB,EAA0C;IACxC,OAAO,CAACF,KAAD,EAAQ,EAAR,CAAP;EACD;;EACD,MAAMG,eAAe,GAAG,EAAxB;EACA,MAAMC,UAAU,GAAG,EAAnB;;EACA,KAAK,MAAMC,QAAX,IAAuBL,KAAvB,EAA8B;IAC5B,IAAIK,QAAQ,KAAK,UAAjB,EAA6B;MAC3B;IACD;;IACD,MAAMC,SAAS,GAAGN,KAAK,CAACK,QAAD,CAAvB;;IACA,IAAI,IAAAE,4BAAA,EAAcD,SAAd,CAAJ,EAA8B;MAC5BH,eAAe,CAACE,QAAD,CAAf,GAA4BC,SAA5B;MACAF,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAS,CAACE,KAAjC;IACD,CAHD,MAGO;MACLJ,UAAU,CAACC,QAAD,CAAV,GAAuBC,SAAvB;IACD;EACF;;EACD,OAAO,CAACF,UAAD,EAAaD,eAAb,CAAP;AACD;;AAED,SAASM,oBAAT,CACEC,SADF,EAEEC,IAFF,EAGER,eAHF,EAIE;EACA,MAAMS,YAAY,GAAGC,MAAM,CAACC,MAAP,CAAcX,eAAd,CAArB;;EACA,MAAMY,gBAAgB,GAAGlB,SAAS,CAACmB,GAAV,CAAcL,IAAd,CAAzB;;EACA,IAAII,gBAAgB,KAAKE,SAAzB,EAAoC;IAClC,IAAAC,yBAAA,EAAWH,gBAAX;EACD;;EACD,IAAIH,YAAY,CAACO,MAAb,GAAsB,CAA1B,EAA6B;IAC3B,MAAMC,MAAM,GAAGV,SAAS,CAACW,WAAV,EAAf;IACA,MAAM;MAAEC;IAAF,IAAkBC,MAAxB;;IACA,MAAMC,WAAW,GAAG,MAAM;MACxB,KAAK,MAAMnB,QAAX,IAAuBF,eAAvB,EAAwC;QACtCQ,IAAI,IAAIA,IAAI,CAACc,OAAL,CAAapB,QAAb,EAAuBF,eAAe,CAACE,QAAD,CAAf,CAA0BG,KAAjD,CAAR;MACD,CAHuB,CAIxB;MACA;MACA;MACA;;;MACA,IAAIc,WAAJ,EAAiB;QACfA,WAAW,CAACI,aAAZ,CAA0BN,MAA1B;MACD,CAFD,MAEO;QACLV,SAAS,CAACiB,MAAV;MACD;IACF,CAbD;;IAcA,MAAMC,QAAQ,GAAG,IAAAC,0BAAA,EAAY,MAAM;MACjC;;MACA,IAAAC,sBAAA,EAAQN,WAAR;IACD,CAHgB,EAGdZ,YAHc,CAAjB;;IAIAf,SAAS,CAACkC,GAAV,CAAcpB,IAAd,EAAoBiB,QAApB;EACD;AACF;;AAEM,SAASI,mBAAT,CACLtB,SADK,EAELC,IAFK,EAGLR,eAHK,EAIL;EACA,IAAID,8BAAJ,EAAqB;IACnB,OAAOO,oBAAoB,CAACC,SAAD,EAAYC,IAAZ,EAAkBR,eAAlB,CAA3B;EACD;;EACD,IAAI,CAACF,8BAAL,EAAsB;IACpB;EACD;;EACD,MAAMW,YAAY,GAAGC,MAAM,CAACC,MAAP,CAAcX,eAAd,CAArB;;EACA,MAAMY,gBAAgB,GAAGlB,SAAS,CAACmB,GAAV,CAAcL,IAAd,CAAzB;;EACA,IAAII,gBAAgB,KAAKE,SAAzB,EAAoC;IAClC,IAAAC,yBAAA,EAAWH,gBAAX;EACD;;EACD,IAAIH,YAAY,CAACO,MAAb,GAAsB,CAA1B,EAA6B;IAC3B,MAAMC,MAAM,GAAGV,SAAS,CAACW,WAAV,EAAf;IACA,MAAM;MAAEC;IAAF,IAAkBC,MAAxB;IACA,MAAMK,QAAQ,GAAG,IAAAC,0BAAA,EAAY,MAAM;MACjC;;MACA,KAAK,MAAMxB,QAAX,IAAuBF,eAAvB,EAAwC;QACtCQ,IAAI,IAAIA,IAAI,CAACc,OAAL,CAAapB,QAAb,EAAuBF,eAAe,CAACE,QAAD,CAAf,CAA0BG,KAAjD,CAAR;MACD,CAJgC,CAKjC;MACA;MACA;MACA;;;MACA,IAAIc,WAAJ,EAAiB;QACfA,WAAW,CAACI,aAAZ,CAA0BN,MAA1B;MACD,CAFD,MAEO;QACLV,SAAS,CAACiB,MAAV;MACD;IACF,CAdgB,EAcdf,YAdc,CAAjB;;IAeAf,SAAS,CAACkC,GAAV,CAAcpB,IAAd,EAAoBiB,QAApB;EACD;AACF"}
|
|
1
|
+
{"version":3,"names":["_bindings","WeakMap","extractReanimatedProps","props","HAS_REANIMATED3","HAS_REANIMATED2","reanimatedProps","otherProps","propName","propValue","isSharedValue","value","bindReanimatedProps2","container","node","sharedValues","Object","values","previousMapperId","get","undefined","stopMapper","length","viewId","getNativeId","SkiaViewApi","global","updateProps","setProp","requestRedraw","redraw","mapperId","startMapper","runOnJS","set","bindReanimatedProps"],"sources":["renderHelpers.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n/* eslint-disable reanimated/js-function-in-worklet */\nimport type { Container } from \"../../renderer/Container\";\nimport type { AnimatedProps } from \"../../renderer/processors\";\nimport type { Node } from \"../../dom/types\";\n\nimport {\n startMapper,\n stopMapper,\n isSharedValue,\n HAS_REANIMATED3,\n HAS_REANIMATED2,\n runOnJS,\n} from \"./moduleWrapper\";\n\nconst _bindings = new WeakMap<Node<unknown>, unknown>();\n\nexport function extractReanimatedProps(props: AnimatedProps<any>) {\n if (!HAS_REANIMATED3 && !HAS_REANIMATED2) {\n return [props, {}];\n }\n const reanimatedProps = {} as AnimatedProps<any>;\n const otherProps = {} as AnimatedProps<any>;\n for (const propName in props) {\n if (propName === \"children\") {\n continue;\n }\n const propValue = props[propName];\n if (isSharedValue(propValue)) {\n reanimatedProps[propName] = propValue;\n otherProps[propName] = propValue.value;\n } else {\n otherProps[propName] = propValue;\n }\n }\n return [otherProps, reanimatedProps];\n}\n\nfunction bindReanimatedProps2(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const updateProps = () => {\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n };\n const mapperId = startMapper(() => {\n \"worklet\";\n runOnJS(updateProps)();\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n\nexport function bindReanimatedProps(\n container: Container,\n node: Node<any>,\n reanimatedProps: AnimatedProps<any>\n) {\n if (HAS_REANIMATED2) {\n return bindReanimatedProps2(container, node, reanimatedProps);\n }\n if (!HAS_REANIMATED3) {\n return;\n }\n const sharedValues = Object.values(reanimatedProps);\n const previousMapperId = _bindings.get(node);\n if (previousMapperId !== undefined) {\n stopMapper(previousMapperId as number);\n }\n if (sharedValues.length > 0) {\n const viewId = container.getNativeId();\n const { SkiaViewApi } = global;\n const mapperId = startMapper(() => {\n \"worklet\";\n for (const propName in reanimatedProps) {\n node && node.setProp(propName, reanimatedProps[propName].value);\n }\n // On React Native we use the SkiaViewApi to redraw because it can\n // run on the worklet thread (container.redraw can't)\n // if SkiaViewApi is undefined, we are on web and container.redraw()\n // can safely be invoked\n if (SkiaViewApi) {\n SkiaViewApi.requestRedraw(viewId);\n } else {\n container.redraw();\n }\n }, sharedValues);\n _bindings.set(node, mapperId);\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAnimatedImageValue = void 0;
|
|
7
|
+
|
|
8
|
+
var _AnimatedImage = require("../../skia/core/AnimatedImage");
|
|
9
|
+
|
|
10
|
+
var _moduleWrapper = require("./moduleWrapper");
|
|
11
|
+
|
|
12
|
+
const DEFAULT_FRAME_DURATION = 60;
|
|
13
|
+
|
|
14
|
+
const useAnimatedImageValue = source => {
|
|
15
|
+
(0, _moduleWrapper.throwOnMissingReanimated)();
|
|
16
|
+
const currentFrame = (0, _moduleWrapper.useSharedValue)(null);
|
|
17
|
+
const lastTimestamp = (0, _moduleWrapper.useSharedValue)(0);
|
|
18
|
+
const animatedImage = (0, _AnimatedImage.useAnimatedImage)(source, err => {
|
|
19
|
+
console.error(err);
|
|
20
|
+
throw new Error(`Could not load animated image - got '${err.message}'`);
|
|
21
|
+
});
|
|
22
|
+
const frameDuration = (animatedImage === null || animatedImage === void 0 ? void 0 : animatedImage.currentFrameDuration()) || DEFAULT_FRAME_DURATION;
|
|
23
|
+
(0, _moduleWrapper.useFrameCallback)(frameInfo => {
|
|
24
|
+
if (!animatedImage) {
|
|
25
|
+
currentFrame.value = null;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
timestamp
|
|
31
|
+
} = frameInfo;
|
|
32
|
+
const elapsed = timestamp - lastTimestamp.value; // Check if it's time to switch frames based on GIF frame duration
|
|
33
|
+
|
|
34
|
+
if (elapsed < frameDuration) {
|
|
35
|
+
return;
|
|
36
|
+
} // Update the current frame
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
animatedImage.decodeNextFrame();
|
|
40
|
+
|
|
41
|
+
if (currentFrame.value) {
|
|
42
|
+
currentFrame.value.dispose();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
currentFrame.value = animatedImage.getCurrentFrame(); // Update the last timestamp
|
|
46
|
+
|
|
47
|
+
lastTimestamp.value = timestamp; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
48
|
+
}, true);
|
|
49
|
+
return currentFrame;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.useAnimatedImageValue = useAnimatedImageValue;
|
|
53
|
+
//# sourceMappingURL=useAnimatedImageValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","throwOnMissingReanimated","currentFrame","useSharedValue","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import type { FrameInfo } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport {\n throwOnMissingReanimated,\n useFrameCallback,\n useSharedValue,\n} from \"./moduleWrapper\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (source: DataSourceParam) => {\n throwOnMissingReanimated();\n const currentFrame = useSharedValue<null | SkImage>(null);\n const lastTimestamp = useSharedValue(0);\n const animatedImage = useAnimatedImage(source, (err) => {\n console.error(err);\n throw new Error(`Could not load animated image - got '${err.message}'`);\n });\n const frameDuration =\n animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;\n\n useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n\n const { timestamp } = frameInfo;\n const elapsed = timestamp - lastTimestamp.value;\n\n // Check if it's time to switch frames based on GIF frame duration\n if (elapsed < frameDuration) {\n return;\n }\n\n // Update the current frame\n animatedImage.decodeNextFrame();\n if (currentFrame.value) {\n currentFrame.value.dispose();\n }\n currentFrame.value = animatedImage.getCurrentFrame();\n\n // Update the last timestamp\n lastTimestamp.value = timestamp;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, true);\n return currentFrame;\n};\n"],"mappings":";;;;;;;AAEA;;AAGA;;AAMA,MAAMA,sBAAsB,GAAG,EAA/B;;AAEO,MAAMC,qBAAqB,GAAIC,MAAD,IAA6B;EAChE,IAAAC,uCAAA;EACA,MAAMC,YAAY,GAAG,IAAAC,6BAAA,EAA+B,IAA/B,CAArB;EACA,MAAMC,aAAa,GAAG,IAAAD,6BAAA,EAAe,CAAf,CAAtB;EACA,MAAME,aAAa,GAAG,IAAAC,+BAAA,EAAiBN,MAAjB,EAA0BO,GAAD,IAAS;IACtDC,OAAO,CAACC,KAAR,CAAcF,GAAd;IACA,MAAM,IAAIG,KAAJ,CAAW,wCAAuCH,GAAG,CAACI,OAAQ,GAA9D,CAAN;EACD,CAHqB,CAAtB;EAIA,MAAMC,aAAa,GACjB,CAAAP,aAAa,SAAb,IAAAA,aAAa,WAAb,YAAAA,aAAa,CAAEQ,oBAAf,OAAyCf,sBAD3C;EAGA,IAAAgB,+BAAA,EAAkBC,SAAD,IAA0B;IACzC,IAAI,CAACV,aAAL,EAAoB;MAClBH,YAAY,CAACc,KAAb,GAAqB,IAArB;MACA;IACD;;IAED,MAAM;MAAEC;IAAF,IAAgBF,SAAtB;IACA,MAAMG,OAAO,GAAGD,SAAS,GAAGb,aAAa,CAACY,KAA1C,CAPyC,CASzC;;IACA,IAAIE,OAAO,GAAGN,aAAd,EAA6B;MAC3B;IACD,CAZwC,CAczC;;;IACAP,aAAa,CAACc,eAAd;;IACA,IAAIjB,YAAY,CAACc,KAAjB,EAAwB;MACtBd,YAAY,CAACc,KAAb,CAAmBI,OAAnB;IACD;;IACDlB,YAAY,CAACc,KAAb,GAAqBX,aAAa,CAACgB,eAAd,EAArB,CAnByC,CAqBzC;;IACAjB,aAAa,CAACY,KAAd,GAAsBC,SAAtB,CAtByC,CAuBzC;EACD,CAxBD,EAwBG,IAxBH;EAyBA,OAAOf,YAAP;AACD,CArCM"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const useDerivedValueOnJS: (fn: () => any, deps?: DependencyList) => any;
|
|
1
|
+
export declare const useDerivedValueOnJS: (fn: () => any, deps: unknown[]) => import("react-native-reanimated").SharedValue<any>;
|
|
@@ -10,7 +10,8 @@ var _react = require("react");
|
|
|
10
10
|
var _moduleWrapper = require("./moduleWrapper");
|
|
11
11
|
|
|
12
12
|
const useDerivedValueOnJS = (fn, deps) => {
|
|
13
|
-
const
|
|
13
|
+
const init = (0, _react.useMemo)(() => fn(), [fn]);
|
|
14
|
+
const value = (0, _moduleWrapper.useSharedValue)(init);
|
|
14
15
|
(0, _react.useEffect)(() => {
|
|
15
16
|
const mapperId = (0, _moduleWrapper.startMapper)(() => {
|
|
16
17
|
"worklet";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useDerivedValueOnJS","fn","deps","value","useSharedValue","useEffect","mapperId","startMapper","runOnJS","stopMapper"],"sources":["useDerivedValueOnJS.ts"],"sourcesContent":["import { useEffect,
|
|
1
|
+
{"version":3,"names":["useDerivedValueOnJS","fn","deps","init","useMemo","value","useSharedValue","useEffect","mapperId","startMapper","runOnJS","stopMapper"],"sources":["useDerivedValueOnJS.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\n\nimport {\n useSharedValue,\n runOnJS,\n startMapper,\n stopMapper,\n} from \"./moduleWrapper\";\n\nexport const useDerivedValueOnJS = (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fn: () => any,\n deps: unknown[]\n) => {\n const init = useMemo(() => fn(), [fn]);\n const value = useSharedValue(init);\n useEffect(() => {\n const mapperId = startMapper(() => {\n \"worklet\";\n runOnJS(fn)();\n }, deps);\n return () => stopMapper(mapperId);\n }, [deps, fn]);\n return value;\n};\n"],"mappings":";;;;;;;AAAA;;AAEA;;AAOO,MAAMA,mBAAmB,GAAG,CAEjCC,EAFiC,EAGjCC,IAHiC,KAI9B;EACH,MAAMC,IAAI,GAAG,IAAAC,cAAA,EAAQ,MAAMH,EAAE,EAAhB,EAAoB,CAACA,EAAD,CAApB,CAAb;EACA,MAAMI,KAAK,GAAG,IAAAC,6BAAA,EAAeH,IAAf,CAAd;EACA,IAAAI,gBAAA,EAAU,MAAM;IACd,MAAMC,QAAQ,GAAG,IAAAC,0BAAA,EAAY,MAAM;MACjC;;MACA,IAAAC,sBAAA,EAAQT,EAAR;IACD,CAHgB,EAGdC,IAHc,CAAjB;IAIA,OAAO,MAAM,IAAAS,yBAAA,EAAWH,QAAX,CAAb;EACD,CAND,EAMG,CAACN,IAAD,EAAOD,EAAP,CANH;EAOA,OAAOI,KAAP;AACD,CAfM"}
|
|
@@ -16,6 +16,10 @@ const NoopValue = () => ({
|
|
|
16
16
|
current: 0
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
const NoopSharedValue = () => ({
|
|
20
|
+
value: 0
|
|
21
|
+
});
|
|
22
|
+
|
|
19
23
|
const Mock = CanvasKit => {
|
|
20
24
|
global.SkiaApi = (0, _web.JsiSkApi)(CanvasKit);
|
|
21
25
|
global.SkiaValueApi = _web2.ValueApi;
|
|
@@ -30,6 +34,7 @@ const Mock = CanvasKit => {
|
|
|
30
34
|
...require("../dom/nodes"),
|
|
31
35
|
// We could use the real Canvas if we mock the SkiaView component for node
|
|
32
36
|
Canvas: Noop,
|
|
37
|
+
// Skia Animations
|
|
33
38
|
useValue: NoopValue,
|
|
34
39
|
useComputedValue: NoopValue,
|
|
35
40
|
useTouchHandler: Noop,
|
|
@@ -38,6 +43,9 @@ const Mock = CanvasKit => {
|
|
|
38
43
|
useSpring: NoopValue,
|
|
39
44
|
useClockValue: NoopValue,
|
|
40
45
|
useValueEffect: Noop,
|
|
46
|
+
// Reanimated hooks
|
|
47
|
+
useClock: NoopSharedValue,
|
|
48
|
+
usePathInterpolation: NoopSharedValue,
|
|
41
49
|
useRawData: Noop,
|
|
42
50
|
useData: Noop,
|
|
43
51
|
useFont: () => Skia.Font(undefined, 0),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Noop","undefined","NoopValue","current","Mock","CanvasKit","global","SkiaApi","JsiSkApi","SkiaValueApi","ValueApi","Skia","require","Canvas","useValue","useComputedValue","useTouchHandler","useTiming","useLoop","useSpring","useClockValue","useValueEffect","useRawData","useData","useFont","Font","useTypeface","useImage","useSVG"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { ValueApi } from \"../values/web\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n global.SkiaApi = JsiSkApi(CanvasKit);\n global.SkiaValueApi = ValueApi;\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../values\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n // We could use the real Canvas if we mock the SkiaView component for node\n Canvas: Noop,\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTouchHandler: Noop,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n };\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AAEA;AACA,MAAMA,IAAe,GAAG,MAAMC,SAA9B;;AACA,MAAMC,SAAS,GAAG,OAAO;EAAEC,OAAO,EAAE;AAAX,CAAP,CAAlB;;AAEO,MAAMC,IAAI,GAAIC,SAAD,IAA0B;EAC5CC,MAAM,CAACC,OAAP,GAAiB,IAAAC,aAAA,EAASH,SAAT,CAAjB;EACAC,MAAM,CAACG,YAAP,GAAsBC,cAAtB;EACA,MAAMC,IAAI,GAAGL,MAAM,CAACC,OAApB;EACA,OAAO;IACLI,IADK;IAEL,GAAGC,OAAO,CAAC,wBAAD,CAFL;IAGL,GAAGA,OAAO,CAAC,SAAD,CAHL;IAIL,GAAGA,OAAO,CAAC,WAAD,CAJL;IAKL,GAAGA,OAAO,CAAC,cAAD,CALL;IAML,GAAGA,OAAO,CAAC,cAAD,CANL;IAOL,GAAGA,OAAO,CAAC,cAAD,CAPL;IAQL;IACAC,MAAM,
|
|
1
|
+
{"version":3,"names":["Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","SkiaValueApi","ValueApi","Skia","require","Canvas","useValue","useComputedValue","useTouchHandler","useTiming","useLoop","useSpring","useClockValue","useValueEffect","useClock","usePathInterpolation","useRawData","useData","useFont","Font","useTypeface","useImage","useSVG"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { ValueApi } from \"../values/web\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n global.SkiaApi = JsiSkApi(CanvasKit);\n global.SkiaValueApi = ValueApi;\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../values\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n // We could use the real Canvas if we mock the SkiaView component for node\n Canvas: Noop,\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTouchHandler: Noop,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n };\n};\n"],"mappings":";;;;;;;AAEA;;AACA;;AAEA;AACA,MAAMA,IAAe,GAAG,MAAMC,SAA9B;;AACA,MAAMC,SAAS,GAAG,OAAO;EAAEC,OAAO,EAAE;AAAX,CAAP,CAAlB;;AACA,MAAMC,eAAe,GAAG,OAAO;EAAEC,KAAK,EAAE;AAAT,CAAP,CAAxB;;AAEO,MAAMC,IAAI,GAAIC,SAAD,IAA0B;EAC5CC,MAAM,CAACC,OAAP,GAAiB,IAAAC,aAAA,EAASH,SAAT,CAAjB;EACAC,MAAM,CAACG,YAAP,GAAsBC,cAAtB;EACA,MAAMC,IAAI,GAAGL,MAAM,CAACC,OAApB;EACA,OAAO;IACLI,IADK;IAEL,GAAGC,OAAO,CAAC,wBAAD,CAFL;IAGL,GAAGA,OAAO,CAAC,SAAD,CAHL;IAIL,GAAGA,OAAO,CAAC,WAAD,CAJL;IAKL,GAAGA,OAAO,CAAC,cAAD,CALL;IAML,GAAGA,OAAO,CAAC,cAAD,CANL;IAOL,GAAGA,OAAO,CAAC,cAAD,CAPL;IAQL;IACAC,MAAM,EAAEf,IATH;IAUL;IACAgB,QAAQ,EAAEd,SAXL;IAYLe,gBAAgB,EAAEf,SAZb;IAaLgB,eAAe,EAAElB,IAbZ;IAcLmB,SAAS,EAAEjB,SAdN;IAeLkB,OAAO,EAAElB,SAfJ;IAgBLmB,SAAS,EAAEnB,SAhBN;IAiBLoB,aAAa,EAAEpB,SAjBV;IAkBLqB,cAAc,EAAEvB,IAlBX;IAmBL;IACAwB,QAAQ,EAAEpB,eApBL;IAqBLqB,oBAAoB,EAAErB,eArBjB;IAsBLsB,UAAU,EAAE1B,IAtBP;IAuBL2B,OAAO,EAAE3B,IAvBJ;IAwBL4B,OAAO,EAAE,MAAMf,IAAI,CAACgB,IAAL,CAAU5B,SAAV,EAAqB,CAArB,CAxBV;IAyBL6B,WAAW,EAAE,MAAM,IAzBd;IA0BLC,QAAQ,EAAE,MAAM,IA1BX;IA2BLC,MAAM,EAAE,MAAM;EA3BT,CAAP;AA6BD,CAjCM"}
|