/** * 主题演示组件 * * 展示所有主题颜色和组件在不同主题下的效果 */ import React from 'react'; import { StyleSheet, View, Text, TouchableOpacity, ScrollView } from 'react-native'; import { ThemedText, ThemedView, useThemeColor } from './Themed'; import { useTheme, useSettingsActions } from '@/stores'; import { useHaptics } from '@/hooks'; export function ThemeDemo() { const theme = useTheme(); const { setTheme } = useSettingsActions(); const haptics = useHaptics(); // 获取主题颜色 const primary = useThemeColor({}, 'primary'); const secondary = useThemeColor({}, 'secondary'); const success = useThemeColor({}, 'success'); const warning = useThemeColor({}, 'warning'); const error = useThemeColor({}, 'error'); const info = useThemeColor({}, 'info'); const border = useThemeColor({}, 'border'); const card = useThemeColor({}, 'card'); const textSecondary = useThemeColor({}, 'textSecondary'); const handleThemeChange = (newTheme: 'light' | 'dark' | 'auto') => { haptics.selection(); console.log('🎨 Changing theme to:', newTheme); setTheme(newTheme); console.log('🎨 Theme colors after change:', { primary, secondary, background: card }); }; return ( {/* 主题切换器 */} 主题切换 handleThemeChange('light')} > ☀️ 浅色 handleThemeChange('dark')} > 🌙 深色 handleThemeChange('auto')} > 🔄 自动 当前主题: {theme === 'light' ? '浅色' : theme === 'dark' ? '深色' : '自动'} {/* 文本样式 */} 文本样式 标题文本 (Title) 副标题文本 (Subtitle) 加粗文本 (SemiBold) 默认文本 (Default) 链接文本 (Link) {/* 颜色展示 */} 主题颜色 Primary Secondary Success Warning Error Info {/* 卡片示例 */} 卡片组件 卡片标题 这是一个卡片组件示例,会根据主题自动调整颜色 {/* 按钮示例 */} 按钮组件 Primary Button Secondary Button Success Button Error Button ); } const styles = StyleSheet.create({ container: { flex: 1, padding: 16, }, section: { marginBottom: 24, }, themeButtons: { flexDirection: 'row', gap: 12, marginTop: 12, }, themeButton: { flex: 1, paddingVertical: 12, paddingHorizontal: 16, borderRadius: 8, borderWidth: 1, alignItems: 'center', }, themeButtonText: { fontSize: 14, fontWeight: '600', }, activeButtonText: { color: '#FFFFFF', }, hint: { marginTop: 8, fontSize: 12, opacity: 0.7, }, colorGrid: { flexDirection: 'row', flexWrap: 'wrap', gap: 16, marginTop: 12, }, colorItem: { alignItems: 'center', width: 80, }, colorBox: { width: 60, height: 60, borderRadius: 8, marginBottom: 8, }, colorLabel: { fontSize: 12, textAlign: 'center', }, card: { padding: 16, borderRadius: 12, borderWidth: 1, marginTop: 12, }, button: { paddingVertical: 12, paddingHorizontal: 24, borderRadius: 8, alignItems: 'center', marginTop: 12, }, buttonText: { color: '#FFFFFF', fontSize: 16, fontWeight: '600', }, });