Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | import { Dialog, Text, XStack, YStack } from 'tamagui';
import { Button } from '@/src/design-system/components';
import { IconSymbol } from '@/src/components/ui/IconSymbol';
import { primaryScale, warningScale, infoScale } from '@/src/design-system/tokens';
import { useThemeColors, useIsDarkMode } from '@/src/hooks/useThemeColors';
import type { ThemeMode } from '@/src/store/themeStore';
interface ThemeSelectorModalProps {
open: boolean;
onOpenChange: (open: boolean) => void;
currentTheme: ThemeMode;
onThemeChange: (theme: ThemeMode) => void;
}
const THEME_OPTIONS: {
mode: ThemeMode;
label: string;
icon: string;
description: string;
bgColor: string;
iconColor: string;
}[] = [
{
mode: 'light',
label: '浅色',
icon: 'sun.max.fill',
description: '明亮清晰',
bgColor: warningScale.warning2,
iconColor: warningScale.warning8,
},
{
mode: 'dark',
label: '深色',
icon: 'moon.fill',
description: '护眼模式',
bgColor: infoScale.info2,
iconColor: infoScale.info8,
},
{
mode: 'system',
label: '跟随系统',
icon: 'circle.lefthalf.filled',
description: '自动切换',
bgColor: primaryScale.primary2,
iconColor: primaryScale.primary8,
},
];
export function ThemeSelectorModal({
open,
onOpenChange,
currentTheme,
onThemeChange,
}: ThemeSelectorModalProps) {
const colors = useThemeColors();
const isDark = useIsDarkMode();
const handleThemeSelect = (mode: ThemeMode) => {
onThemeChange(mode);
onOpenChange(false);
};
return (
<Dialog modal open={open} onOpenChange={onOpenChange}>
<Dialog.Portal>
<Dialog.Overlay
key="overlay"
animation="quick"
opacity={0.5}
enterStyle={{ opacity: 0 }}
exitStyle={{ opacity: 0 }}
backgroundColor="black"
/>
<Dialog.Content
key="content"
animateOnly={['transform', 'opacity']}
animation={[
'quick',
{
opacity: {
overshootClamping: true,
},
},
]}
enterStyle={{ y: -20, opacity: 0, scale: 0.95 }}
exitStyle={{ y: 10, opacity: 0, scale: 0.95 }}
backgroundColor={colors.cardBackground as any}
borderRadius={24}
padding="$5"
width="90%"
maxWidth={400}
>
<YStack gap="$4">
{/* 标题 */}
<YStack alignItems="center" gap="$2">
<Text fontSize={20} fontWeight="700" color={colors.text as any}>
选择主题
</Text>
<Text fontSize={13} color={colors.textSecondary as any}>
选择您喜欢的显示模式
</Text>
</YStack>
{/* 主题选项 */}
<YStack gap="$3" marginTop="$2">
{THEME_OPTIONS.map((option) => {
const isSelected = currentTheme === option.mode;
return (
<XStack
key={option.mode}
padding="$4"
borderRadius={16}
borderWidth={2}
borderColor={(isSelected ? colors.primary : colors.border) as any}
backgroundColor={(isSelected ? colors.selected : colors.cardBackground) as any}
pressStyle={{ scale: 0.98, backgroundColor: colors.hover as any }}
onPress={() => handleThemeSelect(option.mode)}
alignItems="center"
gap="$3"
>
<YStack
width={48}
height={48}
borderRadius={14}
backgroundColor={
(isDark ? option.bgColor.replace(/^#/, '#1a') : option.bgColor) as any
}
alignItems="center"
justifyContent="center"
>
<IconSymbol name={option.icon as any} size={24} color={option.iconColor} />
</YStack>
<YStack flex={1}>
<Text
fontSize={16}
fontWeight="600"
color={(isSelected ? colors.primary : colors.text) as any}
>
{option.label}
</Text>
<Text fontSize={13} color={colors.textSecondary as any} marginTop={2}>
{option.description}
</Text>
</YStack>
{isSelected && (
<YStack
width={24}
height={24}
borderRadius={12}
backgroundColor={colors.primary as any}
alignItems="center"
justifyContent="center"
>
<IconSymbol
name="checkmark"
size={14}
color={isDark ? '#0A0A0A' : '#FFFFFF'}
/>
</YStack>
)}
</XStack>
);
})}
</YStack>
{/* 关闭按钮 */}
<Dialog.Close displayWhenAdapted asChild>
<Button
marginTop="$2"
height={48}
backgroundColor={colors.hover as any}
borderRadius={12}
pressStyle={{ backgroundColor: colors.active as any }}
onPress={() => onOpenChange(false)}
>
<Text fontSize={15} fontWeight="600" color={colors.text as any}>
完成
</Text>
</Button>
</Dialog.Close>
</YStack>
</Dialog.Content>
</Dialog.Portal>
</Dialog>
);
}
|