Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Video] Handle push/pop on Android for autoplay (#5194)

authored by

Hailey and committed by
GitHub
7e4f8cab 00ce9589

+45 -7
+1 -1
package.json
··· 139 139 "expo-system-ui": "~3.0.4", 140 140 "expo-task-manager": "~11.8.1", 141 141 "expo-updates": "~0.25.14", 142 - "expo-video": "https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4-1.tgz", 142 + "expo-video": "https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4-2.tgz", 143 143 "expo-web-browser": "~13.0.3", 144 144 "fast-text-encoding": "^1.0.6", 145 145 "history": "^5.3.0",
+13 -2
src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx
··· 1 1 import React from 'react' 2 2 import {useVideoPlayer, VideoPlayer} from 'expo-video' 3 3 4 - import {isNative} from '#/platform/detection' 4 + import {isAndroid, isNative} from '#/platform/detection' 5 5 6 6 const Context = React.createContext<{ 7 7 activeSource: string ··· 26 26 }) 27 27 28 28 const setActiveSourceOuter = (src: string | null, viewId: string | null) => { 29 - setActiveSource(src ? src : '') 29 + // HACK 30 + // expo-video doesn't like it when you try and move a `player` to another `VideoView`. Instead, we need to actually 31 + // unregister that player to let the new screen register it. This is only a problem on Android, so we only need to 32 + // apply it there. 33 + if (src === activeSource && isAndroid) { 34 + setActiveSource('') 35 + setTimeout(() => { 36 + setActiveSource(src ? src : '') 37 + }, 100) 38 + } else { 39 + setActiveSource(src ? src : '') 40 + } 30 41 setActiveViewId(viewId ? viewId : '') 31 42 } 32 43
+1 -1
src/view/com/util/post-embeds/VideoEmbed.tsx
··· 71 71 72 72 const [playerStatus, setPlayerStatus] = useState< 73 73 VideoPlayerStatus | 'paused' 74 - >(player.playing ? 'readyToPlay' : 'paused') 74 + >('paused') 75 75 const [isMuted, setIsMuted] = useState(player.muted) 76 76 const [isFullscreen, setIsFullscreen] = React.useState(false) 77 77 const [timeRemaining, setTimeRemaining] = React.useState(0)
+4
src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
··· 8 8 9 9 import {HITSLOP_30} from '#/lib/constants' 10 10 import {clamp} from '#/lib/numbers' 11 + import {isAndroid} from 'platform/detection' 11 12 import {useActiveVideoNative} from 'view/com/util/post-embeds/ActiveVideoNativeContext' 12 13 import {atoms as a, useTheme} from '#/alf' 13 14 import {Mute_Stroke2_Corner0_Rounded as MuteIcon} from '#/components/icons/Mute' ··· 61 62 PlatformInfo.setAudioActive(true) 62 63 player.muted = false 63 64 setIsFullscreen(true) 65 + if (isAndroid) { 66 + player.play() 67 + } 64 68 }} 65 69 onFullscreenExit={() => { 66 70 PlatformInfo.setAudioCategory(AudioCategory.Ambient)
+24 -1
src/view/shell/index.tsx
··· 11 11 import {useSafeAreaInsets} from 'react-native-safe-area-context' 12 12 import * as NavigationBar from 'expo-navigation-bar' 13 13 import {StatusBar} from 'expo-status-bar' 14 - import {useNavigationState} from '@react-navigation/native' 14 + import {useNavigation, useNavigationState} from '@react-navigation/native' 15 15 16 16 import {useSession} from '#/state/session' 17 17 import { ··· 20 20 useSetDrawerOpen, 21 21 } from '#/state/shell' 22 22 import {useCloseAnyActiveElement} from '#/state/util' 23 + import {useDedupe} from 'lib/hooks/useDedupe' 23 24 import {useNotificationsHandler} from 'lib/hooks/useNotificationHandler' 24 25 import {usePalette} from 'lib/hooks/usePalette' 25 26 import {useNotificationsRegistration} from 'lib/notifications/notifications' ··· 33 34 import {MutedWordsDialog} from '#/components/dialogs/MutedWords' 34 35 import {SigninDialog} from '#/components/dialogs/Signin' 35 36 import {Outlet as PortalOutlet} from '#/components/Portal' 37 + import {updateActiveViewAsync} from '../../../modules/expo-bluesky-swiss-army/src/VisibilityView' 36 38 import {RoutesContainer, TabsNavigator} from '../../Navigation' 37 39 import {Composer} from './Composer' 38 40 import {DrawerContent} from './Drawer' ··· 75 77 listener.remove() 76 78 } 77 79 }, [closeAnyActiveElement]) 80 + 81 + // HACK 82 + // expo-video doesn't like it when you try and move a `player` to another `VideoView`. Instead, we need to actually 83 + // unregister that player to let the new screen register it. This is only a problem on Android, so we only need to 84 + // apply it there. 85 + // The `state` event should only fire whenever we push or pop to a screen, and should not fire consecutively quickly. 86 + // To be certain though, we will also dedupe these calls. 87 + const navigation = useNavigation() 88 + const dedupe = useDedupe(1000) 89 + React.useEffect(() => { 90 + if (!isAndroid) return 91 + const onFocusOrBlur = () => { 92 + setTimeout(() => { 93 + dedupe(updateActiveViewAsync) 94 + }, 500) 95 + } 96 + navigation.addListener('state', onFocusOrBlur) 97 + return () => { 98 + navigation.removeListener('state', onFocusOrBlur) 99 + } 100 + }, [dedupe, navigation]) 78 101 79 102 return ( 80 103 <>
+2 -2
yarn.lock
··· 12414 12414 ignore "^5.3.1" 12415 12415 resolve-from "^5.0.0" 12416 12416 12417 - "expo-video@https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4-1.tgz": 12417 + "expo-video@https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4-2.tgz": 12418 12418 version "1.2.4" 12419 - resolved "https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4-1.tgz#57f61a72f41b86e5a587d9782d32bd32487a551e" 12419 + resolved "https://github.com/bluesky-social/expo/raw/expo-video-1.2.4-patch/packages/expo-video/expo-video-v1.2.4-2.tgz#4127dd5cea5fdf7ab745104c73b8ecf5506f5d34" 12420 12420 12421 12421 expo-web-browser@~13.0.3: 12422 12422 version "13.0.3"