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:
parent
da0a18a318
commit
2c405aed55
15 changed files with 73 additions and 20 deletions
|
@ -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 }) => (
|
||||
|
|
|
@ -36,7 +36,7 @@ class ColumnCollapsable extends React.PureComponent {
|
|||
</div>
|
||||
|
||||
<div className='column-collapsable__content' style={{ height: `${fullHeight}px` }}>
|
||||
{children}
|
||||
{!collapsed && children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue