初步实现选择运动

This commit is contained in:
xianyi
2026-01-13 10:35:07 +08:00
parent ceee6fe699
commit bff2763013
2 changed files with 156 additions and 35 deletions

View File

@@ -152,6 +152,7 @@ export default function HomeScreen() {
id: s.id, id: s.id,
label: s.name, label: s.name,
value: s.id, value: s.id,
icon: s.icon, // 添加图标
}))} }))}
selectedValue={selectedSportId} selectedValue={selectedSportId}
onSelect={setSelectedSportId} onSelect={setSelectedSportId}

View File

@@ -1,4 +1,5 @@
import { ThemedText } from "@/components/themed-text"; import { ThemedText } from "@/components/themed-text";
import { IconSymbol } from "@/components/ui/icon-symbol";
import { Colors } from "@/constants/theme"; import { Colors } from "@/constants/theme";
import { useTheme } from "@/context/ThemeContext"; import { useTheme } from "@/context/ThemeContext";
import React from "react"; import React from "react";
@@ -9,8 +10,47 @@ interface SelectionOption {
id: number | string; id: number | string;
label: string; label: string;
value: any; value: any;
icon?: string; // 图标名称
} }
// 运动名称到图标的映射
const getSportIcon = (label: string, icon?: string): string => {
// 如果提供了 icon 字段,尝试直接使用
if (icon) {
// 如果 icon 已经是 Ionicons 格式,直接返回
if (icon.includes("-")) {
return icon;
}
}
// 根据运动名称映射图标
const labelLower = label.toLowerCase();
if (labelLower.includes("足球") || labelLower.includes("football") || labelLower.includes("soccer")) {
return "football-outline";
}
if (labelLower.includes("篮球") || labelLower.includes("basketball")) {
return "basketball-outline";
}
if (labelLower.includes("板球") || labelLower.includes("cricket")) {
return "baseball-outline";
}
if (labelLower.includes("网球") || labelLower.includes("tennis")) {
return "tennisball-outline";
}
if (labelLower.includes("棒球") || labelLower.includes("baseball")) {
return "baseball-outline";
}
if (labelLower.includes("羽毛球") || labelLower.includes("badminton")) {
return "ellipse-outline";
}
if (labelLower.includes("斯诺克") || labelLower.includes("snooker")) {
return "radio-button-on-outline";
}
// 默认图标
return "ellipse-outline";
};
interface SelectionModalProps { interface SelectionModalProps {
visible: boolean; visible: boolean;
onClose: () => void; onClose: () => void;
@@ -47,37 +87,71 @@ export function SelectionModal({
<View style={[styles.sheet, { backgroundColor: bg }]}> <View style={[styles.sheet, { backgroundColor: bg }]}>
<SafeAreaView edges={["bottom"]}> <SafeAreaView edges={["bottom"]}>
<View style={styles.header}> <View style={styles.header}>
<ThemedText type="subtitle">{title}</ThemedText> <ThemedText type="subtitle" style={styles.title}>
<Pressable onPress={onClose}> {title}
<ThemedText style={{ color: Colors[theme].tint }}>
Done
</ThemedText> </ThemedText>
<Pressable onPress={onClose} style={styles.closeButton}>
<IconSymbol name="close" size={24} color={text} />
</Pressable> </Pressable>
</View> </View>
<ScrollView style={{ maxHeight: 300 }}> <ScrollView style={styles.scrollView} showsVerticalScrollIndicator={false}>
{options.map((opt) => ( {options.map((opt) => {
const isSelected = selectedValue === opt.value;
const optionBg = isDark ? "#2C2C2E" : "#F5F5F5";
const iconBg = isDark ? "#3A3A3C" : "#E5E5EA";
return (
<Pressable <Pressable
key={opt.id} key={opt.id}
style={[ style={[
styles.option, styles.option,
selectedValue === opt.value && { { backgroundColor: optionBg },
backgroundColor: isDark ? "#333" : "#F0F0F0",
},
]} ]}
onPress={() => { onPress={() => {
onSelect(opt.value); onSelect(opt.value);
onClose(); onClose();
}} }}
> >
{/* 左侧图标 */}
<View style={[styles.iconContainer, { backgroundColor: iconBg }]}>
<IconSymbol
name={getSportIcon(opt.label, opt.icon) as any}
size={24}
color={isSelected ? Colors.light.tint : text}
/>
</View>
{/* 中间内容 */}
<View style={styles.content}>
<ThemedText <ThemedText
style={{ style={[
fontWeight: selectedValue === opt.value ? "bold" : "normal", styles.optionLabel,
}} { fontWeight: isSelected ? "600" : "400" },
]}
> >
{opt.label} {opt.label}
</ThemedText> </ThemedText>
<ThemedText style={styles.statusText}>
{isSelected ? "已选择" : "点击切换"}
</ThemedText>
</View>
{/* 右侧指示点 */}
<View
style={[
styles.indicator,
{
backgroundColor: isSelected
? Colors.light.tint
: isDark
? "#666666"
: "#CCCCCC",
},
]}
/>
</Pressable> </Pressable>
))} );
})}
</ScrollView> </ScrollView>
</SafeAreaView> </SafeAreaView>
</View> </View>
@@ -91,21 +165,67 @@ const styles = StyleSheet.create({
backgroundColor: "rgba(0,0,0,0.5)", backgroundColor: "rgba(0,0,0,0.5)",
}, },
sheet: { sheet: {
borderTopLeftRadius: 16, borderTopLeftRadius: 20,
borderTopRightRadius: 16, borderTopRightRadius: 20,
padding: 16, padding: 20,
maxHeight: "60%", maxHeight: "70%",
}, },
header: { header: {
flexDirection: "row", flexDirection: "row",
justifyContent: "space-between", justifyContent: "space-between",
alignItems: "center", alignItems: "center",
marginBottom: 16, marginBottom: 20,
},
title: {
fontSize: 18,
fontWeight: "600",
},
closeButton: {
width: 32,
height: 32,
alignItems: "center",
justifyContent: "center",
},
scrollView: {
maxHeight: 400,
}, },
option: { option: {
flexDirection: "row",
alignItems: "center",
paddingVertical: 16, paddingVertical: 16,
paddingHorizontal: 12, paddingHorizontal: 16,
borderBottomWidth: StyleSheet.hairlineWidth, marginBottom: 12,
borderBottomColor: "#ccc", borderRadius: 12,
},
iconContainer: {
width: 48,
height: 48,
borderRadius: 24,
alignItems: "center",
justifyContent: "center",
marginRight: 12,
},
iconPlaceholder: {
width: 24,
height: 24,
borderRadius: 12,
backgroundColor: "#999",
},
content: {
flex: 1,
},
optionLabel: {
fontSize: 16,
marginBottom: 4,
},
statusText: {
fontSize: 12,
opacity: 0.6,
},
indicator: {
width: 8,
height: 8,
borderRadius: 4,
marginLeft: 12,
}, },
}); });