- MessageBubble: IMAGE renders actual <Image> with aspect ratio clamping (min 80, max screenW-120) - MessageBubble: VIDEO shows thumbnail with play overlay; AUDIO shows waveform + play/stop - MessageBubble: per-message sender avatar (letter fallback when no uri) - ConversationItem: show real avatar when available; pinned indicator; muted dot badge - ConversationListScreen: sort pinned conversations to top; long-press for pin/mute actions - ContactsScreen, UserSearchScreen, GroupMembersScreen: real avatar images with fallback - ProfileScreen: show real avatar image, tap to edit - EditProfileScreen: avatar upload via uploadFile() to file-service before saving profile - GroupSettingsScreen: real leaveGroup() call via SDK, removes user from group server-side - GroupListScreen, GroupMembersScreen: parse memberIds as JSON array (was comma-split) - SingleChatScreen: remove redundant handleLongPress (now handled inside MessageBubble) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
104 行
4.4 KiB
TypeScript
104 行
4.4 KiB
TypeScript
import React from 'react'
|
||
import { View, Text, StyleSheet, TouchableOpacity, SafeAreaView, Alert, ScrollView, Image } from 'react-native'
|
||
import { useNavigation } from '@react-navigation/native'
|
||
import type { NativeStackNavigationProp } from '@react-navigation/native-stack'
|
||
import { useAuth } from '../../context/AuthContext'
|
||
import type { RootStackParams } from '../../navigation/types'
|
||
|
||
type Nav = NativeStackNavigationProp<RootStackParams>
|
||
|
||
function Row({ label, value, onPress }: { label: string; value?: string; onPress?(): void }) {
|
||
return (
|
||
<TouchableOpacity style={styles.row} onPress={onPress} disabled={!onPress} activeOpacity={onPress ? 0.7 : 1}>
|
||
<Text style={styles.rowLabel}>{label}</Text>
|
||
<View style={styles.rowRight}>
|
||
{value !== undefined && <Text style={styles.rowValue} numberOfLines={1}>{value}</Text>}
|
||
{onPress && <Text style={styles.arrow}>›</Text>}
|
||
</View>
|
||
</TouchableOpacity>
|
||
)
|
||
}
|
||
|
||
export default function ProfileScreen() {
|
||
const navigation = useNavigation<Nav>()
|
||
const { profile, logout } = useAuth()
|
||
|
||
const confirmLogout = () => {
|
||
Alert.alert('退出登录', '确定要退出吗?', [
|
||
{ text: '取消', style: 'cancel' },
|
||
{ text: '退出', style: 'destructive', onPress: () => logout() },
|
||
])
|
||
}
|
||
|
||
const genderLabel = (g?: string) => ({ MALE: '男', FEMALE: '女', UNKNOWN: '未设置' }[g ?? 'UNKNOWN'] ?? '未设置')
|
||
const letter = (profile?.nickname || profile?.userId || '?').charAt(0).toUpperCase()
|
||
const avatarUri = profile?.avatar || undefined
|
||
|
||
return (
|
||
<SafeAreaView style={styles.root}>
|
||
<ScrollView>
|
||
<View style={styles.avatarSection}>
|
||
<TouchableOpacity onPress={() => navigation.navigate('EditProfile')} style={styles.avatarWrapper}>
|
||
{avatarUri ? (
|
||
<Image source={{ uri: avatarUri }} style={styles.avatarImg} />
|
||
) : (
|
||
<View style={styles.avatarCircle}>
|
||
<Text style={styles.avatarText}>{letter}</Text>
|
||
</View>
|
||
)}
|
||
<View style={styles.avatarEditBadge}>
|
||
<Text style={styles.avatarEditIcon}>✎</Text>
|
||
</View>
|
||
</TouchableOpacity>
|
||
<Text style={styles.nickname}>{profile?.nickname ?? '-'}</Text>
|
||
<Text style={styles.userId}>@{profile?.userId ?? '-'}</Text>
|
||
</View>
|
||
|
||
<View style={styles.section}>
|
||
<Row label="昵称" value={profile?.nickname} onPress={() => navigation.navigate('EditProfile')} />
|
||
<View style={styles.sep} />
|
||
<Row label="性别" value={genderLabel(profile?.gender)} onPress={() => navigation.navigate('EditProfile')} />
|
||
</View>
|
||
|
||
<TouchableOpacity style={styles.logoutBtn} onPress={confirmLogout}>
|
||
<Text style={styles.logoutText}>退出登录</Text>
|
||
</TouchableOpacity>
|
||
</ScrollView>
|
||
</SafeAreaView>
|
||
)
|
||
}
|
||
|
||
const styles = StyleSheet.create({
|
||
root: { flex: 1, backgroundColor: '#f5f5f5' },
|
||
avatarSection: { alignItems: 'center', paddingTop: 40, paddingBottom: 24, backgroundColor: '#fff', marginBottom: 16 },
|
||
avatarWrapper: { position: 'relative', marginBottom: 12 },
|
||
avatarImg: { width: 80, height: 80, borderRadius: 40 },
|
||
avatarCircle: { width: 80, height: 80, borderRadius: 40, backgroundColor: '#07C160', alignItems: 'center', justifyContent: 'center' },
|
||
avatarText: { color: '#fff', fontSize: 32, fontWeight: '700' },
|
||
avatarEditBadge: {
|
||
position: 'absolute',
|
||
bottom: 0,
|
||
right: 0,
|
||
width: 24,
|
||
height: 24,
|
||
borderRadius: 12,
|
||
backgroundColor: '#fff',
|
||
borderWidth: 1,
|
||
borderColor: '#e0e0e0',
|
||
alignItems: 'center',
|
||
justifyContent: 'center',
|
||
},
|
||
avatarEditIcon: { fontSize: 12, color: '#555' },
|
||
nickname: { fontSize: 20, fontWeight: '700', color: '#111', marginBottom: 4 },
|
||
userId: { fontSize: 13, color: '#888' },
|
||
section: { backgroundColor: '#fff', marginBottom: 16 },
|
||
row: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 16 },
|
||
rowLabel: { fontSize: 16, color: '#333' },
|
||
rowRight: { flexDirection: 'row', alignItems: 'center', gap: 8 },
|
||
rowValue: { fontSize: 15, color: '#888', maxWidth: 160 },
|
||
arrow: { color: '#ccc', fontSize: 20 },
|
||
sep: { height: StyleSheet.hairlineWidth, backgroundColor: '#e0e0e0', marginLeft: 16 },
|
||
logoutBtn: { margin: 16, padding: 16, backgroundColor: '#fff', borderRadius: 8, alignItems: 'center' },
|
||
logoutText: { color: '#ff3b30', fontSize: 16, fontWeight: '600' },
|
||
})
|