From dee28f378a815e6518a010a293733b26ae7bed9c Mon Sep 17 00:00:00 2001
From: Hailey <me@haileyok.com>
Date: Wed, 4 Sep 2024 08:06:45 -0700
Subject: [Video] Only allow one `VideoView` to be active at a time, regardless
 of source (#5131)

---
 .../com/util/post-embeds/ActiveVideoNativeContext.tsx | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

(limited to 'src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx')

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>
   )
-- 
cgit 1.4.1

