import { Colors } from '@/constants/Colors';
import { getTemplatesByCategory, goalCategories, GoalTemplate } from '@/constants/goalTemplates';
import { useColorScheme } from '@/hooks/useColorScheme';
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import React, { useState } from 'react';
import {
Dimensions,
Image,
Modal,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
const { width: screenWidth } = Dimensions.get('window');
interface GoalTemplateModalProps {
visible: boolean;
onClose: () => void;
onSelectTemplate: (template: GoalTemplate) => void;
onCreateCustom: () => void;
}
export default function GoalTemplateModal({
visible,
onClose,
onSelectTemplate,
onCreateCustom
}: GoalTemplateModalProps) {
const theme = (useColorScheme() ?? 'light') as 'light' | 'dark';
const colorTokens = Colors[theme];
const [selectedCategory, setSelectedCategory] = useState('recommended');
const currentTemplates = getTemplatesByCategory(selectedCategory);
// 渲染分类标签
const renderCategoryTab = (category: any) => {
const isSelected = selectedCategory === category.id;
return (
setSelectedCategory(category.id)}
activeOpacity={0.8}
>
{category.isRecommended && (
)}
{category.title}
);
};
// 渲染模板项
const renderTemplateItem = (template: GoalTemplate) => (
onSelectTemplate(template)}
activeOpacity={0.8}
>
{template.title}
);
return (
{/* 头部 */}
创建新目标
{/* 创建自定义目标 */}
创建自定义目标
{/* 分类选择器 */}
{goalCategories.map(renderCategoryTab)}
{/* 当前分类的模板 */}
{currentTemplates.map(renderTemplateItem)}
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F9FAFB',
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingHorizontal: 20,
paddingVertical: 16,
backgroundColor: '#FFFFFF',
borderBottomWidth: 1,
borderBottomColor: '#E5E7EB',
},
closeButton: {
padding: 4,
},
title: {
fontSize: 18,
fontWeight: '600',
color: '#111827',
textAlign: 'center',
},
content: {
flex: 1,
},
scrollContent: {
paddingBottom: 40,
},
customGoalButton: {
flexDirection: 'row',
alignItems: 'center',
marginHorizontal: 20,
marginTop: 20,
padding: 16,
backgroundColor: '#FFFFFF',
borderRadius: 16,
borderWidth: 1,
borderColor: '#E5E7EB',
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.05,
shadowRadius: 2,
elevation: 1,
},
customGoalIcon: {
width: 40,
height: 40,
borderRadius: 20,
backgroundColor: '#F3E8FF',
alignItems: 'center',
justifyContent: 'center',
marginRight: 12,
},
customGoalText: {
fontSize: 16,
fontWeight: '600',
color: '#374151',
},
categorySection: {
marginTop: 24,
},
categoryScrollView: {
paddingLeft: 20,
},
categoryScrollContent: {
paddingRight: 20,
},
categoryTab: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 16,
paddingVertical: 10,
marginRight: 12,
borderRadius: 20,
backgroundColor: '#F3F4F6',
},
categoryTabSelected: {
backgroundColor: '#7C3AED',
},
categoryTabText: {
fontSize: 14,
fontWeight: '600',
color: '#374151',
},
categoryTabTextSelected: {
color: '#FFFFFF',
},
avatarGroup: {
flexDirection: 'row',
marginRight: 8,
},
avatar: {
width: 16,
height: 16,
borderRadius: 8,
borderWidth: 1,
borderColor: '#FFFFFF',
},
templatesSection: {
marginTop: 24,
},
templatesGrid: {
paddingHorizontal: 20,
flexDirection: 'row',
flexWrap: 'wrap',
gap: 12,
},
templateItem: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#FFFFFF',
minWidth: (screenWidth - 60) / 2, // 2列布局,考虑间距和padding
maxWidth: (screenWidth - 60) / 2,
aspectRatio: 2.2,
borderRadius: 16,
padding: 16,
justifyContent: 'center',
shadowColor: '#000',
shadowOffset: { width: 0, height: 1 },
shadowOpacity: 0.1,
shadowRadius: 3,
elevation: 2,
},
templateIcon: {
width: 24,
height: 24,
alignItems: 'center',
justifyContent: 'center',
},
templateTitle: {
fontSize: 14,
color: '#374151',
fontWeight: '600',
lineHeight: 20,
marginLeft: 12,
},
});