优化比赛卡片显示,添加球队名称和logo,调整样式;更新实时比分功能,简化数据处理逻辑

This commit is contained in:
yuchenglong
2026-01-19 15:16:27 +08:00
parent c522f2ba01
commit e766a833f6
3 changed files with 72 additions and 42 deletions

View File

@@ -4,6 +4,7 @@ import { Colors } from "@/constants/theme";
import { useTheme } from "@/context/ThemeContext";
import { addFavorite, removeFavorite } from "@/lib/api";
import { Match } from "@/types/api";
import { Image } from "expo-image";
import { LinearGradient } from "expo-linear-gradient";
import { useRouter } from "expo-router";
import React, { useState } from "react";
@@ -50,17 +51,19 @@ export function MatchCard({
}, [match.time]);
const leagueShort = React.useMemo(() => {
const league = (match.league || "").trim();
const league = (match.leagueName || match.league || "").trim();
if (!league) return "--";
const first = league.split(/[^A-Za-z0-9]+/).filter(Boolean)[0] || league;
return first.slice(0, 3).toUpperCase();
}, [match.league]);
}, [match.leagueName, match.league]);
const scoreParts = React.useMemo(() => {
const s = (match.scoreText || "").trim();
const m = s.match(/(\d+)\s*[-:]\s*(\d+)/);
if (m) return { home: m[1], away: m[2], hasScore: true };
if (s && s !== "-") return { home: s, away: "", hasScore: true };
if (s && s !== "-" && s !== "0 - 0")
return { home: s, away: "", hasScore: true };
if (s === "0 - 0") return { home: "0", away: "0", hasScore: true };
return { home: "", away: "", hasScore: false };
}, [match.scoreText]);
@@ -137,22 +140,40 @@ export function MatchCard({
{/* Middle: Teams */}
<View style={styles.middle}>
<ThemedText
type="defaultSemiBold"
style={styles.teamLine}
numberOfLines={1}
ellipsizeMode="tail"
>
{match.home}
</ThemedText>
<ThemedText
type="defaultSemiBold"
style={styles.teamLine}
numberOfLines={1}
ellipsizeMode="tail"
>
{match.away}
</ThemedText>
<View style={styles.teamRow}>
{match.homeTeamLogo ? (
<Image
source={{ uri: match.homeTeamLogo }}
style={styles.teamLogo}
contentFit="contain"
/>
) : null}
<ThemedText
type="defaultSemiBold"
style={styles.teamLine}
numberOfLines={1}
ellipsizeMode="tail"
>
{match.homeTeamName || match.home}
</ThemedText>
</View>
<View style={styles.teamRow}>
{match.awayTeamLogo ? (
<Image
source={{ uri: match.awayTeamLogo }}
style={styles.teamLogo}
contentFit="contain"
/>
) : null}
<ThemedText
type="defaultSemiBold"
style={styles.teamLine}
numberOfLines={1}
ellipsizeMode="tail"
>
{match.awayTeamName || match.away}
</ThemedText>
</View>
</View>
{/* Right: Score box + favorite */}
@@ -235,16 +256,27 @@ const styles = StyleSheet.create({
timeTextLive: {
color: "#FF3B30",
opacity: 1,
fontWeight: "bold",
},
middle: {
flex: 1,
justifyContent: "center",
gap: 6,
gap: 8,
minWidth: 0,
},
teamRow: {
flexDirection: "row",
alignItems: "center",
gap: 8,
},
teamLogo: {
width: 24,
height: 24,
},
teamLine: {
fontSize: 16,
fontSize: 15,
lineHeight: 18,
flex: 1,
},
right: {
flexDirection: "row",