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 { ...@@ -78,19 +78,23 @@ class Info extends Component {
if (!this.main) { if (!this.main) {
return; return;
} }
requestAnimationFrame(() => {
const { mode: currentMode } = this.state;
let mode = 'inline'; let mode = 'inline';
const { offsetWidth } = this.main; const { offsetWidth } = this.main;
if (offsetWidth < 641 && offsetWidth > 400) {
if (offsetWidth > 400 && offsetWidth < 641) {
mode = 'horizontal'; mode = 'horizontal';
} }
if (window.innerWidth < 768 && offsetWidth > 400) { if (window.innerWidth < 768 && offsetWidth > 400) {
mode = 'horizontal'; mode = 'horizontal';
} }
this.setState({
mode, if (mode !== currentMode) {
}); requestAnimationFrame(() => this.setState({ mode }));
}); }
}; };
render() { 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