Commit 03db6495 authored by Hilmi Erdem KEREN's avatar Hilmi Erdem KEREN Committed by 陈帅

requestAnimationFrame optimization (#4115)

* requestAnimationFrame optimization

Optimizes animation by doing the following changes:

- Moves offsetWidth, innerWidth like expensive calculations out of requestAnimationFrame
- Adds menu mode change control before requesting the animation frame

* fix: Uses object destructuring to read state property
parent 257f0979
......@@ -78,19 +78,23 @@ class Info extends Component {
if (!this.main) {
return;
}
requestAnimationFrame(() => {
let mode = 'inline';
const { offsetWidth } = this.main;
if (offsetWidth < 641 && offsetWidth > 400) {
mode = 'horizontal';
}
if (window.innerWidth < 768 && offsetWidth > 400) {
mode = 'horizontal';
}
this.setState({
mode,
});
});
const { mode: currentMode } = this.state;
let mode = 'inline';
const { offsetWidth } = this.main;
if (offsetWidth > 400 && offsetWidth < 641) {
mode = 'horizontal';
}
if (window.innerWidth < 768 && offsetWidth > 400) {
mode = 'horizontal';
}
if (mode !== currentMode) {
requestAnimationFrame(() => this.setState({ mode }));
}
};
render() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment