import { useState, useEffect, useRef, useMemo, useCallback } from 'react' import { View, Text, StyleSheet, Pressable, TextInput, Dimensions, Platform, Keyboard, ScrollView, } from 'react-native' import { Image } from 'expo-image' import { useSafeAreaInsets } from 'react-native-safe-area-context' import { useTranslation } from 'react-i18next' import BottomSheet, { BottomSheetView, BottomSheetBackdrop, BottomSheetScrollView } from '@gorhom/bottom-sheet' import { CloseIcon, AvatarUploadIcon } from '@/components/icon' import { LinearGradient } from 'expo-linear-gradient' interface EditProfileDrawerProps { visible: boolean onClose: () => void initialName?: string initialAvatar?: any onSave?: (name: string) => void } export default function EditProfileDrawer({ visible, onClose, initialName = '乔乔乔', initialAvatar, onSave, }: EditProfileDrawerProps) { const { t } = useTranslation() const bottomSheetRef = useRef(null) const [name, setName] = useState(initialName) const insets = useSafeAreaInsets() const snapPoints = useMemo(() => [280], []) useEffect(() => { if (visible) { bottomSheetRef.current?.expand() } else { bottomSheetRef.current?.close() } }, [visible]) // 当抽屉打开时,重置名字为初始值 useEffect(() => { if (visible) { setName(initialName) } }, [visible, initialName]) const handleSheetChanges = useCallback((index: number) => { if (index === -1) { onClose() } }, [onClose]) const renderBackdrop = useCallback( (props: any) => ( ), [] ) const handleSave = () => { Keyboard.dismiss() onSave?.(name) onClose() } const handleClose = () => { Keyboard.dismiss() onClose() } return ( {/* 顶部关闭按钮 */} {/* 头像区域 */} {/* 输入框 */} {/* 保存按钮 */} {t('editProfile.save')} ) } const styles = StyleSheet.create({ bottomSheetBackground: { backgroundColor: '#1C1E22', }, handleIndicator: { backgroundColor: '#666666', }, container: { flex: 1, backgroundColor: '#1C1E22', paddingHorizontal: 16, }, scrollView: { flex: 1, }, scrollContent: { paddingTop: 32, paddingBottom: Platform.OS === 'ios' ? 25 : 17, paddingHorizontal: 0, flexGrow: 1, }, closeButton: { position: 'absolute', top: Platform.OS === 'ios' ? 16 : 16, right: 16, width: 24, height: 24, alignItems: 'center', justifyContent: 'center', zIndex: 10, }, avatarContainer: { alignItems: 'center', }, avatarWrapper: { position: 'relative', width: 88, height: 88, }, avatar: { width: 88, height: 88, borderRadius: 50, overflow: 'hidden', }, cameraButton: { position: 'absolute', bottom: 0, right: 0, width: 26, height: 26, borderRadius: 16, backgroundColor: '#16181B', alignItems: 'center', justifyContent: 'center', borderWidth: 2, borderColor: '#FFFFFF', }, cameraIconContainer: { width: 13, height: 13, alignItems: 'center', justifyContent: 'center', }, input: { backgroundColor: '#262A31', borderRadius: 12, paddingHorizontal: 16, marginVertical: 24, paddingVertical: 14, color: '#F5F5F5', fontWeight: '500', fontSize: 14, height: 48, }, saveButtonContainer: { width: '100%', borderRadius: 12, overflow: 'hidden', height: 48, }, saveButton: { width: '100%', alignItems: 'center', justifyContent: 'center', borderRadius: 12, height: 48, }, saveButtonText: { color: '#F5F5F5', fontSize: 16, fontWeight: '500', }, })