Skip to content

Commit

Permalink
💚
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Jun 14, 2024
1 parent 3be25d2 commit d222222
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions package/src/external/reanimated/useVideoLoading.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";

import type { Video } from "../../skia/types";
import { Skia } from "../../skia";
Expand All @@ -10,17 +10,20 @@ const runtime = Rea.createWorkletRuntime("video-metadata-runtime");
type VideoSource = string | null;

export const useVideoLoading = (source: VideoSource) => {
const runOnJS = Rea.runOnJS;
const { runOnJS } = Rea;
const [video, setVideo] = useState<Video | null>(null);
const cb = (src: string) => {
"worklet";
const vid = Skia.Video(src) as Video;
runOnJS(setVideo)(vid);
};
const cb = useCallback(
(src: string) => {
"worklet";
const vid = Skia.Video(src) as Video;
runOnJS(setVideo)(vid);
},
[runOnJS]
);
useEffect(() => {
if (source) {
Rea.runOnRuntime(runtime, cb)(source);
}
}, [source]);
}, [cb, source]);
return video;
};

0 comments on commit d222222

Please sign in to comment.