mattermost-mobile/app/components/file_attachment_list/file_attachment.js
Chris Duarte 2638a9c75d PLT-5517 Image file previewer (#344)
* PLT-5517 RN: Image file previewer

Add preview component and client routes
Add fade transition for modal
Add paging controls, title header, and info footer
Add drag to dismiss behavior
Fix android layout issues
Handle orientation change

* Fix tests

* Review feedback

* Review feedback
2017-03-17 09:04:35 -04:00

122 lines
3.3 KiB
JavaScript

// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React, {
PropTypes,
PureComponent
} from 'react';
import {
Text,
View,
StyleSheet
} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import * as Utils from 'mattermost-redux/utils/file_utils.js';
import FileAttachmentIcon from './file_attachment_icon';
import FileAttachmentPreview from './file_attachment_preview';
export default class FileAttachment extends PureComponent {
static propTypes = {
file: PropTypes.object.isRequired,
theme: PropTypes.object.isRequired
};
renderFileInfo() {
const {file, theme} = this.props;
const style = getStyleSheet(theme);
return (
<View style={style.fileInfoContainer}>
<Text
numberOfLines={4}
style={style.fileName}
>
{file.name.trim()}
</Text>
<View style={style.fileDownloadContainer}>
<Icon
name='download'
size={16}
style={style.downloadIcon}
/>
<Text style={style.fileInfo}>
{`${file.extension.toUpperCase()} ${Utils.getFormattedFileSize(file)}`}
</Text>
</View>
</View>
);
}
render() {
const {file, theme} = this.props;
const style = getStyleSheet(theme);
let fileAttachmentComponent;
if (file.has_preview_image) {
fileAttachmentComponent = (
<FileAttachmentPreview
file={file}
theme={theme}
/>
);
} else {
fileAttachmentComponent = (
<FileAttachmentIcon
file={file}
theme={theme}
/>
);
}
return (
<View style={style.fileWrapper}>
{fileAttachmentComponent}
{this.renderFileInfo()}
</View>
);
}
}
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
return StyleSheet.create({
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)
}
});
});