-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathAttachmentView.js
executable file
·84 lines (74 loc) · 2.51 KB
/
AttachmentView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, {memo} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import Str from 'expensify-common/lib/str';
import styles from '../styles/styles';
import PDFView from './PDFView';
import ImageView from './ImageView';
import Icon from './Icon';
import {Paperclip, Download} from './Icon/Expensicons';
import withLocalize, {withLocalizePropTypes} from './withLocalize';
import compose from '../libs/compose';
import Text from './Text';
import Tooltip from './Tooltip';
const propTypes = {
/** URL to full-sized attachment */
sourceURL: PropTypes.string.isRequired,
/** File object maybe be instance of File or Object */
file: PropTypes.shape({
name: PropTypes.string,
}),
/** Flag to show/hide download icon */
shouldShowDownloadIcon: PropTypes.bool,
...withLocalizePropTypes,
};
const defaultProps = {
file: {
name: '',
},
shouldShowDownloadIcon: false,
};
const AttachmentView = (props) => {
// Check both sourceURL and file.name since PDFs dragged into the the text field
// will appear with a sourceURL that is a blob
if (Str.isPDF(props.sourceURL)
|| (props.file && Str.isPDF(props.file.name || props.translate('attachmentView.unknownFilename')))) {
return (
<PDFView
sourceURL={props.sourceURL}
style={styles.imageModalPDF}
/>
);
}
// For this check we use both sourceURL and file.name since temporary file sourceURL is a blob
// both PDFs and images will appear as images when pasted into the the text field
if (Str.isImage(props.sourceURL) || (props.file && Str.isImage(props.file.name))) {
return (
<ImageView url={props.sourceURL} />
);
}
return (
<View
style={styles.defaultAttachmentView}
>
<View style={styles.mr2}>
<Icon src={Paperclip} />
</View>
<Text style={[styles.textStrong]}>{props.file && props.file.name}</Text>
{props.shouldShowDownloadIcon && (
<Tooltip text={props.translate('common.download')}>
<View style={styles.ml2}>
<Icon src={Download} />
</View>
</Tooltip>
)}
</View>
);
};
AttachmentView.propTypes = propTypes;
AttachmentView.defaultProps = defaultProps;
AttachmentView.displayName = 'AttachmentView';
export default compose(
memo,
withLocalize,
)(AttachmentView);