diff --git a/app/views/RoomView/index.js b/app/views/RoomView/index.js
index 082563187..58915b3c8 100644
--- a/app/views/RoomView/index.js
+++ b/app/views/RoomView/index.js
@@ -122,6 +122,8 @@ export default class RoomView extends LoggedView {
this.beginAnimatingTimeout = setTimeout(() => this.beginAnimating = true, 300);
this.messagebox = React.createRef();
safeAddListener(this.rooms, this.updateRoom);
+ this.willBlurListener = props.navigation.addListener('willBlur', () => this.mounted = false);
+ this.mounted = false;
console.timeEnd(`${ this.constructor.name } init`);
}
@@ -139,6 +141,7 @@ export default class RoomView extends LoggedView {
} else {
EventEmitter.addEventListener('connected', this.handleConnected);
}
+ this.mounted = true;
});
console.timeEnd(`${ this.constructor.name } mount`);
}
@@ -188,6 +191,7 @@ export default class RoomView extends LoggedView {
}
componentWillUnmount() {
+ this.mounted = false;
const { editing, replying } = this.props;
if (!editing && this.messagebox && this.messagebox.current && this.messagebox.current.text) {
const { text } = this.messagebox.current;
@@ -230,6 +234,9 @@ export default class RoomView extends LoggedView {
if (this.initInteraction && this.initInteraction.cancel) {
this.initInteraction.cancel();
}
+ if (this.willBlurListener && this.willBlurListener.remove) {
+ this.willBlurListener.remove();
+ }
EventEmitter.removeListener('connected', this.handleConnected);
console.countReset(`${ this.constructor.name }.render calls`);
}
@@ -293,6 +300,9 @@ export default class RoomView extends LoggedView {
}
internalSetState = (...args) => {
+ if (!this.mounted) {
+ return;
+ }
if (isIOS && this.beginAnimating) {
LayoutAnimation.easeInEaseOut();
}
@@ -347,7 +357,7 @@ export default class RoomView extends LoggedView {
}
}
- setLastOpen = lastOpen => this.setState({ lastOpen });
+ setLastOpen = lastOpen => this.internalSetState({ lastOpen });
joinRoom = async() => {
try {
diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js
index a1a42124e..aa21eb0ce 100644
--- a/app/views/RoomsListView/index.js
+++ b/app/views/RoomsListView/index.js
@@ -5,7 +5,7 @@ import {
} from 'react-native';
import { connect } from 'react-redux';
import { isEqual } from 'lodash';
-import { SafeAreaView, NavigationEvents } from 'react-navigation';
+import { SafeAreaView } from 'react-navigation';
import Orientation from 'react-native-orientation-locker';
import database, { safeAddListener } from '../../lib/realm';
@@ -134,6 +134,8 @@ export default class RoomsListView extends LoggedView {
livechat: []
};
Orientation.unlockAllOrientations();
+ this.didFocusListener = props.navigation.addListener('didFocus', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
+ this.willBlurListener = props.navigation.addListener('willBlur', () => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress));
}
componentDidMount() {
@@ -210,6 +212,12 @@ export default class RoomsListView extends LoggedView {
if (this.updateStateInteraction && this.updateStateInteraction.cancel) {
this.updateStateInteraction.cancel();
}
+ if (this.didFocusListener && this.didFocusListener.remove) {
+ this.didFocusListener.remove();
+ }
+ if (this.willBlurListener && this.willBlurListener.remove) {
+ this.willBlurListener.remove();
+ }
console.countReset(`${ this.constructor.name }.render calls`);
}
@@ -558,10 +566,6 @@ export default class RoomsListView extends LoggedView {
: null
}
{showServerDropdown ? : null}
- BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)}
- onWillBlur={() => BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress)}
- />
);
}