0
0
Fork 0

Performance improvements (#3168)

* refactor(components/status_list): Avoid quering scrollTop if not necessary

* refactor(components/dropdown_menu): Do not render items if not expanded

* refactor: Cherry-pick react-motion imports

* refactor(compose/privacy_dropdown): Do not render options if not open

* refactor(components/column_collapsable): Do not render children if collapsed
This commit is contained in:
Sorin Davidoi 2017-05-20 14:58:13 +02:00 committed by Eugen Rochko
parent da0a18a318
commit 2c405aed55
15 changed files with 73 additions and 20 deletions

View file

@ -1,5 +1,6 @@
import React from 'react';
import { Motion, spring } from 'react-motion';
import Motion from 'react-motion/lib/Motion';
import spring from 'react-motion/lib/spring';
import PropTypes from 'prop-types';
const Collapsable = ({ fullHeight, isVisible, children }) => (

View file

@ -36,7 +36,7 @@ class ColumnCollapsable extends React.PureComponent {
</div>
<div className='column-collapsable__content' style={{ height: `${fullHeight}px` }}>
{children}
{!collapsed && children}
</div>
</div>
);

View file

@ -21,7 +21,8 @@ class DropdownMenu extends React.PureComponent {
};
state = {
direction: 'left'
direction: 'left',
expanded: false,
};
setRef = (c) => {
@ -43,6 +44,10 @@ class DropdownMenu extends React.PureComponent {
this.dropdown.hide();
}
handleShow = () => this.setState({ expanded: true })
handleHide = () => this.setState({ expanded: false })
renderItem = (item, i) => {
if (item === null) {
return <li key={ 'sep' + i } className='dropdown__sep' />;
@ -61,18 +66,23 @@ class DropdownMenu extends React.PureComponent {
render () {
const { icon, items, size, direction, ariaLabel } = this.props;
const { expanded } = this.state;
const directionClass = (direction === "left") ? "dropdown__left" : "dropdown__right";
const dropdownItems = expanded && (
<ul className='dropdown__content-list'>
{items.map(this.renderItem)}
</ul>
);
return (
<Dropdown ref={this.setRef}>
<Dropdown ref={this.setRef} onShow={this.handleShow} onHide={this.handleHide}>
<DropdownTrigger className='icon-button' style={{ fontSize: `${size}px`, width: `${size}px`, lineHeight: `${size}px` }} aria-label={ariaLabel}>
<i className={ `fa fa-fw fa-${icon} dropdown__icon` } aria-hidden={true} />
</DropdownTrigger>
<DropdownContent className={directionClass}>
<ul className='dropdown__content-list'>
{items.map(this.renderItem)}
</ul>
{dropdownItems}
</DropdownContent>
</Dropdown>
);

View file

@ -1,5 +1,6 @@
import React from 'react';
import { Motion, spring } from 'react-motion';
import Motion from 'react-motion/lib/Motion';
import spring from 'react-motion/lib/spring';
import PropTypes from 'prop-types';
class IconButton extends React.PureComponent {

View file

@ -46,7 +46,7 @@ class StatusList extends ImmutablePureComponent {
}
componentDidUpdate (prevProps) {
if (this.node.scrollTop > 0 && (prevProps.statusIds.size < this.props.statusIds.size && prevProps.statusIds.first() !== this.props.statusIds.first() && !!this._oldScrollPosition)) {
if ((prevProps.statusIds.size < this.props.statusIds.size && prevProps.statusIds.first() !== this.props.statusIds.first() && !!this._oldScrollPosition) && this.node.scrollTop > 0) {
this.node.scrollTop = this.node.scrollHeight - this._oldScrollPosition;
}
}