From fac0958b8bd04d31f40f61e9eb9dc953b4f4d2ec Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Fri, 28 Feb 2020 13:18:45 -0300 Subject: [PATCH] [FIX] Stop video when modal is closed (#1787) Co-authored-by: Diego Mello --- app/views/AttachmentView.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/views/AttachmentView.js b/app/views/AttachmentView.js index e89893d20..51646896e 100644 --- a/app/views/AttachmentView.js +++ b/app/views/AttachmentView.js @@ -65,8 +65,22 @@ class AttachmentView extends React.Component { componentDidMount() { const { navigation } = this.props; navigation.setParams({ handleSave: this.handleSave }); + + this.willBlurListener = navigation.addListener('willBlur', () => { + if (this.videoRef && this.videoRef.stopAsync) { + this.videoRef.stopAsync(); + } + }); } + componentWillUnmount() { + if (this.willBlurListener && this.willBlurListener.remove) { + this.willBlurListener.remove(); + } + } + + getVideoRef = ref => this.videoRef = ref; + handleSave = async() => { const { attachment } = this.state; const { user, baseUrl } = this.props; @@ -117,6 +131,7 @@ class AttachmentView extends React.Component { useNativeControls onLoad={() => this.setState({ loading: false })} onError={console.log} + ref={this.getVideoRef} /> );