[FIX] Check if room is mounted before setting state (#864)

* Tweaks on sequential threads messages

* Update tests

* Fix quote

* Prevent from deleting thread start message when positioned inside the thread

* Remove thread listener from RightButtons

* Fix error on thread start parse

* Stop parsing threads on render

* Check replied thread only if necessary

* Fix messages don't displaying

* Fix threads e2e

* RoomsListView.updateState slice

* Stop fetching hidden messages on threads

* Check if RoomView is mounted before rendering

* Refactor navigation events on RoomsListView

* Fix lint

* Fix listener
This commit is contained in:
Diego Mello 2019-05-03 11:54:57 -03:00 committed by GitHub
parent a243b1ccd7
commit 2492371b50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

View File

@ -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 {

View File

@ -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 ? <ServerDropdown /> : null}
<NavigationEvents
onDidFocus={() => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)}
onWillBlur={() => BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress)}
/>
</SafeAreaView>
);
}