|
| 1 | +import { isWeb } from '@baca/constants' |
| 2 | +import { Box, Text, Button, Row, themeColors } from '@baca/design-system' |
| 3 | +import * as ImagePicker from 'expo-image-picker' |
| 4 | +import { t } from 'i18next' |
| 5 | +import { useState, useCallback } from 'react' |
| 6 | +import { Image, StyleSheet } from 'react-native' |
| 7 | + |
| 8 | +export const ProfileEditImage: React.FC = () => { |
| 9 | + const [image, setImage] = useState<string | null>(null) |
| 10 | + |
| 11 | + const pickImage = useCallback(async () => { |
| 12 | + const result = await ImagePicker.launchImageLibraryAsync({ |
| 13 | + mediaTypes: ImagePicker.MediaTypeOptions.Images, |
| 14 | + allowsEditing: true, |
| 15 | + aspect: [4, 3], |
| 16 | + quality: 1, |
| 17 | + }) |
| 18 | + |
| 19 | + if (!result.canceled && result.assets && result.assets.length > 0) { |
| 20 | + setImage(result.assets[0].uri) |
| 21 | + } |
| 22 | + }, []) |
| 23 | + |
| 24 | + return ( |
| 25 | + <Box borderColor="border.secondary" borderTopWidth={1} py={6}> |
| 26 | + <Box style={styles.marginBottom}> |
| 27 | + <Text.SmBold color="text.primary">{t('profile_screen.your_photo')}</Text.SmBold> |
| 28 | + <Text.SmRegular color="text.secondary"> |
| 29 | + {t('profile_screen.your_photo_description')} |
| 30 | + </Text.SmRegular> |
| 31 | + </Box> |
| 32 | + <Box style={styles.imageContainer}> |
| 33 | + {image ? ( |
| 34 | + <Image source={{ uri: image }} style={styles.image} /> |
| 35 | + ) : ( |
| 36 | + <Box style={styles.placeholder}> |
| 37 | + <Text color="Gray modern.600">{t('profile_screen.photo_innerText')}</Text> |
| 38 | + </Box> |
| 39 | + )} |
| 40 | + </Box> |
| 41 | + <Row maxW={800} justifyContent="flex-end"> |
| 42 | + <Button onPress={pickImage}>{t('common.upload')}</Button> |
| 43 | + </Row> |
| 44 | + </Box> |
| 45 | + ) |
| 46 | +} |
| 47 | + |
| 48 | +const styles = StyleSheet.create({ |
| 49 | + image: { |
| 50 | + height: '100%', |
| 51 | + width: '100%', |
| 52 | + }, |
| 53 | + imageContainer: { |
| 54 | + alignSelf: 'center', |
| 55 | + borderRadius: 50, |
| 56 | + height: 100, |
| 57 | + marginBottom: 10, |
| 58 | + overflow: 'hidden', |
| 59 | + right: isWeb ? 150 : 0, |
| 60 | + width: 100, |
| 61 | + }, |
| 62 | + marginBottom: { |
| 63 | + marginBottom: 10, |
| 64 | + }, |
| 65 | + placeholder: { |
| 66 | + alignItems: 'center', |
| 67 | + backgroundColor: themeColors.primitives['Gray neutral']['50'], |
| 68 | + height: '100%', |
| 69 | + justifyContent: 'center', |
| 70 | + width: '100%', |
| 71 | + }, |
| 72 | +}) |
0 commit comments