Cleanup source handling

This commit is contained in:
2026-04-10 19:20:45 +02:00
parent 7a5f495b39
commit fd40915bc9
26 changed files with 415 additions and 450 deletions
+18 -9
View File
@@ -1,10 +1,9 @@
import { createContext, type ReactNode, useContext } from "react";
import { createContext, type ReactNode, useContext, useEffect } from "react";
import { NitroModules } from "react-native-nitro-modules";
import type {
OmniPlayerFactory,
OmniPlayerProps,
} from "./specs/omni-player.nitro";
import type { OmniPlayerFactory } from "./specs/omni-player.nitro";
import type { OmniPlayer } from "./types/player";
import type { Source } from "./types/source";
import { useLazyRef } from "./utils/lazy-ref";
const ProviderFactory = NitroModules.createHybridObject<OmniPlayerFactory>(
"OmniProviderFactory",
@@ -14,10 +13,20 @@ const PlayerCtx = createContext<OmniPlayer>(null!);
export const OmniProvider = ({
children,
...props
}: OmniPlayerProps & { children: ReactNode }) => {
const player = ProviderFactory.createPlayer(props);
return <PlayerCtx.Provider value={player}>{children}</PlayerCtx.Provider>;
source,
}: {
source: Source;
children: ReactNode;
}) => {
const player = useLazyRef(() => ProviderFactory.createPlayer(source));
useEffect(() => {
player.current.source = source;
}, [source]);
return (
<PlayerCtx.Provider value={player.current}>{children}</PlayerCtx.Provider>
);
};
export const usePlayer = () => {