add editable button profile picture

This commit is contained in:
João Ferreiro
2022-11-30 15:19:58 +00:00
parent d0c9f95c7e
commit ef9ea5722b
2 changed files with 44 additions and 4 deletions
+1
View File
@@ -156,6 +156,7 @@ export const ProfileHeader = observer(function ProfileHeader({
<View style={styles.avi}>
<UserAvatar
size={80}
isMe={isMe}
displayName={view.displayName}
handle={view.handle}
/>
+43 -4
View File
@@ -1,19 +1,25 @@
import React from 'react'
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
import React, {useCallback} from 'react'
import {Alert, StyleSheet, View, TouchableOpacity} from 'react-native'
import Svg, {Circle, Text, Defs, LinearGradient, Stop} from 'react-native-svg'
import {getGradient} from '../../lib/asset-gen'
import {colors} from '../../lib/styles'
export function UserAvatar({
isMe = false,
size,
displayName,
handle,
displayName,
}: {
isMe?: boolean
size: number
displayName: string | undefined
handle: string
displayName: string | undefined
}) {
const initials = getInitials(displayName || handle)
const gradient = getGradient(handle)
return (
const renderSvg = (size: number, initials: string) => (
<Svg width={size} height={size} viewBox="0 0 100 100">
<Defs>
<LinearGradient id="grad" x1="0" y1="0" x2="1" y2="1">
@@ -33,6 +39,25 @@ export function UserAvatar({
</Text>
</Svg>
)
const handleEditAvatar = useCallback(() => {
Alert.alert('TB Implemented')
}, [])
return isMe ? (
<TouchableOpacity onPress={handleEditAvatar}>
{renderSvg(size, initials)}
<View style={styles.editButtonContainer}>
<FontAwesomeIcon
icon="camera"
size={10}
style={{color: colors.gray1}}
/>
</View>
</TouchableOpacity>
) : (
renderSvg(size, initials)
)
}
function getInitials(str: string): string {
@@ -50,3 +75,17 @@ function getInitials(str: string): string {
}
return 'X'
}
const styles = StyleSheet.create({
editButtonContainer: {
position: 'absolute',
bottom: 6,
right: 6,
backgroundColor: colors.gray5,
width: 20,
height: 20,
borderRadius: 10,
alignItems: 'center',
justifyContent: 'center',
},
})