Upload image in composer (#27)
* upload images in composer v1 * fix android compile * reafctor image carousel into new component; fix photo overlapping text in composer * revert android changes * further refactoring code into different components * move show carousel out of the component * fixing add photo using camera * fix typescript issue; force mediatype photo * change post test with photo attached; remove auto linking settings * use runInAction in getPhotos model * react-hooks/exhaustive-deps fixes * crop every photo; make use of useCallback * moving placeholder condition * Cleanup Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
parent
7ae1bac620
commit
67c4dcff37
10 changed files with 391 additions and 58 deletions
87
src/view/com/composer/SelectedPhoto.tsx
Normal file
87
src/view/com/composer/SelectedPhoto.tsx
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import React, {useCallback} from 'react'
|
||||
import {Image, StyleSheet, TouchableOpacity, View} from 'react-native'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {colors} from '../../lib/styles'
|
||||
|
||||
export const SelectedPhoto = ({
|
||||
selectedPhotos,
|
||||
setSelectedPhotos,
|
||||
}: {
|
||||
selectedPhotos: string[]
|
||||
setSelectedPhotos: React.Dispatch<React.SetStateAction<string[]>>
|
||||
}) => {
|
||||
const imageStyle =
|
||||
selectedPhotos.length === 1
|
||||
? styles.image250
|
||||
: selectedPhotos.length === 2
|
||||
? styles.image175
|
||||
: styles.image85
|
||||
|
||||
const handleRemovePhoto = useCallback(
|
||||
item => {
|
||||
setSelectedPhotos(
|
||||
selectedPhotos.filter(filterItem => filterItem !== item),
|
||||
)
|
||||
},
|
||||
[selectedPhotos, setSelectedPhotos],
|
||||
)
|
||||
|
||||
return selectedPhotos.length !== 0 ? (
|
||||
<View style={styles.imageContainer}>
|
||||
{selectedPhotos.length !== 0 &&
|
||||
selectedPhotos.map((item, index) => (
|
||||
<View
|
||||
key={`selected-image-${index}`}
|
||||
style={[styles.image, imageStyle]}>
|
||||
<TouchableOpacity
|
||||
onPress={() => handleRemovePhoto(item)}
|
||||
style={styles.removePhotoButton}>
|
||||
<FontAwesomeIcon
|
||||
icon="xmark"
|
||||
size={16}
|
||||
style={{color: colors.white}}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
|
||||
<Image style={[styles.image, imageStyle]} source={{uri: item}} />
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
imageContainer: {
|
||||
flex: 1,
|
||||
flexDirection: 'row',
|
||||
marginTop: 16,
|
||||
},
|
||||
image: {
|
||||
borderRadius: 8,
|
||||
margin: 2,
|
||||
},
|
||||
image250: {
|
||||
width: 250,
|
||||
height: 250,
|
||||
},
|
||||
image175: {
|
||||
width: 175,
|
||||
height: 175,
|
||||
},
|
||||
image85: {
|
||||
width: 85,
|
||||
height: 85,
|
||||
},
|
||||
removePhotoButton: {
|
||||
position: 'absolute',
|
||||
top: 8,
|
||||
right: 8,
|
||||
width: 24,
|
||||
height: 24,
|
||||
borderRadius: 12,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
backgroundColor: colors.black,
|
||||
zIndex: 1,
|
||||
},
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue