2026-05-12 21:29:45 +08:00
|
|
|
|
import React from "react";
|
2026-03-17 22:18:05 +08:00
|
|
|
|
import {
|
|
|
|
|
|
View,
|
|
|
|
|
|
Text,
|
|
|
|
|
|
Modal,
|
|
|
|
|
|
TouchableOpacity,
|
|
|
|
|
|
Animated,
|
|
|
|
|
|
StyleSheet,
|
2026-05-12 21:29:45 +08:00
|
|
|
|
ScrollView,
|
|
|
|
|
|
useWindowDimensions,
|
2026-03-17 22:18:05 +08:00
|
|
|
|
} from "react-native";
|
|
|
|
|
|
import { Ionicons } from "@expo/vector-icons";
|
|
|
|
|
|
import { useDownload } from "../hooks/useDownload";
|
2026-03-26 00:43:37 +08:00
|
|
|
|
import { useTheme } from "../utils/theme";
|
2026-05-12 21:29:45 +08:00
|
|
|
|
import { useSheetTransition } from "../utils/useSheetTransition";
|
2026-03-17 22:18:05 +08:00
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
|
visible: boolean;
|
|
|
|
|
|
onClose: () => void;
|
2026-05-12 21:29:45 +08:00
|
|
|
|
/** Sheet 顶部对齐到屏幕的绝对 Y(一般是播放器底部) */
|
|
|
|
|
|
topOffset: number;
|
2026-03-17 22:18:05 +08:00
|
|
|
|
bvid: string;
|
|
|
|
|
|
cid: number;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
cover: string;
|
|
|
|
|
|
qualities: { qn: number; desc: string }[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function DownloadSheet({
|
|
|
|
|
|
visible,
|
|
|
|
|
|
onClose,
|
2026-05-12 21:29:45 +08:00
|
|
|
|
topOffset,
|
2026-03-17 22:18:05 +08:00
|
|
|
|
bvid,
|
|
|
|
|
|
cid,
|
|
|
|
|
|
title,
|
|
|
|
|
|
cover,
|
|
|
|
|
|
qualities,
|
|
|
|
|
|
}: Props) {
|
|
|
|
|
|
const { tasks, startDownload, taskKey } = useDownload();
|
2026-03-26 00:43:37 +08:00
|
|
|
|
const theme = useTheme();
|
2026-05-12 21:29:45 +08:00
|
|
|
|
const { height } = useWindowDimensions();
|
|
|
|
|
|
const sheetH = Math.max(120, height - topOffset);
|
|
|
|
|
|
const { rendered, slideAnim } = useSheetTransition(visible, sheetH);
|
2026-03-17 22:18:05 +08:00
|
|
|
|
|
2026-05-12 21:29:45 +08:00
|
|
|
|
if (!rendered || qualities.length === 0) return null;
|
2026-03-17 22:18:05 +08:00
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<Modal
|
2026-05-12 21:29:45 +08:00
|
|
|
|
visible
|
2026-03-17 22:18:05 +08:00
|
|
|
|
transparent
|
|
|
|
|
|
animationType="none"
|
2026-05-12 21:29:45 +08:00
|
|
|
|
statusBarTranslucent
|
2026-03-17 22:18:05 +08:00
|
|
|
|
onRequestClose={onClose}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Animated.View
|
2026-05-12 21:29:45 +08:00
|
|
|
|
style={[
|
|
|
|
|
|
styles.sheet,
|
|
|
|
|
|
{
|
|
|
|
|
|
top: topOffset,
|
|
|
|
|
|
backgroundColor: theme.sheetBg,
|
|
|
|
|
|
transform: [{ translateY: slideAnim }],
|
|
|
|
|
|
},
|
|
|
|
|
|
]}
|
2026-03-17 22:18:05 +08:00
|
|
|
|
>
|
2026-05-12 21:29:45 +08:00
|
|
|
|
<View style={[styles.header, { borderBottomColor: theme.modalBorder }]}>
|
2026-03-26 00:43:37 +08:00
|
|
|
|
<Text style={[styles.headerTitle, { color: theme.modalText }]}>下载视频</Text>
|
2026-05-12 21:29:45 +08:00
|
|
|
|
<TouchableOpacity onPress={onClose} style={styles.closeBtn} hitSlop={8}>
|
|
|
|
|
|
<Ionicons name="close" size={22} color={theme.modalTextSub} />
|
2026-03-17 22:18:05 +08:00
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
</View>
|
2026-05-12 21:29:45 +08:00
|
|
|
|
<ScrollView
|
|
|
|
|
|
contentContainerStyle={styles.body}
|
|
|
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
|
|
|
>
|
|
|
|
|
|
{qualities.map((q) => {
|
|
|
|
|
|
const key = taskKey(bvid, q.qn);
|
|
|
|
|
|
const task = tasks[key];
|
|
|
|
|
|
return (
|
|
|
|
|
|
<View
|
|
|
|
|
|
key={q.qn}
|
|
|
|
|
|
style={[styles.row, { borderBottomColor: theme.modalBorder }]}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Text style={[styles.qualityLabel, { color: theme.modalText }]}>
|
|
|
|
|
|
{q.desc}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
<View style={styles.right}>
|
|
|
|
|
|
{!task && (
|
2026-03-17 22:18:05 +08:00
|
|
|
|
<TouchableOpacity
|
2026-05-12 21:29:45 +08:00
|
|
|
|
style={styles.downloadBtn}
|
2026-03-17 22:18:05 +08:00
|
|
|
|
onPress={() =>
|
|
|
|
|
|
startDownload(bvid, cid, q.qn, q.desc, title, cover)
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
2026-05-12 21:29:45 +08:00
|
|
|
|
<Text style={styles.downloadBtnTxt}>下载</Text>
|
2026-03-17 22:18:05 +08:00
|
|
|
|
</TouchableOpacity>
|
2026-05-12 21:29:45 +08:00
|
|
|
|
)}
|
|
|
|
|
|
{task?.status === "downloading" && (
|
|
|
|
|
|
<View style={styles.progressWrap}>
|
|
|
|
|
|
<View style={styles.progressTrack}>
|
|
|
|
|
|
<View
|
|
|
|
|
|
style={[
|
|
|
|
|
|
styles.progressFill,
|
|
|
|
|
|
{
|
|
|
|
|
|
width: `${Math.round(task.progress * 100)}%` as any,
|
|
|
|
|
|
},
|
|
|
|
|
|
]}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
<Text style={[styles.progressTxt, { color: theme.modalTextSub }]}>
|
|
|
|
|
|
{Math.round(task.progress * 100)}%
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{task?.status === "done" && (
|
|
|
|
|
|
<View style={styles.doneRow}>
|
|
|
|
|
|
<Ionicons name="checkmark-circle" size={16} color="#00AEEC" />
|
|
|
|
|
|
<Text style={styles.doneTxt}>已下载</Text>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{task?.status === "error" && (
|
|
|
|
|
|
<View style={styles.errorWrap}>
|
|
|
|
|
|
{!!task.error && (
|
|
|
|
|
|
<Text style={styles.errorMsg} numberOfLines={2}>
|
|
|
|
|
|
{task.error}
|
|
|
|
|
|
</Text>
|
|
|
|
|
|
)}
|
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
|
style={styles.retryBtn}
|
|
|
|
|
|
onPress={() =>
|
|
|
|
|
|
startDownload(bvid, cid, q.qn, q.desc, title, cover)
|
|
|
|
|
|
}
|
|
|
|
|
|
>
|
|
|
|
|
|
<Ionicons name="refresh" size={14} color="#f44" />
|
|
|
|
|
|
<Text style={styles.retryTxt}>重试</Text>
|
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
</View>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</View>
|
2026-03-17 22:18:05 +08:00
|
|
|
|
</View>
|
2026-05-12 21:29:45 +08:00
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</ScrollView>
|
2026-03-17 22:18:05 +08:00
|
|
|
|
</Animated.View>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
|
|
sheet: {
|
|
|
|
|
|
position: "absolute",
|
|
|
|
|
|
left: 0,
|
|
|
|
|
|
right: 0,
|
2026-05-12 21:29:45 +08:00
|
|
|
|
bottom: 0,
|
|
|
|
|
|
borderTopLeftRadius: 12,
|
|
|
|
|
|
borderTopRightRadius: 12,
|
|
|
|
|
|
overflow: "hidden",
|
2026-03-17 22:18:05 +08:00
|
|
|
|
},
|
|
|
|
|
|
header: {
|
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
justifyContent: "space-between",
|
2026-05-12 21:29:45 +08:00
|
|
|
|
paddingHorizontal: 20,
|
|
|
|
|
|
paddingTop: 14,
|
|
|
|
|
|
paddingBottom: 10,
|
|
|
|
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
2026-03-17 22:18:05 +08:00
|
|
|
|
},
|
2026-05-12 21:29:45 +08:00
|
|
|
|
headerTitle: { fontSize: 16, fontWeight: "700" },
|
2026-03-17 22:18:05 +08:00
|
|
|
|
closeBtn: { padding: 4 },
|
2026-05-12 21:29:45 +08:00
|
|
|
|
body: { paddingHorizontal: 20, paddingBottom: 40 },
|
2026-03-17 22:18:05 +08:00
|
|
|
|
row: {
|
|
|
|
|
|
flexDirection: "row",
|
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
|
justifyContent: "space-between",
|
|
|
|
|
|
paddingVertical: 14,
|
2026-05-12 21:29:45 +08:00
|
|
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
2026-03-17 22:18:05 +08:00
|
|
|
|
},
|
2026-05-12 21:29:45 +08:00
|
|
|
|
qualityLabel: { fontSize: 15 },
|
2026-03-17 22:18:05 +08:00
|
|
|
|
right: { flexDirection: "row", alignItems: "center" },
|
|
|
|
|
|
downloadBtn: {
|
|
|
|
|
|
backgroundColor: "#00AEEC",
|
|
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
|
|
paddingVertical: 5,
|
|
|
|
|
|
borderRadius: 14,
|
|
|
|
|
|
},
|
|
|
|
|
|
downloadBtnTxt: { color: "#fff", fontSize: 13, fontWeight: "600" },
|
|
|
|
|
|
progressWrap: { flexDirection: "row", alignItems: "center", gap: 8 },
|
|
|
|
|
|
progressTrack: {
|
|
|
|
|
|
width: 80,
|
|
|
|
|
|
height: 4,
|
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
|
backgroundColor: "#e0e0e0",
|
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
|
},
|
|
|
|
|
|
progressFill: { height: 4, backgroundColor: "#00AEEC", borderRadius: 2 },
|
2026-05-12 21:29:45 +08:00
|
|
|
|
progressTxt: { fontSize: 12, minWidth: 32 },
|
2026-03-17 22:18:05 +08:00
|
|
|
|
doneRow: { flexDirection: "row", alignItems: "center", gap: 4 },
|
|
|
|
|
|
doneTxt: { fontSize: 13, color: "#00AEEC" },
|
|
|
|
|
|
errorWrap: { alignItems: "flex-end", gap: 2 },
|
|
|
|
|
|
errorMsg: { fontSize: 11, color: "#f44", maxWidth: 160, textAlign: "right" },
|
|
|
|
|
|
retryBtn: { flexDirection: "row", alignItems: "center", gap: 4 },
|
|
|
|
|
|
retryTxt: { fontSize: 13, color: "#f44" },
|
|
|
|
|
|
});
|