From 2a54c00e16fb1be5654e94a86aba63c2b95d22a4 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Wed, 29 Aug 2018 17:05:37 -0300 Subject: [PATCH] Open file attachment preview when tapping on the filename (#2049) --- .../file_attachment_list/file_attachment.js | 16 +++++++++++----- .../file_attachment_list/file_attachment_list.js | 7 ------- app/components/post_body/post_body.js | 2 -- app/screens/long_post/long_post.js | 1 - 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/components/file_attachment_list/file_attachment.js b/app/components/file_attachment_list/file_attachment.js index 271eb65b7..2b6ebcb45 100644 --- a/app/components/file_attachment_list/file_attachment.js +++ b/app/components/file_attachment_list/file_attachment.js @@ -25,14 +25,12 @@ export default class FileAttachment extends PureComponent { file: PropTypes.object.isRequired, index: PropTypes.number.isRequired, onCaptureRef: PropTypes.func, - onInfoPress: PropTypes.func, onPreviewPress: PropTypes.func, theme: PropTypes.object.isRequired, navigator: PropTypes.object, }; static defaultProps = { - onInfoPress: () => true, onPreviewPress: () => true, }; @@ -45,7 +43,11 @@ export default class FileAttachment extends PureComponent { }; handlePreviewPress = () => { - this.props.onPreviewPress(this.props.index); + if (this.documentElement) { + this.documentElement.handlePreviewPress(); + } else { + this.props.onPreviewPress(this.props.index); + } }; renderFileInfo() { @@ -79,12 +81,15 @@ export default class FileAttachment extends PureComponent { ); } + setDocumentRef = (ref) => { + this.documentElement = ref; + }; + render() { const { canDownloadFiles, deviceWidth, file, - onInfoPress, theme, navigator, } = this.props; @@ -105,6 +110,7 @@ export default class FileAttachment extends PureComponent { } else if (isDocument(data)) { fileAttachmentComponent = ( {fileAttachmentComponent} {this.renderFileInfo()} diff --git a/app/components/file_attachment_list/file_attachment_list.js b/app/components/file_attachment_list/file_attachment_list.js index 6316096cf..3fbec8455 100644 --- a/app/components/file_attachment_list/file_attachment_list.js +++ b/app/components/file_attachment_list/file_attachment_list.js @@ -34,7 +34,6 @@ export default class FileAttachmentList extends Component { isFailed: PropTypes.bool, navigator: PropTypes.object, onLongPress: PropTypes.func, - onPress: PropTypes.func, postId: PropTypes.string.isRequired, theme: PropTypes.object.isRequired, toggleSelected: PropTypes.func.isRequired, @@ -125,11 +124,6 @@ export default class FileAttachmentList extends Component { this.items[idx] = ref; }; - handleInfoPress = () => { - this.props.hideOptionsContext(); - this.props.onPress(); - }; - handlePreviewPress = preventDoubleTap((idx) => { this.props.hideOptionsContext(); Keyboard.dismiss(); @@ -180,7 +174,6 @@ export default class FileAttachmentList extends Component { index={idx} navigator={navigator} onCaptureRef={this.handleCaptureRef} - onInfoPress={this.handleInfoPress} onPreviewPress={this.handlePreviewPress} theme={this.props.theme} /> diff --git a/app/components/post_body/post_body.js b/app/components/post_body/post_body.js index f2e6f1660..f5ef0166b 100644 --- a/app/components/post_body/post_body.js +++ b/app/components/post_body/post_body.js @@ -264,7 +264,6 @@ export default class PostBody extends PureComponent { fileIds, isFailed, navigator, - onPress, postId, showLongPost, toggleSelected, @@ -286,7 +285,6 @@ export default class PostBody extends PureComponent { hideOptionsContext={this.hideOptionsContext} isFailed={isFailed} onLongPress={this.showOptionsContext} - onPress={onPress} postId={postId} toggleSelected={toggleSelected} navigator={navigator} diff --git a/app/screens/long_post/long_post.js b/app/screens/long_post/long_post.js index 60f94b65f..973b25fbb 100644 --- a/app/screens/long_post/long_post.js +++ b/app/screens/long_post/long_post.js @@ -143,7 +143,6 @@ export default class LongPost extends PureComponent { hideOptionsContext={emptyFunction} isFailed={false} onLongPress={emptyFunction} - onPress={this.handlePress} postId={postId} toggleSelected={emptyFunction} navigator={navigator}