import React, { useState } from 'react' import { View, Text, TextInput, StyleSheet, TouchableOpacity, SafeAreaView, ActivityIndicator, Alert, ScrollView, } from 'react-native' import { useAuth } from '../../context/AuthContext' import { useNavigation } from '@react-navigation/native' type Gender = 'UNKNOWN' | 'MALE' | 'FEMALE' export default function EditProfileScreen() { const navigation = useNavigation() const { profile, updateProfile } = useAuth() const [nickname, setNickname] = useState(profile?.nickname ?? '') const [gender, setGender] = useState(profile?.gender ?? 'UNKNOWN') const [loading, setLoading] = useState(false) const save = async () => { const nick = nickname.trim() if (!nick) { Alert.alert('提示', '昵称不能为空'); return } setLoading(true) try { await updateProfile({ nickname: nick, gender }) navigation.goBack() } catch (e: any) { Alert.alert('失败', e?.message ?? '保存失败,请重试') } finally { setLoading(false) } } return ( 昵称 性别 {(['MALE', 'FEMALE', 'UNKNOWN'] as Gender[]).map(g => { const label = { MALE: '男', FEMALE: '女', UNKNOWN: '不设置' }[g] return ( setGender(g)} > {label} ) })} {loading ? : 保存} ) } const styles = StyleSheet.create({ root: { flex: 1, backgroundColor: '#f5f5f5' }, inner: { padding: 20 }, label: { fontSize: 13, color: '#888', marginBottom: 8, marginTop: 16 }, input: { backgroundColor: '#fff', borderWidth: 1, borderColor: '#e0e0e0', borderRadius: 8, padding: 12, fontSize: 16 }, genderRow: { flexDirection: 'row', gap: 12 }, genderBtn: { flex: 1, padding: 12, borderRadius: 8, borderWidth: 1, borderColor: '#e0e0e0', backgroundColor: '#fff', alignItems: 'center' }, genderBtnActive: { borderColor: '#07C160', backgroundColor: '#e8f9f0' }, genderBtnText: { fontSize: 15, color: '#555' }, genderBtnTextActive: { color: '#07C160', fontWeight: '600' }, saveBtn: { marginTop: 32, backgroundColor: '#07C160', borderRadius: 8, padding: 14, alignItems: 'center' }, saveBtnText: { color: '#fff', fontSize: 16, fontWeight: '600' }, })