From e1853c6682feef5b051247bc604dfbd330b05ddf Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 11 Jan 2019 12:59:44 -0300 Subject: [PATCH] MM-13665 Prevent quick multiple taps on file to open multiple file previews (#2503) --- .../file_attachment_list/file_attachment_document.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/components/file_attachment_list/file_attachment_document.js b/app/components/file_attachment_list/file_attachment_document.js index 91b4398ac..87c147665 100644 --- a/app/components/file_attachment_list/file_attachment_document.js +++ b/app/components/file_attachment_list/file_attachment_document.js @@ -66,13 +66,14 @@ export default class FileAttachmentDocument extends PureComponent { state = { didCancel: false, downloading: false, + preview: false, progress: 0, }; componentDidMount() { this.mounted = true; this.eventEmitter = new NativeEventEmitter(NativeModules.RNReactNativeDocViewer); - this.eventEmitter.addListener('DoneButtonEvent', () => this.setStatusBarColor()); + this.eventEmitter.addListener('DoneButtonEvent', this.onDonePreviewingFile); } componentWillUnmount() { @@ -223,15 +224,21 @@ export default class FileAttachmentDocument extends PureComponent { }, delay); }; + onDonePreviewingFile = () => { + this.setState({preview: false}); + this.setStatusBarColor(); + }; + openDocument = (file, delay = 2000) => { // The animation for the progress circle takes about 2 seconds to finish // therefore we are delaying the opening of the document to have the UI // shown nicely and smooth setTimeout(() => { - if (!this.state.didCancel && this.mounted) { + if (!this.state.didCancel && !this.state.preview && this.mounted) { const {data} = file; const prefix = Platform.OS === 'android' ? 'file:/' : ''; const path = `${DOCUMENTS_PATH}/${data.id}-${file.caption}`; + this.setState({preview: true}); this.setStatusBarColor('dark-content'); OpenFile.openDoc([{ url: `${prefix}${path}`,