@shopify/react-native-skia 1.8.1 → 1.8.2
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/lib/commonjs/external/reanimated/useAnimatedImageValue.js +1 -8
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.js +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.js.map +1 -1
- package/lib/commonjs/skia/core/Data.d.ts +1 -1
- package/lib/commonjs/skia/core/Data.js +2 -8
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.js +1 -8
- package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/module/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/module/skia/core/AnimatedImage.js +1 -1
- package/lib/module/skia/core/AnimatedImage.js.map +1 -1
- package/lib/module/skia/core/Data.d.ts +1 -1
- package/lib/module/skia/core/Data.js +2 -8
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/typescript/lib/commonjs/skia/core/Data.d.ts +1 -1
- package/lib/typescript/lib/module/mock/index.d.ts +1 -1
- package/lib/typescript/lib/module/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/typescript/lib/module/skia/core/Data.d.ts +1 -1
- package/lib/typescript/src/skia/core/AnimatedImage.d.ts +1 -1
- package/lib/typescript/src/skia/core/Data.d.ts +1 -1
- package/package.json +1 -1
- package/src/external/reanimated/useAnimatedImageValue.ts +4 -15
- package/src/skia/core/AnimatedImage.ts +2 -3
- package/src/skia/core/Data.ts +3 -9
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.useAnimatedImageValue = void 0;
|
7
|
-
var _react = require("react");
|
8
7
|
var _AnimatedImage = require("../../skia/core/AnimatedImage");
|
9
8
|
var _ReanimatedProxy = _interopRequireDefault(require("./ReanimatedProxy"));
|
10
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
@@ -17,7 +16,7 @@ const useAnimatedImageValue = (source, paused) => {
|
|
17
16
|
const animatedImage = (0, _AnimatedImage.useAnimatedImage)(source, err => {
|
18
17
|
console.error(err);
|
19
18
|
throw new Error(`Could not load animated image - got '${err.message}'`);
|
20
|
-
}
|
19
|
+
});
|
21
20
|
const frameDuration = (animatedImage === null || animatedImage === void 0 ? void 0 : animatedImage.currentFrameDuration()) || DEFAULT_FRAME_DURATION;
|
22
21
|
_ReanimatedProxy.default.useFrameCallback(frameInfo => {
|
23
22
|
if (!animatedImage) {
|
@@ -47,12 +46,6 @@ const useAnimatedImageValue = (source, paused) => {
|
|
47
46
|
// Update the last timestamp
|
48
47
|
lastTimestamp.value = timestamp;
|
49
48
|
});
|
50
|
-
(0, _react.useEffect)(() => {
|
51
|
-
return () => {
|
52
|
-
animatedImage === null || animatedImage === void 0 || animatedImage.dispose();
|
53
|
-
};
|
54
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
55
|
-
}, []);
|
56
49
|
return currentFrame;
|
57
50
|
};
|
58
51
|
exports.useAnimatedImageValue = useAnimatedImageValue;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_AnimatedImage","require","_ReanimatedProxy","_interopRequireDefault","e","__esModule","default","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","Rea","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","useAnimatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame","exports"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import type { FrameInfo, SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n const defaultPaused = Rea.useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\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 Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\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 });\n return currentFrame;\n};\n"],"mappings":";;;;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AAGA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAoC,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAEpC,MAAMG,sBAAsB,GAAG,EAAE;AAE1B,MAAMC,qBAAqB,GAAGA,CACnCC,MAAuB,EACvBC,MAA6B,KAC1B;EACH,MAAMC,aAAa,GAAGC,wBAAG,CAACC,cAAc,CAAC,KAAK,CAAC;EAC/C,MAAMC,QAAQ,GAAGJ,MAAM,aAANA,MAAM,cAANA,MAAM,GAAI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from "../types";
|
|
2
2
|
/**
|
3
3
|
* Returns a Skia Animated Image object
|
4
4
|
* */
|
5
|
-
export declare const useAnimatedImage: (source: DataSourceParam, onError?: (err: Error) => void
|
5
|
+
export declare const useAnimatedImage: (source: DataSourceParam, onError?: (err: Error) => void) => import("../types").SkAnimatedImage | null;
|
@@ -11,6 +11,6 @@ const animatedImgFactory = _Skia.Skia.AnimatedImage.MakeAnimatedImageFromEncoded
|
|
11
11
|
/**
|
12
12
|
* Returns a Skia Animated Image object
|
13
13
|
* */
|
14
|
-
const useAnimatedImage = (source, onError
|
14
|
+
const useAnimatedImage = (source, onError) => (0, _Data.useRawData)(source, animatedImgFactory, onError);
|
15
15
|
exports.useAnimatedImage = useAnimatedImage;
|
16
16
|
//# sourceMappingURL=AnimatedImage.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_Skia","require","_Data","animatedImgFactory","Skia","AnimatedImage","MakeAnimatedImageFromEncoded","bind","useAnimatedImage","source","onError","
|
1
|
+
{"version":3,"names":["_Skia","require","_Data","animatedImgFactory","Skia","AnimatedImage","MakeAnimatedImageFromEncoded","bind","useAnimatedImage","source","onError","useRawData","exports"],"sources":["AnimatedImage.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSourceParam } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(\n Skia.AnimatedImage\n);\n\n/**\n * Returns a Skia Animated Image object\n * */\nexport const useAnimatedImage = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, animatedImgFactory, onError);\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAGA,IAAAC,KAAA,GAAAD,OAAA;AAEA,MAAME,kBAAkB,GAAGC,UAAI,CAACC,aAAa,CAACC,4BAA4B,CAACC,IAAI,CAC7EH,UAAI,CAACC,aACP,CAAC;;AAED;AACA;AACA;AACO,MAAMG,gBAAgB,GAAGA,CAC9BC,MAAuB,EACvBC,OAA8B,KAC3B,IAAAC,gBAAU,EAACF,MAAM,EAAEN,kBAAkB,EAAEO,OAAO,CAAC;AAACE,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
|
2
2
|
export declare const loadData: <T>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void) => Promise<T | null>;
|
3
3
|
export declare const useCollectionLoading: <T extends SkJSIInstance<string>>(source: DataSourceParam[], loader: () => Promise<(T | null)[]>) => T[] | null;
|
4
|
-
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void
|
4
|
+
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void) => T | null;
|
5
5
|
export declare const useData: (source: DataSourceParam, onError?: (err: Error) => void) => SkData | null;
|
@@ -27,7 +27,7 @@ const loadData = (source, factory, onError) => {
|
|
27
27
|
}
|
28
28
|
};
|
29
29
|
exports.loadData = loadData;
|
30
|
-
const useLoading = (source, loader
|
30
|
+
const useLoading = (source, loader) => {
|
31
31
|
const mounted = (0, _react.useRef)(false);
|
32
32
|
const [data, setData] = (0, _react.useState)(null);
|
33
33
|
const dataRef = (0, _react.useRef)(null);
|
@@ -40,10 +40,6 @@ const useLoading = (source, loader, manage = true) => {
|
|
40
40
|
}
|
41
41
|
});
|
42
42
|
return () => {
|
43
|
-
if (manage) {
|
44
|
-
var _dataRef$current;
|
45
|
-
(_dataRef$current = dataRef.current) === null || _dataRef$current === void 0 || _dataRef$current.dispose();
|
46
|
-
}
|
47
43
|
mounted.current = false;
|
48
44
|
};
|
49
45
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -64,8 +60,6 @@ const useCollectionLoading = (source, loader) => {
|
|
64
60
|
}
|
65
61
|
});
|
66
62
|
return () => {
|
67
|
-
var _dataRef$current2;
|
68
|
-
(_dataRef$current2 = dataRef.current) === null || _dataRef$current2 === void 0 || _dataRef$current2.forEach(instance => instance === null || instance === void 0 ? void 0 : instance.dispose());
|
69
63
|
mounted.current = false;
|
70
64
|
};
|
71
65
|
|
@@ -74,7 +68,7 @@ const useCollectionLoading = (source, loader) => {
|
|
74
68
|
return data;
|
75
69
|
};
|
76
70
|
exports.useCollectionLoading = useCollectionLoading;
|
77
|
-
const useRawData = (source, factory, onError
|
71
|
+
const useRawData = (source, factory, onError) => useLoading(source, () => loadData(source, factory, onError));
|
78
72
|
exports.useRawData = useRawData;
|
79
73
|
const identity = data => data;
|
80
74
|
const useData = (source, onError) => useRawData(source, identity, onError);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_Skia","_Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","uri","Platform","resolveAsset","fromURI","then","d","exports","useLoading","loader","
|
1
|
+
{"version":3,"names":["_react","require","_Skia","_Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Skia","Data","fromBytes","uri","Platform","resolveAsset","fromURI","then","d","exports","useLoading","loader","mounted","useRef","data","setData","useState","dataRef","useEffect","current","value","useCollectionLoading","result","filter","r","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, SkJSIInstance } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nexport const loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\n\nconst useLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useCollectionLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam[],\n loader: () => Promise<(T | null)[]>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T[] | null>(null);\n const dataRef = useRef<T[] | null>(null);\n\n useEffect(() => {\n mounted.current = true;\n loader().then((result) => {\n const value = result.filter((r) => r !== null) as T[];\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n\n return () => {\n mounted.current = false;\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n\n return data;\n};\n\nexport const useRawData = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,SAAA,GAAAF,OAAA;AAEA,MAAMG,cAAc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;AAACL,OAAA,CAAAY,oBAAA,GAAAA,oBAAA;AAEK,MAAMI,UAAU,GAAGA,CACxB9B,MAAuB,EACvBL,OAAmC,EACnCC,OAA8B,KAC3BmB,UAAU,CAACf,MAAM,EAAE,MAAMD,QAAQ,CAAIC,MAAM,EAAEL,OAAO,EAAEC,OAAO,CAAC,CAAC;AAACkB,OAAA,CAAAgB,UAAA,GAAAA,UAAA;AAErE,MAAMC,QAAQ,GAAIZ,IAAY,IAAKA,IAAI;AAEhC,MAAMa,OAAO,GAAGA,CACrBhC,MAAuB,EACvBJ,OAA8B,KAC3BkC,UAAU,CAAC9B,MAAM,EAAE+B,QAAQ,EAAEnC,OAAO,CAAC;AAACkB,OAAA,CAAAkB,OAAA,GAAAA,OAAA","ignoreList":[]}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { useEffect } from "react";
|
2
1
|
import { useAnimatedImage } from "../../skia/core/AnimatedImage";
|
3
2
|
import Rea from "./ReanimatedProxy";
|
4
3
|
const DEFAULT_FRAME_DURATION = 60;
|
@@ -10,7 +9,7 @@ export const useAnimatedImageValue = (source, paused) => {
|
|
10
9
|
const animatedImage = useAnimatedImage(source, err => {
|
11
10
|
console.error(err);
|
12
11
|
throw new Error(`Could not load animated image - got '${err.message}'`);
|
13
|
-
}
|
12
|
+
});
|
14
13
|
const frameDuration = (animatedImage === null || animatedImage === void 0 ? void 0 : animatedImage.currentFrameDuration()) || DEFAULT_FRAME_DURATION;
|
15
14
|
Rea.useFrameCallback(frameInfo => {
|
16
15
|
if (!animatedImage) {
|
@@ -40,12 +39,6 @@ export const useAnimatedImageValue = (source, paused) => {
|
|
40
39
|
// Update the last timestamp
|
41
40
|
lastTimestamp.value = timestamp;
|
42
41
|
});
|
43
|
-
useEffect(() => {
|
44
|
-
return () => {
|
45
|
-
animatedImage === null || animatedImage === void 0 || animatedImage.dispose();
|
46
|
-
};
|
47
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
48
|
-
}, []);
|
49
42
|
return currentFrame;
|
50
43
|
};
|
51
44
|
//# sourceMappingURL=useAnimatedImageValue.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["useAnimatedImage","Rea","DEFAULT_FRAME_DURATION","useAnimatedImageValue","source","paused","defaultPaused","useSharedValue","isPaused","currentFrame","lastTimestamp","animatedImage","err","console","error","Error","message","frameDuration","currentFrameDuration","useFrameCallback","frameInfo","value","timestamp","elapsed","decodeNextFrame","dispose","getCurrentFrame"],"sources":["useAnimatedImageValue.ts"],"sourcesContent":["import type { FrameInfo, SharedValue } from \"react-native-reanimated\";\n\nimport { useAnimatedImage } from \"../../skia/core/AnimatedImage\";\nimport type { DataSourceParam, SkImage } from \"../../skia/types\";\n\nimport Rea from \"./ReanimatedProxy\";\n\nconst DEFAULT_FRAME_DURATION = 60;\n\nexport const useAnimatedImageValue = (\n source: DataSourceParam,\n paused?: SharedValue<boolean>\n) => {\n const defaultPaused = Rea.useSharedValue(false);\n const isPaused = paused ?? defaultPaused;\n const currentFrame = Rea.useSharedValue<null | SkImage>(null);\n const lastTimestamp = Rea.useSharedValue(-1);\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 Rea.useFrameCallback((frameInfo: FrameInfo) => {\n if (!animatedImage) {\n currentFrame.value = null;\n return;\n }\n if (isPaused.value && lastTimestamp.value !== -1) {\n return;\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 });\n return currentFrame;\n};\n"],"mappings":"AAEA,SAASA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K,CAACI,OAAO,CAAC,CAAC;IAC9B;IACAhB,YAAY,CAACY,KAAK,GAAGV,aAAa,CAACe,eAAe,CAAC,CAAC;;IAEpD;IACAhB,aAAa,CAACW,KAAK,GAAGC,SAAS;EACjC,CAAC,CAAC;EACF,OAAOb,YAAY;AACrB,CAAC","ignoreList":[]}
|
@@ -2,4 +2,4 @@ import type { DataSourceParam } from "../types";
|
|
2
2
|
/**
|
3
3
|
* Returns a Skia Animated Image object
|
4
4
|
* */
|
5
|
-
export declare const useAnimatedImage: (source: DataSourceParam, onError?: (err: Error) => void
|
5
|
+
export declare const useAnimatedImage: (source: DataSourceParam, onError?: (err: Error) => void) => import("../types").SkAnimatedImage | null;
|
@@ -5,5 +5,5 @@ const animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(
|
|
5
5
|
/**
|
6
6
|
* Returns a Skia Animated Image object
|
7
7
|
* */
|
8
|
-
export const useAnimatedImage = (source, onError
|
8
|
+
export const useAnimatedImage = (source, onError) => useRawData(source, animatedImgFactory, onError);
|
9
9
|
//# sourceMappingURL=AnimatedImage.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["Skia","useRawData","animatedImgFactory","AnimatedImage","MakeAnimatedImageFromEncoded","bind","useAnimatedImage","source","onError"
|
1
|
+
{"version":3,"names":["Skia","useRawData","animatedImgFactory","AnimatedImage","MakeAnimatedImageFromEncoded","bind","useAnimatedImage","source","onError"],"sources":["AnimatedImage.ts"],"sourcesContent":["import { Skia } from \"../Skia\";\nimport type { DataSourceParam } from \"../types\";\n\nimport { useRawData } from \"./Data\";\n\nconst animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(\n Skia.AnimatedImage\n);\n\n/**\n * Returns a Skia Animated Image object\n * */\nexport const useAnimatedImage = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, animatedImgFactory, onError);\n"],"mappings":"AAAA,SAASA,IAAI,QAAQ,SAAS;AAG9B,SAASC,UAAU,QAAQ,QAAQ;AAEnC,MAAMC,kBAAkB,GAAGF,IAAI,CAACG,aAAa,CAACC,4BAA4B,CAACC,IAAI,CAC7EL,IAAI,CAACG,aACP,CAAC;;AAED;AACA;AACA;AACA,OAAO,MAAMG,gBAAgB,GAAGA,CAC9BC,MAAuB,EACvBC,OAA8B,KAC3BP,UAAU,CAACM,MAAM,EAAEL,kBAAkB,EAAEM,OAAO,CAAC","ignoreList":[]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
|
2
2
|
export declare const loadData: <T>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void) => Promise<T | null>;
|
3
3
|
export declare const useCollectionLoading: <T extends SkJSIInstance<string>>(source: DataSourceParam[], loader: () => Promise<(T | null)[]>) => T[] | null;
|
4
|
-
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void
|
4
|
+
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void) => T | null;
|
5
5
|
export declare const useData: (source: DataSourceParam, onError?: (err: Error) => void) => SkData | null;
|
@@ -20,7 +20,7 @@ export const loadData = (source, factory, onError) => {
|
|
20
20
|
return Skia.Data.fromURI(uri).then(d => factoryWrapper(d, factory, onError));
|
21
21
|
}
|
22
22
|
};
|
23
|
-
const useLoading = (source, loader
|
23
|
+
const useLoading = (source, loader) => {
|
24
24
|
const mounted = useRef(false);
|
25
25
|
const [data, setData] = useState(null);
|
26
26
|
const dataRef = useRef(null);
|
@@ -33,10 +33,6 @@ const useLoading = (source, loader, manage = true) => {
|
|
33
33
|
}
|
34
34
|
});
|
35
35
|
return () => {
|
36
|
-
if (manage) {
|
37
|
-
var _dataRef$current;
|
38
|
-
(_dataRef$current = dataRef.current) === null || _dataRef$current === void 0 || _dataRef$current.dispose();
|
39
|
-
}
|
40
36
|
mounted.current = false;
|
41
37
|
};
|
42
38
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -57,8 +53,6 @@ export const useCollectionLoading = (source, loader) => {
|
|
57
53
|
}
|
58
54
|
});
|
59
55
|
return () => {
|
60
|
-
var _dataRef$current2;
|
61
|
-
(_dataRef$current2 = dataRef.current) === null || _dataRef$current2 === void 0 || _dataRef$current2.forEach(instance => instance === null || instance === void 0 ? void 0 : instance.dispose());
|
62
56
|
mounted.current = false;
|
63
57
|
};
|
64
58
|
|
@@ -66,7 +60,7 @@ export const useCollectionLoading = (source, loader) => {
|
|
66
60
|
}, [source]);
|
67
61
|
return data;
|
68
62
|
};
|
69
|
-
export const useRawData = (source, factory, onError
|
63
|
+
export const useRawData = (source, factory, onError) => useLoading(source, () => loadData(source, factory, onError));
|
70
64
|
const identity = data => data;
|
71
65
|
export const useData = (source, onError) => useRawData(source, identity, onError);
|
72
66
|
//# sourceMappingURL=Data.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","useState","Skia","Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Data","fromBytes","uri","resolveAsset","fromURI","then","d","useLoading","loader","
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","Skia","Platform","factoryWrapper","data2","factory","onError","factoryResult","Error","loadData","source","undefined","Promise","resolve","Uint8Array","Data","fromBytes","uri","resolveAsset","fromURI","then","d","useLoading","loader","mounted","data","setData","dataRef","current","value","useCollectionLoading","result","filter","r","useRawData","identity","useData"],"sources":["Data.ts"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\n\nimport { Skia } from \"../Skia\";\nimport type { SkData, DataSourceParam, SkJSIInstance } from \"../types\";\nimport { Platform } from \"../../Platform\";\n\nconst factoryWrapper = <T>(\n data2: SkData,\n factory: (data: SkData) => T,\n onError?: (err: Error) => void\n) => {\n const factoryResult = factory(data2);\n if (factoryResult === null) {\n onError && onError(new Error(\"Could not load data\"));\n return null;\n } else {\n return factoryResult;\n }\n};\n\nexport const loadData = <T>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n): Promise<T | null> => {\n if (source === null || source === undefined) {\n return new Promise((resolve) => resolve(null));\n } else if (source instanceof Uint8Array) {\n return new Promise((resolve) =>\n resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))\n );\n } else {\n const uri =\n typeof source === \"string\" ? source : Platform.resolveAsset(source);\n return Skia.Data.fromURI(uri).then((d) =>\n factoryWrapper(d, factory, onError)\n );\n }\n};\n\nconst useLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n loader: () => Promise<T | null>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T | null>(null);\n const dataRef = useRef<T | null>(null);\n useEffect(() => {\n mounted.current = true;\n loader().then((value) => {\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n return () => {\n mounted.current = false;\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n return data;\n};\n\nexport const useCollectionLoading = <T extends SkJSIInstance<string>>(\n source: DataSourceParam[],\n loader: () => Promise<(T | null)[]>\n) => {\n const mounted = useRef(false);\n const [data, setData] = useState<T[] | null>(null);\n const dataRef = useRef<T[] | null>(null);\n\n useEffect(() => {\n mounted.current = true;\n loader().then((result) => {\n const value = result.filter((r) => r !== null) as T[];\n if (mounted.current) {\n setData(value);\n dataRef.current = value;\n }\n });\n\n return () => {\n mounted.current = false;\n };\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [source]);\n\n return data;\n};\n\nexport const useRawData = <T extends SkJSIInstance<string>>(\n source: DataSourceParam,\n factory: (data: SkData) => T | null,\n onError?: (err: Error) => void\n) => useLoading(source, () => loadData<T>(source, factory, onError));\n\nconst identity = (data: SkData) => data;\n\nexport const useData = (\n source: DataSourceParam,\n onError?: (err: Error) => void\n) => useRawData(source, identity, onError);\n"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAA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AC,CAAC;EAEZ,OAAOe,IAAI;AACb,CAAC;AAED,OAAO,MAAMS,UAAU,GAAGA,CACxBxB,MAAuB,EACvBL,OAAmC,EACnCC,OAA8B,KAC3BgB,UAAU,CAACZ,MAAM,EAAE,MAAMD,QAAQ,CAAIC,MAAM,EAAEL,OAAO,EAAEC,OAAO,CAAC,CAAC;AAEpE,MAAM6B,QAAQ,GAAIV,IAAY,IAAKA,IAAI;AAEvC,OAAO,MAAMW,OAAO,GAAGA,CACrB1B,MAAuB,EACvBJ,OAA8B,KAC3B4B,UAAU,CAACxB,MAAM,EAAEyB,QAAQ,EAAE7B,OAAO,CAAC","ignoreList":[]}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
export const __esModule: boolean;
|
2
2
|
export function loadData(source: any, factory: any, onError: any): Promise<any>;
|
3
3
|
export function useCollectionLoading(source: any, loader: any): null;
|
4
|
-
export function useRawData(source: any, factory: any, onError: any
|
4
|
+
export function useRawData(source: any, factory: any, onError: any): null;
|
5
5
|
export function useData(source: any, onError: any): null;
|
@@ -154,7 +154,7 @@ export function Mock(CanvasKit: any): {
|
|
154
154
|
matchFont: (inputStyle?: {}, fontMgr?: import("../../..").SkFontMgr) => import("../../..").SkFont;
|
155
155
|
listFontFamilies: (fontMgr?: import("../../..").SkFontMgr) => string[];
|
156
156
|
makeImageFromView: (viewRef: any, callback?: null) => any;
|
157
|
-
useAnimatedImage: (source: any, onError: any
|
157
|
+
useAnimatedImage: (source: any, onError: any) => null;
|
158
158
|
createPicture: (cb: any, rect: any) => import("../../..").SkPicture;
|
159
159
|
vec: (x: number | undefined, y: any) => import("../../..").SkPoint;
|
160
160
|
point: (x: number | undefined, y: any) => import("../../..").SkPoint;
|
@@ -1 +1 @@
|
|
1
|
-
export function useAnimatedImage(source: any, onError: any
|
1
|
+
export function useAnimatedImage(source: any, onError: any): null;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
export function loadData(source: any, factory: any, onError: any): Promise<any>;
|
2
2
|
export function useCollectionLoading(source: any, loader: any): null;
|
3
|
-
export function useRawData(source: any, factory: any, onError: any
|
3
|
+
export function useRawData(source: any, factory: any, onError: any): null;
|
4
4
|
export function useData(source: any, onError: any): null;
|
@@ -2,4 +2,4 @@ import type { DataSourceParam } from "../types";
|
|
2
2
|
/**
|
3
3
|
* Returns a Skia Animated Image object
|
4
4
|
* */
|
5
|
-
export declare const useAnimatedImage: (source: DataSourceParam, onError?: (err: Error) => void
|
5
|
+
export declare const useAnimatedImage: (source: DataSourceParam, onError?: (err: Error) => void) => import("../types").SkAnimatedImage | null;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { SkData, DataSourceParam, SkJSIInstance } from "../types";
|
2
2
|
export declare const loadData: <T>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void) => Promise<T | null>;
|
3
3
|
export declare const useCollectionLoading: <T extends SkJSIInstance<string>>(source: DataSourceParam[], loader: () => Promise<(T | null)[]>) => T[] | null;
|
4
|
-
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void
|
4
|
+
export declare const useRawData: <T extends SkJSIInstance<string>>(source: DataSourceParam, factory: (data: SkData) => T | null, onError?: (err: Error) => void) => T | null;
|
5
5
|
export declare const useData: (source: DataSourceParam, onError?: (err: Error) => void) => SkData | null;
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
8
|
},
|
9
9
|
"title": "React Native Skia",
|
10
|
-
"version": "1.8.
|
10
|
+
"version": "1.8.2",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"react-native": "src/index.ts",
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { useEffect } from "react";
|
2
1
|
import type { FrameInfo, SharedValue } from "react-native-reanimated";
|
3
2
|
|
4
3
|
import { useAnimatedImage } from "../../skia/core/AnimatedImage";
|
@@ -16,14 +15,10 @@ export const useAnimatedImageValue = (
|
|
16
15
|
const isPaused = paused ?? defaultPaused;
|
17
16
|
const currentFrame = Rea.useSharedValue<null | SkImage>(null);
|
18
17
|
const lastTimestamp = Rea.useSharedValue(-1);
|
19
|
-
const animatedImage = useAnimatedImage(
|
20
|
-
|
21
|
-
(
|
22
|
-
|
23
|
-
throw new Error(`Could not load animated image - got '${err.message}'`);
|
24
|
-
},
|
25
|
-
false
|
26
|
-
);
|
18
|
+
const animatedImage = useAnimatedImage(source, (err) => {
|
19
|
+
console.error(err);
|
20
|
+
throw new Error(`Could not load animated image - got '${err.message}'`);
|
21
|
+
});
|
27
22
|
const frameDuration =
|
28
23
|
animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;
|
29
24
|
|
@@ -53,11 +48,5 @@ export const useAnimatedImageValue = (
|
|
53
48
|
// Update the last timestamp
|
54
49
|
lastTimestamp.value = timestamp;
|
55
50
|
});
|
56
|
-
useEffect(() => {
|
57
|
-
return () => {
|
58
|
-
animatedImage?.dispose();
|
59
|
-
};
|
60
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
61
|
-
}, []);
|
62
51
|
return currentFrame;
|
63
52
|
};
|
@@ -12,6 +12,5 @@ const animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(
|
|
12
12
|
* */
|
13
13
|
export const useAnimatedImage = (
|
14
14
|
source: DataSourceParam,
|
15
|
-
onError?: (err: Error) => void
|
16
|
-
|
17
|
-
) => useRawData(source, animatedImgFactory, onError, managed);
|
15
|
+
onError?: (err: Error) => void
|
16
|
+
) => useRawData(source, animatedImgFactory, onError);
|
package/src/skia/core/Data.ts
CHANGED
@@ -40,8 +40,7 @@ export const loadData = <T>(
|
|
40
40
|
|
41
41
|
const useLoading = <T extends SkJSIInstance<string>>(
|
42
42
|
source: DataSourceParam,
|
43
|
-
loader: () => Promise<T | null
|
44
|
-
manage = true
|
43
|
+
loader: () => Promise<T | null>
|
45
44
|
) => {
|
46
45
|
const mounted = useRef(false);
|
47
46
|
const [data, setData] = useState<T | null>(null);
|
@@ -55,9 +54,6 @@ const useLoading = <T extends SkJSIInstance<string>>(
|
|
55
54
|
}
|
56
55
|
});
|
57
56
|
return () => {
|
58
|
-
if (manage) {
|
59
|
-
dataRef.current?.dispose();
|
60
|
-
}
|
61
57
|
mounted.current = false;
|
62
58
|
};
|
63
59
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
@@ -84,7 +80,6 @@ export const useCollectionLoading = <T extends SkJSIInstance<string>>(
|
|
84
80
|
});
|
85
81
|
|
86
82
|
return () => {
|
87
|
-
dataRef.current?.forEach((instance) => instance?.dispose());
|
88
83
|
mounted.current = false;
|
89
84
|
};
|
90
85
|
|
@@ -97,9 +92,8 @@ export const useCollectionLoading = <T extends SkJSIInstance<string>>(
|
|
97
92
|
export const useRawData = <T extends SkJSIInstance<string>>(
|
98
93
|
source: DataSourceParam,
|
99
94
|
factory: (data: SkData) => T | null,
|
100
|
-
onError?: (err: Error) => void
|
101
|
-
|
102
|
-
) => useLoading(source, () => loadData<T>(source, factory, onError), manage);
|
95
|
+
onError?: (err: Error) => void
|
96
|
+
) => useLoading(source, () => loadData<T>(source, factory, onError));
|
103
97
|
|
104
98
|
const identity = (data: SkData) => data;
|
105
99
|
|