navigate to playback
This commit is contained in:
@@ -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,6 +30,7 @@ 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}>
|
||||||
|
<Pressable onPress={() => navigate(Routes.Playbacks, { projectId: item.id })}>
|
||||||
<Image
|
<Image
|
||||||
source={{ uri: item.coverUrl || "" }}
|
source={{ uri: item.coverUrl || "" }}
|
||||||
style={{
|
style={{
|
||||||
@@ -36,6 +39,7 @@ const BackTracks = () => {
|
|||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -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)}
|
||||||
|
|||||||
Reference in New Issue
Block a user