import React from 'react'; import { FlatList, Image, StyleSheet, View } from 'react-native'; import { RectButton, TouchableNativeFeedback, TouchableOpacity } from 'react-native-gesture-handler'; import { BUTTON_HIT_SLOP } from '../../containers/message/utils'; import { themes } from '../../lib/constants'; import { CustomIcon } from '../../containers/CustomIcon'; import { isIOS } from '../../utils/deviceInfo'; import { THUMBS_HEIGHT } from './constants'; import { allowPreview } from './utils'; import { TSupportedThemes } from '../../theme'; import { IShareAttachment } from '../../definitions'; const THUMB_SIZE = 64; const styles = StyleSheet.create({ list: { height: THUMBS_HEIGHT, paddingHorizontal: 8 }, videoThumbIcon: { position: 'absolute', left: 0, bottom: 0 }, dangerIcon: { position: 'absolute', right: 16, bottom: 0 }, removeButton: { position: 'absolute', right: 6, width: 28, height: 28, borderWidth: 2, borderRadius: 14, alignItems: 'center', justifyContent: 'center' }, removeView: { width: 28, height: 28, borderWidth: 2, borderRadius: 14, alignItems: 'center', justifyContent: 'center' }, item: { paddingTop: 8 }, thumb: { width: THUMB_SIZE, height: THUMB_SIZE, borderRadius: 2, marginRight: 16, overflow: 'hidden', alignItems: 'center', justifyContent: 'center', borderWidth: 1 } }); interface IThumbContent { item: IShareAttachment; theme: TSupportedThemes; isShareExtension: boolean; } interface IThumb extends IThumbContent { onPress(item: IShareAttachment): void; onRemove(item: IShareAttachment): void; } interface IThumbs extends Omit { attachments: IShareAttachment[]; } const ThumbContent = React.memo(({ item, theme, isShareExtension }: IThumbContent) => { const type = item?.mime; if (type?.match(/image/)) { // Disallow preview of images too big in order to prevent memory issues on iOS share extension if (allowPreview(isShareExtension, item?.size)) { return ; } return ( ); } if (type?.match(/video/)) { if (isIOS) { return ( ); } const { uri } = item; return ( <> ); } // Multiple files upload of files different than image/video is not implemented, so there's no thumb return null; }); const ThumbButton: typeof React.Component = isIOS ? TouchableOpacity : TouchableNativeFeedback; const Thumb = ({ item, theme, isShareExtension, onPress, onRemove }: IThumb) => ( onPress(item)} activeOpacity={0.7}> <> onRemove(item)}> {!item?.canUpload ? ( ) : null} ); const Thumbs = React.memo(({ attachments, theme, isShareExtension, onPress, onRemove }: IThumbs) => { if (attachments?.length > 1) { return ( item.path} renderItem={({ item }) => ( onPress(item)} onRemove={() => onRemove(item)} /> )} style={[styles.list, { backgroundColor: themes[theme].messageboxBackground }]} /> ); } return null; }); export default Thumbs;