diff --git a/app/containers/MessageBox/index.js b/app/containers/MessageBox/index.js index 39e29dbc7..7a0aedbae 100644 --- a/app/containers/MessageBox/index.js +++ b/app/containers/MessageBox/index.js @@ -183,7 +183,7 @@ class MessageBox extends Component { EventEmiter.addEventListener(KEY_COMMAND, this.handleCommands); } - this.didFocusListener = navigation.addListener('didFocus', () => { + this.unsubscribeFocus = navigation.addListener('focus', () => { if (this.tracking && this.tracking.resetTracking) { this.tracking.resetTracking(); } @@ -268,8 +268,8 @@ class MessageBox extends Component { if (this.getSlashCommands && this.getSlashCommands.stop) { this.getSlashCommands.stop(); } - if (this.didFocusListener && this.didFocusListener.remove) { - this.didFocusListener.remove(); + if (this.unsubscribeFocus) { + this.unsubscribeFocus(); } if (isTablet) { EventEmiter.removeListener(KEY_COMMAND, this.handleCommands); diff --git a/app/views/RoomInfoView/index.js b/app/views/RoomInfoView/index.js index 7576c81e2..5face08f0 100644 --- a/app/views/RoomInfoView/index.js +++ b/app/views/RoomInfoView/index.js @@ -83,7 +83,7 @@ class RoomInfoView extends React.Component { } const { navigation } = this.props; - this.willFocusListener = navigation.addListener('focus', () => { + this.unsubscribeFocus = navigation.addListener('focus', () => { if (this.isLivechat) { this.loadVisitor(); } @@ -94,8 +94,8 @@ class RoomInfoView extends React.Component { if (this.subscription && this.subscription.unsubscribe) { this.subscription.unsubscribe(); } - if (this.willFocusListener) { - this.willFocusListener(); + if (this.unsubscribeFocus) { + this.unsubscribeFocus(); } } diff --git a/app/views/RoomView/List.js b/app/views/RoomView/List.js index 51240c7a0..ff1bfe718 100644 --- a/app/views/RoomView/List.js +++ b/app/views/RoomView/List.js @@ -57,7 +57,7 @@ class List extends React.Component { animated: false }; this.init(); - this.didFocusListener = props.navigation.addListener('didFocus', () => { + this.unsubscribeFocus = props.navigation.addListener('focus', () => { if (this.mounted) { this.setState({ animated: true }); } else { @@ -163,8 +163,8 @@ class List extends React.Component { if (this.onEndReached && this.onEndReached.stop) { this.onEndReached.stop(); } - if (this.didFocusListener && this.didFocusListener.remove) { - this.didFocusListener.remove(); + if (this.unsubscribeFocus) { + this.unsubscribeFocus(); } console.countReset(`${ this.constructor.name }.render calls`); } diff --git a/app/views/ShareListView/index.js b/app/views/ShareListView/index.js index eb496d982..847535763 100644 --- a/app/views/ShareListView/index.js +++ b/app/views/ShareListView/index.js @@ -61,8 +61,8 @@ class ShareListView extends React.Component { serverInfo: null }; this.setHeader(); - this.didFocusListener = props.navigation.addListener('didFocus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)); - this.willBlurListener = props.navigation.addListener('willBlur', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)); + this.unsubscribeFocus = props.navigation.addListener('focus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)); + this.unsubscribeBlur = props.navigation.addListener('blur', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)); } componentDidMount() { @@ -129,6 +129,15 @@ class ShareListView extends React.Component { return false; } + componentWillUnmount() { + if (this.unsubscribeFocus) { + this.unsubscribeFocus(); + } + if (this.unsubscribeBlur) { + this.unsubscribeBlur(); + } + } + setHeader = () => { const { searching } = this.state; const { navigation, theme } = this.props;