mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
Create types for player & view
This commit is contained in:
Executable
+25
@@ -0,0 +1,25 @@
|
||||
import { createContext, type ReactNode, useContext } from "react";
|
||||
import { NitroModules } from "react-native-nitro-modules";
|
||||
import type {
|
||||
OmniPlayerFactory,
|
||||
OmniPlayerProps,
|
||||
} from "./specs/omni-player.nitro";
|
||||
import type { OmniPlayer } from "./types/player";
|
||||
|
||||
const ProviderFactory = NitroModules.createHybridObject<OmniPlayerFactory>(
|
||||
"OmniProviderFactory",
|
||||
);
|
||||
|
||||
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>;
|
||||
};
|
||||
|
||||
export const usePlayer = () => {
|
||||
return useContext(PlayerCtx);
|
||||
};
|
||||
Reference in New Issue
Block a user