@shopify/react-native-skia 0.1.210 → 0.1.211
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/JsiSkAnimatedImage.h +60 -0
- package/cpp/api/JsiSkAnimatedImageFactory.h +39 -0
- package/cpp/api/JsiSkApi.h +4 -0
- package/cpp/api/JsiSkImage.h +15 -23
- package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +2 -0
- package/lib/commonjs/external/reanimated/moduleWrapper.js +11 -11
- package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/commonjs/skia/core/AnimatedImage.d.ts +6 -0
- package/lib/commonjs/skia/core/AnimatedImage.js +65 -0
- package/lib/commonjs/skia/core/AnimatedImage.js.map +1 -0
- package/lib/commonjs/skia/core/index.d.ts +1 -0
- package/lib/commonjs/skia/core/index.js +13 -0
- package/lib/commonjs/skia/core/index.js.map +1 -1
- package/lib/commonjs/skia/types/AnimatedImage/AnimatedImage.d.ts +24 -0
- package/lib/commonjs/skia/types/AnimatedImage/AnimatedImage.js +6 -0
- package/lib/commonjs/skia/types/AnimatedImage/AnimatedImage.js.map +1 -0
- package/lib/commonjs/skia/types/AnimatedImage/AnimatedImageFactory.d.ts +13 -0
- package/lib/commonjs/skia/types/AnimatedImage/AnimatedImageFactory.js +6 -0
- package/lib/commonjs/skia/types/AnimatedImage/AnimatedImageFactory.js.map +1 -0
- package/lib/commonjs/skia/types/AnimatedImage/index.d.ts +2 -0
- package/lib/commonjs/skia/types/AnimatedImage/index.js +32 -0
- package/lib/commonjs/skia/types/AnimatedImage/index.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +13 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkAnimatedImage.d.ts +11 -0
- package/lib/commonjs/skia/web/JsiSkAnimatedImage.js +44 -0
- package/lib/commonjs/skia/web/JsiSkAnimatedImage.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkAnimatedImageFactory.d.ts +9 -0
- package/lib/commonjs/skia/web/JsiSkAnimatedImageFactory.js +32 -0
- package/lib/commonjs/skia/web/JsiSkAnimatedImageFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkia.js +3 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/external/reanimated/moduleWrapper.d.ts +2 -0
- package/lib/module/external/reanimated/moduleWrapper.js +8 -11
- package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/module/skia/core/AnimatedImage.d.ts +6 -0
- package/lib/module/skia/core/AnimatedImage.js +49 -0
- package/lib/module/skia/core/AnimatedImage.js.map +1 -0
- package/lib/module/skia/core/index.d.ts +1 -0
- package/lib/module/skia/core/index.js +1 -0
- package/lib/module/skia/core/index.js.map +1 -1
- package/lib/module/skia/types/AnimatedImage/AnimatedImage.d.ts +24 -0
- package/lib/module/skia/types/AnimatedImage/AnimatedImage.js +2 -0
- package/lib/module/skia/types/AnimatedImage/AnimatedImage.js.map +1 -0
- package/lib/module/skia/types/AnimatedImage/AnimatedImageFactory.d.ts +13 -0
- package/lib/module/skia/types/AnimatedImage/AnimatedImageFactory.js +2 -0
- package/lib/module/skia/types/AnimatedImage/AnimatedImageFactory.js.map +1 -0
- package/lib/module/skia/types/AnimatedImage/index.d.ts +2 -0
- package/lib/module/skia/types/AnimatedImage/index.js +3 -0
- package/lib/module/skia/types/AnimatedImage/index.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkAnimatedImage.d.ts +11 -0
- package/lib/module/skia/web/JsiSkAnimatedImage.js +33 -0
- package/lib/module/skia/web/JsiSkAnimatedImage.js.map +1 -0
- package/lib/module/skia/web/JsiSkAnimatedImageFactory.d.ts +9 -0
- package/lib/module/skia/web/JsiSkAnimatedImageFactory.js +20 -0
- package/lib/module/skia/web/JsiSkAnimatedImageFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkia.js +2 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +2 -0
- package/lib/typescript/src/skia/core/AnimatedImage.d.ts +6 -0
- package/lib/typescript/src/skia/core/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/AnimatedImage/AnimatedImage.d.ts +24 -0
- package/lib/typescript/src/skia/types/AnimatedImage/AnimatedImageFactory.d.ts +13 -0
- package/lib/typescript/src/skia/types/AnimatedImage/index.d.ts +2 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkAnimatedImage.d.ts +11 -0
- package/lib/typescript/src/skia/web/JsiSkAnimatedImageFactory.d.ts +9 -0
- package/package.json +1 -1
- package/src/external/reanimated/moduleWrapper.ts +9 -8
- package/src/skia/core/AnimatedImage.ts +63 -0
- package/src/skia/core/index.ts +1 -0
- package/src/skia/types/AnimatedImage/AnimatedImage.ts +29 -0
- package/src/skia/types/AnimatedImage/AnimatedImageFactory.ts +15 -0
- package/src/skia/types/AnimatedImage/index.ts +2 -0
- package/src/skia/types/Skia.ts +3 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkAnimatedImage.ts +35 -0
- package/src/skia/web/JsiSkAnimatedImageFactory.ts +27 -0
- package/src/skia/web/JsiSkia.ts +2 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { SharedValueType } from "../../renderer/processors/Animations";
|
|
2
2
|
export declare const HAS_REANIMATED2: boolean;
|
|
3
3
|
export declare const HAS_REANIMATED3: boolean;
|
|
4
|
+
export declare function throwOnMissingReanimated(): void;
|
|
4
5
|
export declare const useSharedValue: any;
|
|
6
|
+
export declare const useFrameCallback: (...args: any[]) => any;
|
|
5
7
|
export declare const startMapper: any;
|
|
6
8
|
export declare const stopMapper: any;
|
|
7
9
|
export declare const runOnJS: any;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DataSourceParam } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Returns a Skia Animated Image object
|
|
4
|
+
* */
|
|
5
|
+
export declare const useAnimatedImage: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => import("../types").SkAnimatedImage | null;
|
|
6
|
+
export declare const useAnimatedImageValue: (source: DataSourceParam) => any;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SkJSIInstance } from "../JsiInstance";
|
|
2
|
+
import type { SkImage } from "../Image";
|
|
3
|
+
export interface SkAnimatedImage extends SkJSIInstance<"AnimatedImage"> {
|
|
4
|
+
/**
|
|
5
|
+
* Decode the next frame.
|
|
6
|
+
*
|
|
7
|
+
* If the animation is on the last frame or has hit an error, returns
|
|
8
|
+
* kFinished (-1).
|
|
9
|
+
*/
|
|
10
|
+
decodeNextFrame(): number;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the current frame as an SkImage. The SkImage will not change
|
|
13
|
+
* after it has been returned.
|
|
14
|
+
* If there is no current frame, null will be returned.
|
|
15
|
+
*/
|
|
16
|
+
getCurrentFrame(): SkImage | null;
|
|
17
|
+
/**
|
|
18
|
+
* How long to display the current frame.
|
|
19
|
+
*
|
|
20
|
+
* Useful for the first frame, for which decodeNextFrame is called
|
|
21
|
+
* internally.
|
|
22
|
+
*/
|
|
23
|
+
currentFrameDuration(): number;
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SkData } from "../Data";
|
|
2
|
+
import type { SkAnimatedImage } from "./AnimatedImage";
|
|
3
|
+
export interface AnimatedImageFactory {
|
|
4
|
+
/**
|
|
5
|
+
* Decodes the given bytes into an animated image. Returns null if the bytes were invalid.
|
|
6
|
+
* The passed in bytes will be copied into the WASM heap, so the caller can dispose of them.
|
|
7
|
+
*
|
|
8
|
+
* The returned AnimatedImage will be "pointing to" the first frame, i.e. currentFrameDuration
|
|
9
|
+
* and makeImageAtCurrentFrame will be referring to the first frame.
|
|
10
|
+
* @param encoded
|
|
11
|
+
*/
|
|
12
|
+
MakeAnimatedImageFromEncoded: (encoded: SkData) => SkAnimatedImage | null;
|
|
13
|
+
}
|
|
@@ -24,6 +24,7 @@ import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
|
24
24
|
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
|
25
25
|
import type { Color, SkColor } from "./Color";
|
|
26
26
|
import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
|
|
27
|
+
import type { AnimatedImageFactory } from "./AnimatedImage";
|
|
27
28
|
/**
|
|
28
29
|
* Declares the interface for the native Skia API
|
|
29
30
|
*/
|
|
@@ -63,6 +64,7 @@ export interface Skia {
|
|
|
63
64
|
MakeVertices(mode: VertexMode, positions: SkPoint[], textureCoordinates?: SkPoint[] | null, colors?: SkColor[], indices?: number[] | null, isVolatile?: boolean): SkVertices;
|
|
64
65
|
Data: DataFactory;
|
|
65
66
|
Image: ImageFactory;
|
|
67
|
+
AnimatedImage: AnimatedImageFactory;
|
|
66
68
|
SVG: SVGFactory;
|
|
67
69
|
TextBlob: TextBlobFactory;
|
|
68
70
|
Surface: SurfaceFactory;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AnimatedImage, CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
import type { SkAnimatedImage } from "../types/AnimatedImage";
|
|
3
|
+
import { HostObject } from "./Host";
|
|
4
|
+
import { JsiSkImage } from "./JsiSkImage";
|
|
5
|
+
export declare class JsiSkAnimatedImage extends HostObject<AnimatedImage, "AnimatedImage"> implements SkAnimatedImage {
|
|
6
|
+
constructor(CanvasKit: CanvasKit, ref: AnimatedImage);
|
|
7
|
+
decodeNextFrame(): number;
|
|
8
|
+
currentFrameDuration(): number;
|
|
9
|
+
getCurrentFrame(): JsiSkImage | null;
|
|
10
|
+
dispose: () => void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
import type { SkData } from "../types";
|
|
3
|
+
import type { AnimatedImageFactory } from "../types/AnimatedImage/AnimatedImageFactory";
|
|
4
|
+
import { Host } from "./Host";
|
|
5
|
+
import { JsiSkAnimatedImage } from "./JsiSkAnimatedImage";
|
|
6
|
+
export declare class JsiSkAnimatedImageFactory extends Host implements AnimatedImageFactory {
|
|
7
|
+
constructor(CanvasKit: CanvasKit);
|
|
8
|
+
MakeAnimatedImageFromEncoded(encoded: SkData): JsiSkAnimatedImage | null;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { useMemo } from "react";
|
|
2
3
|
|
|
3
4
|
import type { SharedValueType } from "../../renderer/processors/Animations";
|
|
4
5
|
|
|
5
6
|
// This one is needed for the deprecated useSharedValue function
|
|
6
7
|
// We can remove it once we remove the deprecation
|
|
7
|
-
|
|
8
|
+
|
|
8
9
|
let Reanimated2: any;
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
let Reanimated3: any;
|
|
11
12
|
let reanimatedVersion: string;
|
|
12
13
|
|
|
@@ -26,7 +27,7 @@ try {
|
|
|
26
27
|
export const HAS_REANIMATED2 = !!Reanimated2;
|
|
27
28
|
export const HAS_REANIMATED3 = !!Reanimated3;
|
|
28
29
|
|
|
29
|
-
function
|
|
30
|
+
export function throwOnMissingReanimated() {
|
|
30
31
|
if (!HAS_REANIMATED2) {
|
|
31
32
|
throw new Error(
|
|
32
33
|
"Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
|
|
@@ -41,17 +42,17 @@ function throwOnMissingReanimated3() {
|
|
|
41
42
|
`Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`
|
|
42
43
|
);
|
|
43
44
|
}
|
|
44
|
-
throwOnMissingReanimated2();
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export const useSharedValue =
|
|
48
48
|
Reanimated2?.useSharedValue ||
|
|
49
49
|
((value: number) => useMemo(() => ({ value }), [value]));
|
|
50
|
+
export const useFrameCallback: (...args: any[]) => any =
|
|
51
|
+
Reanimated2?.useFrameCallback || throwOnMissingReanimated;
|
|
50
52
|
|
|
51
|
-
export const startMapper =
|
|
52
|
-
|
|
53
|
-
export const
|
|
54
|
-
export const runOnJS = Reanimated2?.runOnJS || throwOnMissingReanimated2;
|
|
53
|
+
export const startMapper = Reanimated2?.startMapper || throwOnMissingReanimated;
|
|
54
|
+
export const stopMapper = Reanimated2?.stopMapper || throwOnMissingReanimated;
|
|
55
|
+
export const runOnJS = Reanimated2?.runOnJS || throwOnMissingReanimated;
|
|
55
56
|
export const isSharedValue = <T>(
|
|
56
57
|
value: unknown
|
|
57
58
|
): value is SharedValueType<T> => {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
throwOnMissingReanimated,
|
|
3
|
+
useFrameCallback,
|
|
4
|
+
useSharedValue,
|
|
5
|
+
} from "../../external/reanimated/moduleWrapper";
|
|
6
|
+
import { Skia } from "../Skia";
|
|
7
|
+
import type { DataSourceParam } from "../types";
|
|
8
|
+
|
|
9
|
+
import { useRawData } from "./Data";
|
|
10
|
+
|
|
11
|
+
const animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(
|
|
12
|
+
Skia.AnimatedImage
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns a Skia Animated Image object
|
|
17
|
+
* */
|
|
18
|
+
export const useAnimatedImage = (
|
|
19
|
+
source: DataSourceParam,
|
|
20
|
+
onError?: (err: Error) => void
|
|
21
|
+
) => useRawData(source, animatedImgFactory, onError);
|
|
22
|
+
|
|
23
|
+
const DEFAULT_FRAME_DURATION = 60;
|
|
24
|
+
|
|
25
|
+
export const useAnimatedImageValue = (source: DataSourceParam) => {
|
|
26
|
+
throwOnMissingReanimated();
|
|
27
|
+
const currentFrame = useSharedValue(null);
|
|
28
|
+
const lastTimestamp = useSharedValue(0);
|
|
29
|
+
const animatedImage = useAnimatedImage(source, (err) => {
|
|
30
|
+
console.error(err);
|
|
31
|
+
throw new Error(`Could not load animated image - got '${err.message}'`);
|
|
32
|
+
});
|
|
33
|
+
const frameDuration =
|
|
34
|
+
animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
useFrameCallback((frameInfo: any) => {
|
|
38
|
+
if (!animatedImage) {
|
|
39
|
+
currentFrame.value = null;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { timestamp } = frameInfo;
|
|
44
|
+
const elapsed = timestamp - lastTimestamp.value;
|
|
45
|
+
|
|
46
|
+
// Check if it's time to switch frames based on GIF frame duration
|
|
47
|
+
if (elapsed < frameDuration) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Update the current frame
|
|
52
|
+
animatedImage.decodeNextFrame();
|
|
53
|
+
if (currentFrame.value) {
|
|
54
|
+
currentFrame.value.dispose();
|
|
55
|
+
}
|
|
56
|
+
currentFrame.value = animatedImage.getCurrentFrame();
|
|
57
|
+
|
|
58
|
+
// Update the last timestamp
|
|
59
|
+
lastTimestamp.value = timestamp;
|
|
60
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
}, true);
|
|
62
|
+
return currentFrame;
|
|
63
|
+
};
|
package/src/skia/core/index.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SkJSIInstance } from "../JsiInstance";
|
|
2
|
+
import type { SkImage } from "../Image";
|
|
3
|
+
|
|
4
|
+
export interface SkAnimatedImage extends SkJSIInstance<"AnimatedImage"> {
|
|
5
|
+
/**
|
|
6
|
+
* Decode the next frame.
|
|
7
|
+
*
|
|
8
|
+
* If the animation is on the last frame or has hit an error, returns
|
|
9
|
+
* kFinished (-1).
|
|
10
|
+
*/
|
|
11
|
+
decodeNextFrame(): number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Returns the current frame as an SkImage. The SkImage will not change
|
|
15
|
+
* after it has been returned.
|
|
16
|
+
* If there is no current frame, null will be returned.
|
|
17
|
+
*/
|
|
18
|
+
getCurrentFrame(): SkImage | null;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* How long to display the current frame.
|
|
22
|
+
*
|
|
23
|
+
* Useful for the first frame, for which decodeNextFrame is called
|
|
24
|
+
* internally.
|
|
25
|
+
*/
|
|
26
|
+
currentFrameDuration(): number;
|
|
27
|
+
|
|
28
|
+
// TODO - add the rest of the methods from the Skia API (see SkAnimatedImage.h)
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SkData } from "../Data";
|
|
2
|
+
|
|
3
|
+
import type { SkAnimatedImage } from "./AnimatedImage";
|
|
4
|
+
|
|
5
|
+
export interface AnimatedImageFactory {
|
|
6
|
+
/**
|
|
7
|
+
* Decodes the given bytes into an animated image. Returns null if the bytes were invalid.
|
|
8
|
+
* The passed in bytes will be copied into the WASM heap, so the caller can dispose of them.
|
|
9
|
+
*
|
|
10
|
+
* The returned AnimatedImage will be "pointing to" the first frame, i.e. currentFrameDuration
|
|
11
|
+
* and makeImageAtCurrentFrame will be referring to the first frame.
|
|
12
|
+
* @param encoded
|
|
13
|
+
*/
|
|
14
|
+
MakeAnimatedImageFromEncoded: (encoded: SkData) => SkAnimatedImage | null;
|
|
15
|
+
}
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -28,6 +28,8 @@ import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
|
28
28
|
import type { PictureFactory, SkPictureRecorder } from "./Picture";
|
|
29
29
|
import type { Color, SkColor } from "./Color";
|
|
30
30
|
import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
|
|
31
|
+
import type { AnimatedImageFactory } from "./AnimatedImage";
|
|
32
|
+
|
|
31
33
|
/**
|
|
32
34
|
* Declares the interface for the native Skia API
|
|
33
35
|
*/
|
|
@@ -78,6 +80,7 @@ export interface Skia {
|
|
|
78
80
|
): SkVertices;
|
|
79
81
|
Data: DataFactory;
|
|
80
82
|
Image: ImageFactory;
|
|
83
|
+
AnimatedImage: AnimatedImageFactory;
|
|
81
84
|
SVG: SVGFactory;
|
|
82
85
|
TextBlob: TextBlobFactory;
|
|
83
86
|
Surface: SurfaceFactory;
|
package/src/skia/types/index.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AnimatedImage, CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import type { SkAnimatedImage } from "../types/AnimatedImage";
|
|
4
|
+
|
|
5
|
+
import { HostObject } from "./Host";
|
|
6
|
+
import { JsiSkImage } from "./JsiSkImage";
|
|
7
|
+
|
|
8
|
+
export class JsiSkAnimatedImage
|
|
9
|
+
extends HostObject<AnimatedImage, "AnimatedImage">
|
|
10
|
+
implements SkAnimatedImage
|
|
11
|
+
{
|
|
12
|
+
constructor(CanvasKit: CanvasKit, ref: AnimatedImage) {
|
|
13
|
+
super(CanvasKit, ref, "AnimatedImage");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
decodeNextFrame() {
|
|
17
|
+
return this.ref.decodeNextFrame();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
currentFrameDuration() {
|
|
21
|
+
return this.ref.currentFrameDuration();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getCurrentFrame() {
|
|
25
|
+
const image = this.ref.makeImageAtCurrentFrame();
|
|
26
|
+
if (image === null) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return new JsiSkImage(this.CanvasKit, image);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
dispose = () => {
|
|
33
|
+
this.ref.delete();
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import type { SkData } from "../types";
|
|
4
|
+
import type { AnimatedImageFactory } from "../types/AnimatedImage/AnimatedImageFactory";
|
|
5
|
+
|
|
6
|
+
import { Host } from "./Host";
|
|
7
|
+
import { JsiSkData } from "./JsiSkData";
|
|
8
|
+
import { JsiSkAnimatedImage } from "./JsiSkAnimatedImage";
|
|
9
|
+
|
|
10
|
+
export class JsiSkAnimatedImageFactory
|
|
11
|
+
extends Host
|
|
12
|
+
implements AnimatedImageFactory
|
|
13
|
+
{
|
|
14
|
+
constructor(CanvasKit: CanvasKit) {
|
|
15
|
+
super(CanvasKit);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
MakeAnimatedImageFromEncoded(encoded: SkData) {
|
|
19
|
+
const image = this.CanvasKit.MakeAnimatedImageFromEncoded(
|
|
20
|
+
JsiSkData.fromValue(encoded)
|
|
21
|
+
);
|
|
22
|
+
if (image === null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
return new JsiSkAnimatedImage(this.CanvasKit, image);
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -39,6 +39,7 @@ import { JsiSkPath } from "./JsiSkPath";
|
|
|
39
39
|
import { JsiSkTypeface } from "./JsiSkTypeface";
|
|
40
40
|
import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFactory";
|
|
41
41
|
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
|
42
|
+
import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
|
|
42
43
|
|
|
43
44
|
export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
44
45
|
Point: (x: number, y: number) =>
|
|
@@ -98,6 +99,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
98
99
|
MakeVertices: MakeVertices.bind(null, CanvasKit),
|
|
99
100
|
Data: new JsiSkDataFactory(CanvasKit),
|
|
100
101
|
Image: new JsiSkImageFactory(CanvasKit),
|
|
102
|
+
AnimatedImage: new JsiSkAnimatedImageFactory(CanvasKit),
|
|
101
103
|
SVG: new JsiSkSVGFactory(CanvasKit),
|
|
102
104
|
TextBlob: new JsiSkTextBlobFactory(CanvasKit),
|
|
103
105
|
XYWHRect: (x: number, y: number, width: number, height: number) => {
|