acupedia-mobile-ui/src/features/profile/components/ProfileAvatar.tsx

141 lines
2.7 KiB
TypeScript

import React from "react";
import {
Pressable,
StyleSheet,
Text,
View,
} from "react-native";
import { Image } from "expo-image";
import { Ionicons } from "@expo/vector-icons";
import { useRouter } from "expo-router";
import {
moderateScale,
scale,
verticalScale,
} from "react-native-size-matters";
import { Colors } from "@/theme";
interface ProfileAvatarProps {
name: string;
email: string;
imageUri?: string;
onEditPress?: () => void;
}
export default function ProfileAvatar({
name,
email,
imageUri,
onEditPress,
}: ProfileAvatarProps) {
const router = useRouter();
const handleEditProfile = () => {
onEditPress?.();
router.push("/profile/edit");
};
return (
<View style={styles.container}>
<View style={styles.avatarWrapper}>
{imageUri ? (
<Image
source={{ uri: imageUri }}
style={styles.avatar}
contentFit="cover"
/>
) : (
<View style={styles.avatar}>
<Ionicons
name="person"
size={moderateScale(52)}
color="#B8B8B8"
/>
</View>
)}
<Pressable
accessibilityRole="button"
accessibilityLabel="Edit Profile Picture"
hitSlop={10}
onPress={handleEditProfile}
style={styles.editButton}
>
<Ionicons
name="camera"
size={moderateScale(14)}
color="#FFFFFF"
/>
</Pressable>
</View>
<Pressable
accessibilityRole="button"
accessibilityLabel="Edit Profile"
hitSlop={10}
onPress={handleEditProfile}
>
<Text style={styles.name}>
{name}
</Text>
</Pressable>
<Text style={styles.email}>
{email}
</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
alignItems: "center",
marginTop: verticalScale(10),
marginBottom: verticalScale(28),
},
avatarWrapper: {
position: "relative",
marginBottom: verticalScale(16),
},
avatar: {
width: scale(96),
height: scale(96),
borderRadius: scale(48),
backgroundColor: "#F2F3F7",
justifyContent: "center",
alignItems: "center",
},
editButton: {
position: "absolute",
right: scale(-2),
bottom: scale(-2),
width: scale(30),
height: scale(30),
borderRadius: scale(15),
backgroundColor: "#5B3DF5",
justifyContent: "center",
alignItems: "center",
borderWidth: 2,
borderColor: "#FFFFFF",
},
name: {
fontSize: moderateScale(18),
fontWeight: "700",
color: Colors.text,
},
email: {
marginTop: verticalScale(6),
fontSize: moderateScale(14),
color: "#7A7A7A",
},
});