import React, {useCallback} from 'react' import {StyleSheet, View, TouchableOpacity, Alert, Image} from 'react-native' import Svg, {Rect, Defs, LinearGradient, Stop} from 'react-native-svg' import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome' import {colors, gradients} from '../../lib/styles' import { openCamera, openCropper, openPicker, PickedMedia, } from './images/image-crop-picker/ImageCropPicker' import {useStores} from '../../../state' export function UserBanner({ banner, onSelectNewBanner, }: { banner?: string | null onSelectNewBanner?: (img: PickedMedia) => void }) { const store = useStores() const handleEditBanner = useCallback(() => { Alert.alert('Select upload method', '', [ { text: 'Take a new photo', onPress: () => { openCamera(store, { mediaType: 'photo', // compressImageMaxWidth: 3000, TODO needed? width: 3000, // compressImageMaxHeight: 1000, TODO needed? height: 1000, }).then(onSelectNewBanner) }, }, { text: 'Select from gallery', onPress: () => { openPicker(store, { mediaType: 'photo', }).then(async items => { await openCropper(store, { mediaType: 'photo', path: items[0].path, // compressImageMaxWidth: 3000, TODO needed? width: 3000, // compressImageMaxHeight: 1000, TODO needed? height: 1000, }).then(onSelectNewBanner) }) }, }, ]) }, [store, onSelectNewBanner]) const renderSvg = () => ( ) // setUserBanner is only passed as prop on the EditProfile component return onSelectNewBanner ? ( {banner ? ( ) : ( renderSvg() )} ) : banner ? ( ) : ( renderSvg() ) } const styles = StyleSheet.create({ editButtonContainer: { position: 'absolute', width: 24, height: 24, bottom: 8, right: 8, borderRadius: 12, alignItems: 'center', justifyContent: 'center', backgroundColor: colors.gray5, }, bannerImage: { width: '100%', height: 150, }, })