navigate to playback

This commit is contained in:
2025-09-03 16:41:15 +02:00
parent 482dd3f964
commit 65dcf15006
2 changed files with 38 additions and 10 deletions
+13 -9
View File
@@ -1,5 +1,7 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { FlatList, Image, Text, View, useWindowDimensions } from "react-native"; import { FlatList, Image, Pressable, Text, View, useWindowDimensions } from "react-native";
import { Routes } from "../../../navigation";
import { navigate } from "../../../navigation/NavigationService";
import { useUserData } from "../../../providers/UserDataProvider"; import { useUserData } from "../../../providers/UserDataProvider";
import { Style } from "../../../styles"; import { Style } from "../../../styles";
import CardContainer from "./CardContainer"; import CardContainer from "./CardContainer";
@@ -28,14 +30,16 @@ const BackTracks = () => {
keyExtractor={(item) => item.id} keyExtractor={(item) => item.id}
renderItem={({ item }) => ( renderItem={({ item }) => (
<View style={{ width: itemWidth }} key={item.id}> <View style={{ width: itemWidth }} key={item.id}>
<Image <Pressable onPress={() => navigate(Routes.Playbacks, { projectId: item.id })}>
source={{ uri: item.coverUrl || "" }} <Image
style={{ source={{ uri: item.coverUrl || "" }}
width: "100%", style={{
height: Math.round((itemWidth * 16) / 9), width: "100%",
borderRadius: 10, height: Math.round((itemWidth * 16) / 9),
}} borderRadius: 10,
/> }}
/>
</Pressable>
</View> </View>
)} )}
/> />
+25 -1
View File
@@ -1,4 +1,4 @@
import { useIsFocused } from "@react-navigation/native"; import { useIsFocused, useRoute } from "@react-navigation/native";
import { useAudioPlayer } from "expo-audio"; import { useAudioPlayer } from "expo-audio";
import { BlurView } from "expo-blur"; import { BlurView } from "expo-blur";
import { VideoView, useVideoPlayer } from "expo-video"; import { VideoView, useVideoPlayer } from "expo-video";
@@ -422,6 +422,9 @@ const PlaybackItem = ({ item, isActive, userCache, getUserByUid }) => {
const Playbacks = () => { const Playbacks = () => {
const [activeIndex, setActiveIndex] = useState(0); const [activeIndex, setActiveIndex] = useState(0);
const carouselRef = useRef(null);
const route = useRoute();
const focusProjectId = route?.params?.projectId || route?.params?.focusId || null;
const userCache = useRef(new Map()); const userCache = useRef(new Map());
const { getUserByUid } = useUser() || {}; const { getUserByUid } = useUser() || {};
const isFocused = useIsFocused(); const isFocused = useIsFocused();
@@ -444,9 +447,30 @@ const Playbacks = () => {
[playbacks?.length, loadMore] [playbacks?.length, loadMore]
); );
// When a specific playback id is provided via navigation params,
// try to focus it by scrolling the carousel to its index.
const triedLoadMoreRef = useRef(0);
useEffect(() => {
if (!focusProjectId) return;
const idx = playbacks.findIndex((p) => p?.id === focusProjectId);
if (idx >= 0) {
setActiveIndex(idx);
// give time for first render before scrolling
setTimeout(() => {
try {
carouselRef.current?.scrollTo?.({ index: idx, animated: false });
} catch (e) {}
}, 50);
} else if (loadMore && triedLoadMoreRef.current < 6) {
triedLoadMoreRef.current += 1;
loadMore();
}
}, [focusProjectId, playbacks, loadMore]);
return ( return (
<View style={{ flex: 1, backgroundColor: "black" }}> <View style={{ flex: 1, backgroundColor: "black" }}>
<Carousel <Carousel
ref={carouselRef}
data={playbacks} data={playbacks}
vertical vertical
height={responsiveHeight(100)} height={responsiveHeight(100)}