Files
JKVideo/components/LiveCard.tsx

156 lines
3.9 KiB
TypeScript
Raw Permalink Normal View History

2026-03-13 21:52:09 +08:00
import React from "react";
import {
View,
Text,
TouchableOpacity,
StyleSheet,
Dimensions,
} from "react-native";
import { Image } from "expo-image";
2026-03-13 21:52:09 +08:00
import { Ionicons } from "@expo/vector-icons";
2026-03-14 11:55:45 +08:00
import { LivePulse } from "./LivePulse";
2026-03-13 21:52:09 +08:00
import type { LiveRoom } from "../services/types";
import { formatCount } from "../utils/format";
import { proxyImageUrl } from "../utils/imageUrl";
import { useTheme } from "../utils/theme";
2026-03-13 21:52:09 +08:00
const { width } = Dimensions.get("window");
const CARD_WIDTH = (width - 14) / 2;
interface Props {
item: LiveRoom;
2026-03-14 12:27:03 +08:00
isLivePulse?: Boolean;
2026-03-13 21:52:09 +08:00
onPress?: () => void;
2026-03-14 12:27:03 +08:00
fullWidth?: boolean;
2026-03-13 21:52:09 +08:00
}
2026-03-14 18:25:13 +08:00
export const LiveCard = React.memo(function LiveCard({
2026-03-14 12:27:03 +08:00
item,
onPress,
fullWidth,
isLivePulse = false,
}: Props) {
const cardWidth = fullWidth ? width - 8 : CARD_WIDTH;
const theme = useTheme();
2026-03-13 21:52:09 +08:00
return (
<TouchableOpacity
style={[styles.card, { width: cardWidth, backgroundColor: theme.card }]}
2026-03-13 21:52:09 +08:00
onPress={onPress}
activeOpacity={0.85}
>
<View style={styles.thumbContainer}>
<Image
source={{ uri: proxyImageUrl(item.cover) }}
style={[styles.thumb, { width: cardWidth, height: cardWidth * 0.5625, backgroundColor: theme.card }]}
contentFit="cover"
recyclingKey={String(item.roomid)}
transition={200}
2026-03-13 21:52:09 +08:00
/>
<View style={styles.liveBadge}>
2026-03-14 12:27:03 +08:00
{isLivePulse && <LivePulse />}
<Text style={styles.liveBadgeText}></Text>
2026-03-13 21:52:09 +08:00
</View>
<View style={styles.meta}>
<Ionicons name="people" size={11} color="#fff" />
<Text style={styles.metaText}>{formatCount(item.online)}</Text>
</View>
<View style={styles.areaBadge}>
<Text style={styles.areaText}>{item.area_name}</Text>
</View>
</View>
<View style={styles.info}>
<Text style={[styles.title, { color: theme.text }]} numberOfLines={2}>
2026-03-13 21:52:09 +08:00
{item.title}
</Text>
<View style={styles.ownerRow}>
<Image
source={{ uri: proxyImageUrl(item.face) }}
style={styles.avatar}
contentFit="cover"
recyclingKey={`face-${item.roomid}`}
2026-03-13 21:52:09 +08:00
/>
<Text
style={[styles.owner, { color: theme.textSub }]}
numberOfLines={1}
>
2026-03-13 21:52:09 +08:00
{item.uname}
</Text>
</View>
</View>
</TouchableOpacity>
);
2026-03-14 18:25:13 +08:00
});
2026-03-13 21:52:09 +08:00
const styles = StyleSheet.create({
card: {
width: CARD_WIDTH,
marginBottom: 6,
backgroundColor: "#fff",
borderRadius: 6,
overflow: "hidden",
},
thumbContainer: { position: "relative" },
thumb: {
width: CARD_WIDTH,
height: CARD_WIDTH * 0.5625,
backgroundColor: "#ddd",
},
liveBadge: {
position: "absolute",
top: 4,
left: 4,
backgroundColor: "rgba(0,0,0,0.6)",
borderRadius: 5,
paddingHorizontal: 5,
paddingVertical: 1,
flexDirection: "row",
alignItems: "center",
gap: 2,
},
liveBadgeText: { color: "#fff", fontSize: 9, fontWeight: "400" },
2026-03-13 21:52:09 +08:00
meta: {
position: "absolute",
bottom: 4,
left: 4,
borderRadius: 5,
paddingHorizontal: 5,
paddingVertical: 1,
2026-03-13 21:52:09 +08:00
backgroundColor: "rgba(0,0,0,0.6)",
flexDirection: "row",
alignItems: "center",
gap: 2,
},
metaText: { fontSize: 9, color: "#fff" },
2026-03-13 21:52:09 +08:00
areaBadge: {
position: "absolute",
bottom: 4,
right: 4,
borderRadius: 5,
paddingHorizontal: 5,
paddingVertical: 1,
2026-03-13 21:52:09 +08:00
backgroundColor: "rgba(0,0,0,0.6)",
},
areaText: { color: "#fff", fontSize: 9 },
2026-03-13 21:52:09 +08:00
info: { padding: 6 },
title: {
fontSize: 12,
lineHeight: 17,
minHeight: 40,
2026-03-13 21:52:09 +08:00
color: "#212121",
marginBottom: 4,
},
ownerRow: {
flexDirection: "row",
alignItems: "center",
gap: 4,
marginTop: 2,
},
avatar: {
width: 16,
height: 16,
borderRadius: 8,
backgroundColor: "#eee",
},
owner: { fontSize: 11, color: "#999", flex: 1 },
});