[IMPROVEMENT] Use class variable instead of state for List's animated (#2718)

This commit is contained in:
Diego Mello 2020-12-17 09:56:53 -03:00 committed by GitHub
parent 2f3a24824f
commit a34807d3cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 9 deletions

View File

@ -53,20 +53,16 @@ class List extends React.Component {
this.count = 0; this.count = 0;
this.needsFetch = false; this.needsFetch = false;
this.mounted = false; this.mounted = false;
this.animated = false;
this.state = { this.state = {
loading: true, loading: true,
end: false, end: false,
messages: [], messages: [],
refreshing: false, refreshing: false
animated: false
}; };
this.query(); this.query();
this.unsubscribeFocus = props.navigation.addListener('focus', () => { this.unsubscribeFocus = props.navigation.addListener('focus', () => {
if (this.mounted) { this.animated = true;
this.setState({ animated: true });
} else {
this.state.animated = true;
}
}); });
console.timeEnd(`${ this.constructor.name } init`); console.timeEnd(`${ this.constructor.name } init`);
} }
@ -290,8 +286,7 @@ class List extends React.Component {
// eslint-disable-next-line react/sort-comp // eslint-disable-next-line react/sort-comp
update = () => { update = () => {
const { animated } = this.state; if (this.animated) {
if (animated) {
animateNextTransition(); animateNextTransition();
} }
this.forceUpdate(); this.forceUpdate();