diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-07-25 20:41:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 20:41:50 +0100 |
commit | 00240b95b90847f6691f7fa19c19f37d2ffc6624 (patch) | |
tree | b543a07196f55db11a3eb1dc30cb604b2ce28ff6 /src/view/com/util/post-embeds/ActiveVideoContext.tsx | |
parent | 4ec999cab7104a381c8c7a3202ebb2d01599a513 (diff) | |
download | voidsky-00240b95b90847f6691f7fa19c19f37d2ffc6624.tar.zst |
* add ffmpeg-kit-react-native * get select video button + compression working * up res to 1080p * add progress component * move logic out of compressVideo * (WIP) add lonestar compression * rework web compression a bit * mess around with adding a thumbnail * 3mbps * replace * use 3mbps * add expo-video * remove unnecessary try/catch * rm ToastAndroid * fix web * wrap lazy component in suspense * gate video select button * rm web compression * flip sign * remove expo-video from web * review nits * add video picker permissions + rm temp buttons * add ffmpeg-kit-react-native * replace * hls-capable player * start trying to hoist up video player instance * hoist video player and move things around * always show native controls * fix controls on expo video android * gate temp video player in feed * rm IS_DEV, doesn't do what I thought it did * use __DEV__ instead --------- Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com> Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'src/view/com/util/post-embeds/ActiveVideoContext.tsx')
-rw-r--r-- | src/view/com/util/post-embeds/ActiveVideoContext.tsx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/view/com/util/post-embeds/ActiveVideoContext.tsx b/src/view/com/util/post-embeds/ActiveVideoContext.tsx new file mode 100644 index 000000000..6804436a7 --- /dev/null +++ b/src/view/com/util/post-embeds/ActiveVideoContext.tsx @@ -0,0 +1,48 @@ +import React, {useCallback, useId, useMemo, useState} from 'react' + +import {VideoPlayerProvider} from './VideoPlayerContext' + +const ActiveVideoContext = React.createContext<{ + activeViewId: string | null + setActiveView: (viewId: string, src: string) => void +} | null>(null) + +export function ActiveVideoProvider({children}: {children: React.ReactNode}) { + const [activeViewId, setActiveViewId] = useState<string | null>(null) + const [source, setSource] = useState<string | null>(null) + + const value = useMemo( + () => ({ + activeViewId, + setActiveView: (viewId: string, src: string) => { + setActiveViewId(viewId) + setSource(src) + }, + }), + [activeViewId], + ) + + return ( + <ActiveVideoContext.Provider value={value}> + <VideoPlayerProvider source={source ?? ''} viewId={activeViewId}> + {children} + </VideoPlayerProvider> + </ActiveVideoContext.Provider> + ) +} + +export function useActiveVideoView() { + const context = React.useContext(ActiveVideoContext) + if (!context) { + throw new Error('useActiveVideo must be used within a ActiveVideoProvider') + } + const id = useId() + + return { + active: context.activeViewId === id, + setActive: useCallback( + (source: string) => context.setActiveView(id, source), + [context, id], + ), + } +} |