From d459e4032d1f1d330a2eac8abe62ca4b06bbc557 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Wed, 15 Jan 2025 14:35:25 +0000 Subject: [PATCH] right swipe --- bskyweb/cmd/bskyweb/server.go | 2 +- src/Navigation.tsx | 11 +- src/components/FeedInterstitials.tsx | 2 +- src/lib/constants.ts | 2 +- src/lib/routes/types.ts | 2 +- src/routes.ts | 2 +- .../Feeds/{YoloScreen.tsx => VibeScreen.tsx} | 164 +++++++++++++----- src/view/com/posts/PostFeed.tsx | 4 +- 8 files changed, 133 insertions(+), 56 deletions(-) rename src/screens/Feeds/{YoloScreen.tsx => VibeScreen.tsx} (51%) diff --git a/bskyweb/cmd/bskyweb/server.go b/bskyweb/cmd/bskyweb/server.go index 5febbc9d05..12ba3a15eb 100644 --- a/bskyweb/cmd/bskyweb/server.go +++ b/bskyweb/cmd/bskyweb/server.go @@ -273,7 +273,7 @@ func serve(cctx *cli.Context) error { e.GET("/messages/:conversation", server.WebGeneric) // temp - e.GET("/temp-yolo", server.WebGeneric) + e.GET("/temp-vibe", server.WebGeneric) // profile endpoints; only first populates info e.GET("/profile/:handleOrDID", server.WebProfile) diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 494f0148f2..acb8d7fc46 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -89,7 +89,7 @@ import {Wizard} from '#/screens/StarterPack/Wizard' import {useTheme} from '#/alf' import {router} from '#/routes' import {Referrer} from '../modules/expo-bluesky-swiss-army' -import {YoloScreen} from './screens/Feeds/YoloScreen' +import {VibeScreen} from './screens/Feeds/VibeScreen' import {AboutSettingsScreen} from './screens/Settings/AboutSettings' import {AccessibilitySettingsScreen} from './screens/Settings/AccessibilitySettings' import {AccountSettingsScreen} from './screens/Settings/AccountSettings' @@ -424,9 +424,12 @@ function commonScreens(Stack: typeof HomeTab, unreadCountLabel?: string) { options={{title: title(msg`Edit your starter pack`), requireAuth: true}} /> YoloScreen} - options={{title: title(msg`Yolo mode`), requireAuth: true}} + name="TempVibe" + getComponent={() => VibeScreen} + options={{ + title: title(msg`Vibe`), + requireAuth: true, + }} /> ) diff --git a/src/components/FeedInterstitials.tsx b/src/components/FeedInterstitials.tsx index 83a732f4c3..fb12706a35 100644 --- a/src/components/FeedInterstitials.tsx +++ b/src/components/FeedInterstitials.tsx @@ -538,7 +538,7 @@ export function VideoModeEntranceInterstitial() { -export function YoloScreen({}: Props) { +type Props = NativeStackScreenProps +export function VibeScreen({}: Props) { const {top} = useSafeAreaInsets() - const t = useTheme() const [headerHeight, setHeaderHeight] = useState(0) const setMinShellMode = useSetMinimalShellMode() @@ -40,37 +47,41 @@ export function YoloScreen({}: Props) { }, [setMinShellMode]), ) + useSetLightStatusBar(true) + return ( - - - setHeaderHeight(nativeEvent.layout.height) - }> - - - - - Yolo mode - - - - - - - + + + + setHeaderHeight(nativeEvent.layout.height) + }> + + + + + {/* TODO: needs to be feed name */} + Vibes (wip) + + + + + + + + ) } function YoloFeed({headerHeight}: {headerHeight: number}) { + const isFocused = useIsFocused() const { data, isFetching, @@ -78,7 +89,7 @@ function YoloFeed({headerHeight}: {headerHeight: number}) { hasNextPage, isFetchingNextPage, fetchNextPage, - } = usePostFeedQuery(`feedgen|${THEVIDS_FEED_URI}`) + } = usePostFeedQuery(`feedgen|${VIBES_FEED_URI}`) const player1 = useVideoPlayer('', p => { p.loop = true @@ -106,17 +117,17 @@ function YoloFeed({headerHeight}: {headerHeight: number}) { const player = [player1, player2, player3][index % 3] return ( - ) }, - [player1, player2, player3, currentIndex, headerHeight], + [player1, player2, player3, currentIndex, headerHeight, isFocused], ) const onViewableItemsChanged = useCallback( @@ -159,7 +170,7 @@ function keyExtractor(item: FeedPostSliceItem) { return item._reactKey } -function VideoScreen({ +function VibeItem({ player, embed, active, @@ -181,17 +192,34 @@ function VideoScreen({ oldSource: {uri?: string} } + // for initial video - useEffect will handle the typical case where + // videos have a chance to preload + const maybePlay = useNonReactiveCallback(() => { + if (active && !player.playing) { + console.log('play (nonreactive)') + player.play() + } + }) + useEffect(() => { if (loaded && sourceChangeEvent?.source?.uri !== source) { player.replace(source) + // play next tick + const timeout = setTimeout(() => { + maybePlay() + }, 0) + return () => { + clearTimeout(timeout) + } } - }, [sourceChangeEvent?.source?.uri, loaded, source, player]) + }, [sourceChangeEvent?.source?.uri, loaded, source, player, maybePlay]) useEffect(() => { if (active) { + console.log('play (effect)') player.play() - } - return () => { + } else { + // should be a cleanup function, but that causes a crash player.pause() } }, [active, player]) @@ -202,7 +230,9 @@ function VideoScreen({ height, width, }}> - + {active && ( )} + ) } + +function VibeOverlay({player}: {player: VideoPlayer}) { + const navigation = useNavigation() + const pushToProfile = useNonReactiveCallback(() => { + navigation.navigate('Profile', {name: 'lulaoficial.bsky.social'}) + }) + + const togglePlayPause = () => { + if (player.playing) { + player.pause() + } else { + player.play() + } + } + + const gesture = useMemo(() => { + const dragLeftGesture = Gesture.Pan() + .onEnd(evt => { + 'worklet' + if (evt.translationX < -100) { + runOnJS(pushToProfile)() + } + }) + .activeOffsetX([-10, 10]) + .failOffsetY([-10, 10]) + .maxPointers(1) + + return dragLeftGesture + }, [pushToProfile]) + + return ( + + + + + + ) +} diff --git a/src/view/com/posts/PostFeed.tsx b/src/view/com/posts/PostFeed.tsx index e2cae4d9bd..a06230fd68 100644 --- a/src/view/com/posts/PostFeed.tsx +++ b/src/view/com/posts/PostFeed.tsx @@ -17,7 +17,7 @@ import {useQueryClient} from '@tanstack/react-query' import { DISCOVER_FEED_URI, KNOWN_SHUTDOWN_FEEDS, - THEVIDS_FEED_URI, + VIBES_FEED_URI, } from '#/lib/constants' import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender' import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' @@ -287,7 +287,7 @@ let PostFeed = ({ feedKind = 'following' } else if (feedUri === DISCOVER_FEED_URI) { feedKind = 'discover' - } else if (feedUri === THEVIDS_FEED_URI) { + } else if (feedUri === VIBES_FEED_URI) { feedKind = 'thevids' } else if ( feedType === 'author' &&