better music selection
This commit is contained in:
@@ -16,7 +16,7 @@ import Page from "../../layouts/Page";
|
|||||||
import { Routes } from "../../navigation";
|
import { Routes } from "../../navigation";
|
||||||
import { navigate } from "../../navigation/NavigationService";
|
import { navigate } from "../../navigation/NavigationService";
|
||||||
import { useUser } from "../../providers/UserDataProvider";
|
import { useUser } from "../../providers/UserDataProvider";
|
||||||
import { Style } from "../../styles";
|
import { Palette, Style } from "../../styles";
|
||||||
import { gutters, size } from "../../styles/Style";
|
import { gutters, size } from "../../styles/Style";
|
||||||
import { isWeb } from "../../hooks/useLayoutType";
|
import { isWeb } from "../../hooks/useLayoutType";
|
||||||
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
|
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
|
||||||
@@ -97,6 +97,7 @@ const SongReady = () => {
|
|||||||
}, [player0, player1]);
|
}, [player0, player1]);
|
||||||
|
|
||||||
const togglePlay = async (idx) => {
|
const togglePlay = async (idx) => {
|
||||||
|
setSelectedIndex(idx);
|
||||||
const url = musicUrls[idx];
|
const url = musicUrls[idx];
|
||||||
if (!url) return;
|
if (!url) return;
|
||||||
try {
|
try {
|
||||||
@@ -245,13 +246,29 @@ const SongReady = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={{ gap: 16 }}>
|
<View style={{ gap: 16 }}>
|
||||||
{[0, 1].map((idx) => (
|
{[0, 1].map((idx) => {
|
||||||
<BlurView
|
const isSelected = selectedIndex === idx;
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
key={idx}
|
key={idx}
|
||||||
|
onPress={() => setSelectedIndex(idx)}
|
||||||
|
style={({ pressed }) => [
|
||||||
|
{
|
||||||
|
borderRadius: 20,
|
||||||
|
borderWidth: isSelected ? 2 : 1,
|
||||||
|
borderColor: isSelected
|
||||||
|
? Palette.primary
|
||||||
|
: Palette.ultraLightWhite,
|
||||||
|
overflow: "hidden",
|
||||||
|
},
|
||||||
|
pressed && { opacity: 0.96 },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<BlurView
|
||||||
intensity={Platform.OS !== "ios" ? 10 : 40}
|
intensity={Platform.OS !== "ios" ? 10 : 40}
|
||||||
tint="dark"
|
tint="dark"
|
||||||
style={{
|
style={{
|
||||||
borderRadius: 16,
|
borderRadius: 18,
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
padding: 12,
|
padding: 12,
|
||||||
backgroundColor: "#FFFFFF0A",
|
backgroundColor: "#FFFFFF0A",
|
||||||
@@ -261,13 +278,22 @@ const SongReady = () => {
|
|||||||
// }
|
// }
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
style={{ flexDirection: "row", alignItems: "center", gap: 12 }}
|
style={{
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 12,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => togglePlay(idx)}
|
onPress={() => togglePlay(idx)}
|
||||||
style={{ ...Style.containerCenter, ...size({ size: 48 }) }}
|
style={{
|
||||||
|
...Style.containerCenter,
|
||||||
|
...size({ size: 48 }),
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Image source={isPlaying[idx] ? icons.pause : icons.play} />
|
<Image
|
||||||
|
source={isPlaying[idx] ? icons.pause : icons.play}
|
||||||
|
/>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<Text
|
<Text
|
||||||
@@ -281,14 +307,17 @@ const SongReady = () => {
|
|||||||
maxValue={fmt(progressInfo[idx]?.dur)}
|
maxValue={fmt(progressInfo[idx]?.dur)}
|
||||||
progress={
|
progress={
|
||||||
progressInfo[idx]?.dur
|
progressInfo[idx]?.dur
|
||||||
? (progressInfo[idx].pos || 0) / progressInfo[idx].dur
|
? (progressInfo[idx].pos || 0) /
|
||||||
|
progressInfo[idx].dur
|
||||||
: 0
|
: 0
|
||||||
}
|
}
|
||||||
seekEnabled={!!musicUrls[idx]}
|
seekEnabled={!!musicUrls[idx]}
|
||||||
onSeekStart={async () => {
|
onSeekStart={async () => {
|
||||||
|
setSelectedIndex(idx);
|
||||||
try {
|
try {
|
||||||
const player = idx === 0 ? player0 : player1;
|
const player = idx === 0 ? player0 : player1;
|
||||||
wasPlayingBeforeSeek.current[idx] = !!player?.playing;
|
wasPlayingBeforeSeek.current[idx] =
|
||||||
|
!!player?.playing;
|
||||||
if (player?.playing) {
|
if (player?.playing) {
|
||||||
await player.pause?.();
|
await player.pause?.();
|
||||||
setIsPlaying((p) => ({ ...p, [idx]: false }));
|
setIsPlaying((p) => ({ ...p, [idx]: false }));
|
||||||
@@ -310,14 +339,20 @@ const SongReady = () => {
|
|||||||
}
|
}
|
||||||
wasPlayingBeforeSeek.current[idx] = false;
|
wasPlayingBeforeSeek.current[idx] = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("SongReady resume after seek", e?.message);
|
console.log(
|
||||||
|
"SongReady resume after seek",
|
||||||
|
e?.message
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={() => setSelectedIndex(idx)}
|
onPress={() => setSelectedIndex(idx)}
|
||||||
style={{ ...Style.containerCenter, ...size({ size: 24 }) }}
|
style={{
|
||||||
|
...Style.containerCenter,
|
||||||
|
...size({ size: 24 }),
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
@@ -325,18 +360,20 @@ const SongReady = () => {
|
|||||||
height: 18,
|
height: 18,
|
||||||
borderRadius: 9,
|
borderRadius: 9,
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
borderColor: "white",
|
borderColor: isSelected
|
||||||
|
? Palette.primary
|
||||||
|
: "white",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{selectedIndex === idx && (
|
{isSelected && (
|
||||||
<View
|
<View
|
||||||
style={{
|
style={{
|
||||||
width: 10,
|
width: 10,
|
||||||
height: 10,
|
height: 10,
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
backgroundColor: "white",
|
backgroundColor: Palette.primary,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -344,7 +381,9 @@ const SongReady = () => {
|
|||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
</BlurView>
|
</BlurView>
|
||||||
))}
|
</Pressable>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View
|
<View
|
||||||
|
|||||||
Reference in New Issue
Block a user