// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import { Text, TouchableOpacity, View } from 'react-native'; import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme'; import * as Utils from 'mattermost-redux/utils/file_utils.js'; import FileAttachmentIcon from './file_attachment_icon'; import FileAttachmentImage from './file_attachment_image'; export default class FileAttachment extends PureComponent { static propTypes = { addFileToFetchCache: PropTypes.func.isRequired, fetchCache: PropTypes.object.isRequired, file: PropTypes.object.isRequired, onInfoPress: PropTypes.func, onPreviewPress: PropTypes.func, theme: PropTypes.object.isRequired }; static defaultProps = { onInfoPress: () => true, onPreviewPress: () => true } renderFileInfo() { const {file, theme} = this.props; const style = getStyleSheet(theme); if (!file.id) { return null; } return ( {file.name.trim()} {`${file.extension.toUpperCase()} ${Utils.getFormattedFileSize(file)}`} ); } handlePreviewPress = () => { this.props.onPreviewPress(this.props.file); } render() { const {file, theme} = this.props; const style = getStyleSheet(theme); let fileAttachmentComponent; if (file.has_preview_image || file.loading || file.mime_type === 'image/gif') { fileAttachmentComponent = ( ); } else { fileAttachmentComponent = ( ); } return ( {fileAttachmentComponent} {this.renderFileInfo()} ); } } const getStyleSheet = makeStyleSheetFromTheme((theme) => { return { downloadIcon: { color: changeOpacity(theme.centerChannelColor, 0.7), marginRight: 5 }, fileDownloadContainer: { flexDirection: 'row', marginTop: 3 }, fileInfo: { marginLeft: 2, fontSize: 14, color: changeOpacity(theme.centerChannelColor, 0.5) }, fileInfoContainer: { flex: 1, paddingHorizontal: 8, paddingVertical: 5, borderLeftWidth: 1, borderLeftColor: changeOpacity(theme.centerChannelColor, 0.2) }, fileName: { flexDirection: 'column', flexWrap: 'wrap', marginLeft: 2, fontSize: 14, color: theme.centerChannelColor }, fileWrapper: { flex: 1, flexDirection: 'row', marginTop: 10, borderWidth: 1, borderColor: changeOpacity(theme.centerChannelColor, 0.2) } }; });