Skip to content

Commit

Permalink
Merge branch 'main' into new-sksg
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Jan 7, 2025
2 parents 4351a88 + a78b255 commit 73fa371
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
19 changes: 4 additions & 15 deletions packages/skia/src/external/reanimated/useAnimatedImageValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useEffect } from "react";
import type { FrameInfo, SharedValue } from "react-native-reanimated";

import { useAnimatedImage } from "../../skia/core/AnimatedImage";
Expand All @@ -16,14 +15,10 @@ export const useAnimatedImageValue = (
const isPaused = paused ?? defaultPaused;
const currentFrame = Rea.useSharedValue<null | SkImage>(null);
const lastTimestamp = Rea.useSharedValue(-1);
const animatedImage = useAnimatedImage(
source,
(err) => {
console.error(err);
throw new Error(`Could not load animated image - got '${err.message}'`);
},
false
);
const animatedImage = useAnimatedImage(source, (err) => {
console.error(err);
throw new Error(`Could not load animated image - got '${err.message}'`);
});
const frameDuration =
animatedImage?.currentFrameDuration() || DEFAULT_FRAME_DURATION;

Expand Down Expand Up @@ -53,11 +48,5 @@ export const useAnimatedImageValue = (
// Update the last timestamp
lastTimestamp.value = timestamp;
});
useEffect(() => {
return () => {
animatedImage?.dispose();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return currentFrame;
};
5 changes: 2 additions & 3 deletions packages/skia/src/skia/core/AnimatedImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ const animatedImgFactory = Skia.AnimatedImage.MakeAnimatedImageFromEncoded.bind(
* */
export const useAnimatedImage = (
source: DataSourceParam,
onError?: (err: Error) => void,
managed = true
) => useRawData(source, animatedImgFactory, onError, managed);
onError?: (err: Error) => void
) => useRawData(source, animatedImgFactory, onError);
13 changes: 3 additions & 10 deletions packages/skia/src/skia/core/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export const loadData = <T>(

const useLoading = <T extends SkJSIInstance<string>>(
source: DataSourceParam,
loader: () => Promise<T | null>,
manage = true
loader: () => Promise<T | null>
) => {
const mounted = useRef(false);
const [data, setData] = useState<T | null>(null);
Expand All @@ -55,10 +54,6 @@ const useLoading = <T extends SkJSIInstance<string>>(
}
});
return () => {
if (manage) {
console.log("dispose!");
dataRef.current?.dispose();
}
mounted.current = false;
};
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -85,7 +80,6 @@ export const useCollectionLoading = <T extends SkJSIInstance<string>>(
});

return () => {
dataRef.current?.forEach((instance) => instance?.dispose());
mounted.current = false;
};

Expand All @@ -98,9 +92,8 @@ export const useCollectionLoading = <T extends SkJSIInstance<string>>(
export const useRawData = <T extends SkJSIInstance<string>>(
source: DataSourceParam,
factory: (data: SkData) => T | null,
onError?: (err: Error) => void,
manage = true
) => useLoading(source, () => loadData<T>(source, factory, onError), manage);
onError?: (err: Error) => void
) => useLoading(source, () => loadData<T>(source, factory, onError));

const identity = (data: SkData) => data;

Expand Down

0 comments on commit 73fa371

Please sign in to comment.