diff options
author | Hailey <me@haileyok.com> | 2024-09-04 08:06:45 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-04 08:06:45 -0700 |
commit | dee28f378a815e6518a010a293733b26ae7bed9c (patch) | |
tree | b11c1421b681d389523368b87e5b48d645178b36 /src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx | |
parent | 21e48bb2d80a5becf3ffdecb1415322e7eae3f14 (diff) | |
download | voidsky-dee28f378a815e6518a010a293733b26ae7bed9c.tar.zst |
[Video] Only allow one `VideoView` to be active at a time, regardless of source (#5131)
Diffstat (limited to 'src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx')
-rw-r--r-- | src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx b/src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx index 77616d788..bdc7967cb 100644 --- a/src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx +++ b/src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx @@ -4,8 +4,9 @@ import {useVideoPlayer, VideoPlayer} from 'expo-video' import {isNative} from '#/platform/detection' const Context = React.createContext<{ - activeSource: string | null - setActiveSource: (src: string) => void + activeSource: string + activeViewId: string | undefined + setActiveSource: (src: string, viewId: string) => void player: VideoPlayer } | null>(null) @@ -15,6 +16,7 @@ export function Provider({children}: {children: React.ReactNode}) { } const [activeSource, setActiveSource] = React.useState('') + const [activeViewId, setActiveViewId] = React.useState<string>() const player = useVideoPlayer(activeSource, p => { p.muted = true @@ -22,8 +24,19 @@ export function Provider({children}: {children: React.ReactNode}) { p.play() }) + const setActiveSourceOuter = (src: string, viewId: string) => { + setActiveSource(src) + setActiveViewId(viewId) + } + return ( - <Context.Provider value={{activeSource, setActiveSource, player}}> + <Context.Provider + value={{ + activeSource, + setActiveSource: setActiveSourceOuter, + activeViewId, + player, + }}> {children} </Context.Provider> ) |