rm blurview, cover for tall videos

This commit is contained in:
Samuel Newman
2025-01-15 22:45:27 +00:00
committed by Eric Bailey
parent c9953c72b0
commit 9bf91ce316
+21 -23
View File
@@ -11,7 +11,6 @@ import {Gesture, GestureDetector} from 'react-native-gesture-handler'
import {runOnJS} from 'react-native-reanimated' import {runOnJS} from 'react-native-reanimated'
import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context' import {SafeAreaView, useSafeAreaInsets} from 'react-native-safe-area-context'
import {useEvent} from 'expo' import {useEvent} from 'expo'
import {BlurView} from 'expo-blur'
import {LinearGradient} from 'expo-linear-gradient' import {LinearGradient} from 'expo-linear-gradient'
import {useVideoPlayer, VideoPlayer, VideoView} from 'expo-video' import {useVideoPlayer, VideoPlayer, VideoView} from 'expo-video'
import { import {
@@ -52,7 +51,6 @@ import {Text} from '#/components/Typography'
type Props = NativeStackScreenProps<CommonNavigatorParams, 'TempVibe'> type Props = NativeStackScreenProps<CommonNavigatorParams, 'TempVibe'>
export function VibeScreen({}: Props) { export function VibeScreen({}: Props) {
const {top} = useSafeAreaInsets() const {top} = useSafeAreaInsets()
const [headerHeight, setHeaderHeight] = useState(0)
const setMinShellMode = useSetMinimalShellMode() const setMinShellMode = useSetMinimalShellMode()
useFocusEffect( useFocusEffect(
@@ -69,18 +67,13 @@ export function VibeScreen({}: Props) {
return ( return (
<ThemeProvider theme="dark"> <ThemeProvider theme="dark">
<Layout.Screen noInsetTop style={{backgroundColor: 'black'}}> <Layout.Screen noInsetTop style={{backgroundColor: 'black'}}>
<BlurView <View
intensity={25}
tint="systemThinMaterialDark"
style={[ style={[
a.absolute, a.absolute,
a.z_10, a.z_10,
{top: 0, left: 0, right: 0, paddingTop: top}, {top: 0, left: 0, right: 0, paddingTop: top},
]} ]}>
onLayout={({nativeEvent}) => <Layout.Header.Outer noBottomBorder>
setHeaderHeight(nativeEvent.layout.height)
}>
<Layout.Header.Outer>
<Layout.Header.BackButton /> <Layout.Header.BackButton />
<Layout.Header.Content> <Layout.Header.Content>
<Layout.Header.TitleText> <Layout.Header.TitleText>
@@ -90,14 +83,14 @@ export function VibeScreen({}: Props) {
</Layout.Header.Content> </Layout.Header.Content>
<Layout.Header.Slot /> <Layout.Header.Slot />
</Layout.Header.Outer> </Layout.Header.Outer>
</BlurView> </View>
<YoloFeed headerHeight={headerHeight} /> <YoloFeed />
</Layout.Screen> </Layout.Screen>
</ThemeProvider> </ThemeProvider>
) )
} }
function YoloFeed({headerHeight}: {headerHeight: number}) { function YoloFeed() {
const isFocused = useIsFocused() const isFocused = useIsFocused()
const { const {
data, data,
@@ -140,11 +133,10 @@ function YoloFeed({headerHeight}: {headerHeight: number}) {
embed={post.embed} embed={post.embed}
loaded={isFocused && Math.abs(index - currentIndex) < 2} loaded={isFocused && Math.abs(index - currentIndex) < 2}
active={isFocused && index === currentIndex} active={isFocused && index === currentIndex}
headerHeight={headerHeight}
/> />
) )
}, },
[player1, player2, player3, currentIndex, headerHeight, isFocused], [player1, player2, player3, currentIndex, isFocused],
) )
const onViewableItemsChanged = useCallback( const onViewableItemsChanged = useCallback(
@@ -193,16 +185,15 @@ function VibeItem({
embed, embed,
active, active,
loaded, loaded,
headerHeight,
}: { }: {
player: VideoPlayer player: VideoPlayer
post: AppBskyFeedDefs.PostView post: AppBskyFeedDefs.PostView
embed: AppBskyEmbedVideo.View embed: AppBskyEmbedVideo.View
active: boolean active: boolean
loaded: boolean loaded: boolean
headerHeight: number
}) { }) {
const {height, width} = useWindowDimensions() const {height, width} = useWindowDimensions()
const insets = useSafeAreaInsets()
const source = embed.playlist const source = embed.playlist
const sourceChangeEvent = useEvent(player, 'sourceChange') as { const sourceChangeEvent = useEvent(player, 'sourceChange') as {
// incorrect types // incorrect types
@@ -214,7 +205,6 @@ function VibeItem({
// videos have a chance to preload // videos have a chance to preload
const maybePlay = useNonReactiveCallback(() => { const maybePlay = useNonReactiveCallback(() => {
if (active && !player.playing) { if (active && !player.playing) {
console.log('play (nonreactive)')
player.play() player.play()
} }
}) })
@@ -234,7 +224,6 @@ function VibeItem({
useEffect(() => { useEffect(() => {
if (active) { if (active) {
console.log('play (effect)')
player.play() player.play()
} else { } else {
// should be a cleanup function, but that causes a crash // should be a cleanup function, but that causes a crash
@@ -242,20 +231,29 @@ function VibeItem({
} }
}, [active, player]) }, [active, player])
const screenAspectRatio =
(width - insets.left - insets.right) / (height - insets.bottom)
const videoAspectRatio =
(embed.aspectRatio?.width ?? 1) / (embed.aspectRatio?.height ?? 1)
// if the video is either taller, on only 20% shorter than the screen,
// set the video to be cover rather than contain
const isCloseEnough = videoAspectRatio < screenAspectRatio * 1.2
return ( return (
<View <View
style={{ style={{
height, height,
width, width,
}}> }}>
<SafeAreaView <SafeAreaView edges={['left', 'right', 'bottom']} style={[a.flex_1]}>
edges={['left', 'right', 'bottom']} {loaded && (
style={[a.flex_1, {paddingTop: headerHeight}]}>
{active && (
<VideoView <VideoView
style={[a.flex_1]} style={[a.flex_1]}
player={player} player={player}
nativeControls={false} nativeControls={false}
contentFit={isCloseEnough ? 'cover' : 'contain'}
/> />
)} )}
<VibeOverlay player={player} post={post} /> <VibeOverlay player={player} post={post} />