[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:
parent
a243b1ccd7
commit
2492371b50
|
@ -122,6 +122,8 @@ export default class RoomView extends LoggedView {
|
||||||
this.beginAnimatingTimeout = setTimeout(() => this.beginAnimating = true, 300);
|
this.beginAnimatingTimeout = setTimeout(() => this.beginAnimating = true, 300);
|
||||||
this.messagebox = React.createRef();
|
this.messagebox = React.createRef();
|
||||||
safeAddListener(this.rooms, this.updateRoom);
|
safeAddListener(this.rooms, this.updateRoom);
|
||||||
|
this.willBlurListener = props.navigation.addListener('willBlur', () => this.mounted = false);
|
||||||
|
this.mounted = false;
|
||||||
console.timeEnd(`${ this.constructor.name } init`);
|
console.timeEnd(`${ this.constructor.name } init`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,6 +141,7 @@ export default class RoomView extends LoggedView {
|
||||||
} else {
|
} else {
|
||||||
EventEmitter.addEventListener('connected', this.handleConnected);
|
EventEmitter.addEventListener('connected', this.handleConnected);
|
||||||
}
|
}
|
||||||
|
this.mounted = true;
|
||||||
});
|
});
|
||||||
console.timeEnd(`${ this.constructor.name } mount`);
|
console.timeEnd(`${ this.constructor.name } mount`);
|
||||||
}
|
}
|
||||||
|
@ -188,6 +191,7 @@ export default class RoomView extends LoggedView {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
this.mounted = false;
|
||||||
const { editing, replying } = this.props;
|
const { editing, replying } = this.props;
|
||||||
if (!editing && this.messagebox && this.messagebox.current && this.messagebox.current.text) {
|
if (!editing && this.messagebox && this.messagebox.current && this.messagebox.current.text) {
|
||||||
const { text } = this.messagebox.current;
|
const { text } = this.messagebox.current;
|
||||||
|
@ -230,6 +234,9 @@ export default class RoomView extends LoggedView {
|
||||||
if (this.initInteraction && this.initInteraction.cancel) {
|
if (this.initInteraction && this.initInteraction.cancel) {
|
||||||
this.initInteraction.cancel();
|
this.initInteraction.cancel();
|
||||||
}
|
}
|
||||||
|
if (this.willBlurListener && this.willBlurListener.remove) {
|
||||||
|
this.willBlurListener.remove();
|
||||||
|
}
|
||||||
EventEmitter.removeListener('connected', this.handleConnected);
|
EventEmitter.removeListener('connected', this.handleConnected);
|
||||||
console.countReset(`${ this.constructor.name }.render calls`);
|
console.countReset(`${ this.constructor.name }.render calls`);
|
||||||
}
|
}
|
||||||
|
@ -293,6 +300,9 @@ export default class RoomView extends LoggedView {
|
||||||
}
|
}
|
||||||
|
|
||||||
internalSetState = (...args) => {
|
internalSetState = (...args) => {
|
||||||
|
if (!this.mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (isIOS && this.beginAnimating) {
|
if (isIOS && this.beginAnimating) {
|
||||||
LayoutAnimation.easeInEaseOut();
|
LayoutAnimation.easeInEaseOut();
|
||||||
}
|
}
|
||||||
|
@ -347,7 +357,7 @@ export default class RoomView extends LoggedView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setLastOpen = lastOpen => this.setState({ lastOpen });
|
setLastOpen = lastOpen => this.internalSetState({ lastOpen });
|
||||||
|
|
||||||
joinRoom = async() => {
|
joinRoom = async() => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { isEqual } from 'lodash';
|
import { isEqual } from 'lodash';
|
||||||
import { SafeAreaView, NavigationEvents } from 'react-navigation';
|
import { SafeAreaView } from 'react-navigation';
|
||||||
import Orientation from 'react-native-orientation-locker';
|
import Orientation from 'react-native-orientation-locker';
|
||||||
|
|
||||||
import database, { safeAddListener } from '../../lib/realm';
|
import database, { safeAddListener } from '../../lib/realm';
|
||||||
|
@ -134,6 +134,8 @@ export default class RoomsListView extends LoggedView {
|
||||||
livechat: []
|
livechat: []
|
||||||
};
|
};
|
||||||
Orientation.unlockAllOrientations();
|
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() {
|
componentDidMount() {
|
||||||
|
@ -210,6 +212,12 @@ export default class RoomsListView extends LoggedView {
|
||||||
if (this.updateStateInteraction && this.updateStateInteraction.cancel) {
|
if (this.updateStateInteraction && this.updateStateInteraction.cancel) {
|
||||||
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`);
|
console.countReset(`${ this.constructor.name }.render calls`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,10 +566,6 @@ export default class RoomsListView extends LoggedView {
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
{showServerDropdown ? <ServerDropdown /> : null}
|
{showServerDropdown ? <ServerDropdown /> : null}
|
||||||
<NavigationEvents
|
|
||||||
onDidFocus={() => BackHandler.addEventListener('hardwareBackPress', this.handleBackPress)}
|
|
||||||
onWillBlur={() => BackHandler.removeEventListener('hardwareBackPress', this.handleBackPress)}
|
|
||||||
/>
|
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue