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 {Image as PickedImage} from 'react-native-image-crop-picker' import {getGradient} from '../../lib/asset-gen' import {colors} from '../../lib/styles' import { openCamera, openCropper, openPicker, } from 'react-native-image-crop-picker' export function UserBanner({ handle, banner, onSelectNewBanner, }: { handle: string banner?: string | null onSelectNewBanner?: (img: PickedImage) => void }) { const gradient = getGradient(handle) const handleEditBanner = useCallback(() => { Alert.alert('Select upload method', '', [ { text: 'Take a new photo', onPress: () => { openCamera({ mediaType: 'photo', cropping: true, compressImageMaxWidth: 3000, width: 3000, compressImageMaxHeight: 1000, height: 1000, forceJpg: true, // ios only compressImageQuality: 1, includeExif: true, }).then(onSelectNewBanner) }, }, { text: 'Select from gallery', onPress: () => { openPicker({ mediaType: 'photo', }).then(async item => { await openCropper({ mediaType: 'photo', path: item.path, compressImageMaxWidth: 3000, width: 3000, compressImageMaxHeight: 1000, height: 1000, forceJpg: true, // ios only compressImageQuality: 1, includeExif: true, }).then(onSelectNewBanner) }) }, }, ]) }, [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: 120, }, })