add editable button profile picture
This commit is contained in:
@@ -156,6 +156,7 @@ export const ProfileHeader = observer(function ProfileHeader({
|
|||||||
<View style={styles.avi}>
|
<View style={styles.avi}>
|
||||||
<UserAvatar
|
<UserAvatar
|
||||||
size={80}
|
size={80}
|
||||||
|
isMe={isMe}
|
||||||
displayName={view.displayName}
|
displayName={view.displayName}
|
||||||
handle={view.handle}
|
handle={view.handle}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -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 Svg, {Circle, Text, Defs, LinearGradient, Stop} from 'react-native-svg'
|
||||||
import {getGradient} from '../../lib/asset-gen'
|
import {getGradient} from '../../lib/asset-gen'
|
||||||
|
import {colors} from '../../lib/styles'
|
||||||
|
|
||||||
export function UserAvatar({
|
export function UserAvatar({
|
||||||
|
isMe = false,
|
||||||
size,
|
size,
|
||||||
displayName,
|
|
||||||
handle,
|
handle,
|
||||||
|
displayName,
|
||||||
}: {
|
}: {
|
||||||
|
isMe?: boolean
|
||||||
size: number
|
size: number
|
||||||
displayName: string | undefined
|
|
||||||
handle: string
|
handle: string
|
||||||
|
displayName: string | undefined
|
||||||
}) {
|
}) {
|
||||||
const initials = getInitials(displayName || handle)
|
const initials = getInitials(displayName || handle)
|
||||||
const gradient = getGradient(handle)
|
const gradient = getGradient(handle)
|
||||||
return (
|
|
||||||
|
const renderSvg = (size: number, initials: string) => (
|
||||||
<Svg width={size} height={size} viewBox="0 0 100 100">
|
<Svg width={size} height={size} viewBox="0 0 100 100">
|
||||||
<Defs>
|
<Defs>
|
||||||
<LinearGradient id="grad" x1="0" y1="0" x2="1" y2="1">
|
<LinearGradient id="grad" x1="0" y1="0" x2="1" y2="1">
|
||||||
@@ -33,6 +39,25 @@ export function UserAvatar({
|
|||||||
</Text>
|
</Text>
|
||||||
</Svg>
|
</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 {
|
function getInitials(str: string): string {
|
||||||
@@ -50,3 +75,17 @@ function getInitials(str: string): string {
|
|||||||
}
|
}
|
||||||
return 'X'
|
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',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user