Browse Source

Remove onScroll for perf

master
Gaëtan Renaudeau 7 years ago
parent
commit
a18c04a0af
  1. 1
      src/components/SettingsPage/sections/Currencies.js
  2. 48
      src/components/base/GrowScroll/index.js
  3. 13
      src/components/layout/Default.js

1
src/components/SettingsPage/sections/Currencies.js

@ -145,5 +145,4 @@ class TabCurrencies extends PureComponent<Props, State> {
} }
} }
// $FlowFixMe not sure what's wrong
export default connect(mapStateToProps)(TabCurrencies) export default connect(mapStateToProps)(TabCurrencies)

48
src/components/base/GrowScroll/index.js

@ -5,7 +5,6 @@
import React, { PureComponent } from 'react' import React, { PureComponent } from 'react'
import Scrollbar from 'react-smooth-scrollbar' import Scrollbar from 'react-smooth-scrollbar'
import SmoothScrollbar, { ScrollbarPlugin } from 'smooth-scrollbar' import SmoothScrollbar, { ScrollbarPlugin } from 'smooth-scrollbar'
import noop from 'lodash/noop'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -13,42 +12,55 @@ type Props = {
children: any, children: any,
full: boolean, full: boolean,
maxHeight?: number, maxHeight?: number,
onUpdate: Function, onUpdate?: (*) => void,
onScroll: Function, onScroll?: () => void,
} }
// TODO this component is the source of junky scroll experience. need better solution ASAP
class GrowScroll extends PureComponent<Props> { class GrowScroll extends PureComponent<Props> {
static defaultProps = { static defaultProps = {
full: false, full: false,
onUpdate: noop,
onScroll: noop,
} }
componentDidMount() { componentDidMount() {
this.handleUpdate(this.props) const { onUpdate, onScroll } = this.props
const { _scrollbar } = this
if (this._scrollbar) { if (_scrollbar) {
this._scrollbar.addListener(this.props.onScroll) if (onUpdate) {
onUpdate(_scrollbar)
}
if (onScroll) {
_scrollbar.addListener(this.onScroll)
}
} }
} }
componentWillUnmount() { componentWillUnmount() {
if (this._scrollbar) { const { onScroll } = this.props
this._scrollbar.removeListener(this.props.onScroll) const { _scrollbar } = this
if (_scrollbar && onScroll) {
_scrollbar.removeListener(this.onScroll)
} }
} }
componenDidUpdate() { componenDidUpdate() {
this.handleUpdate(this.props) const { onUpdate } = this.props
const { _scrollbar } = this
if (_scrollbar && onUpdate) {
onUpdate(_scrollbar)
}
} }
handleUpdate = (props: Props) => { onScroll = () => {
if (this._scrollbar) { const { onScroll } = this.props
props.onUpdate(this._scrollbar) if (onScroll) onScroll()
} }
onRef = (ref: ?Scrollbar) => {
this._scrollbar = ref && ref.scrollbar
} }
_scrollbar = undefined _scrollbar: *
render() { render() {
const { onUpdate, children, maxHeight, full, ...props } = this.props const { onUpdate, children, maxHeight, full, ...props } = this.props
@ -79,7 +91,7 @@ class GrowScroll extends PureComponent<Props> {
top: 0, top: 0,
}), }),
}} }}
ref={r => r && (this._scrollbar = r.scrollbar)} ref={this.onRef}
> >
<Box {...props}>{children}</Box> <Box {...props}>{children}</Box>
</Scrollbar> </Scrollbar>

13
src/components/layout/Default.js

@ -50,17 +50,6 @@ class Default extends Component<Props> {
clearTimeout(this._timeout) clearTimeout(this._timeout)
} }
handleScroll = () => {
document.querySelectorAll('.tippy-popper').forEach((p: any) => {
const instance = p._tippy
if (instance.state.visible) {
instance.popperInstance.disableEventListeners()
instance.hide(0)
}
})
}
_timeout = undefined _timeout = undefined
_scrollContainer = null _scrollContainer = null
@ -79,7 +68,7 @@ class Default extends Component<Props> {
<Box shrink grow bg="lightGrey" color="grey" relative> <Box shrink grow bg="lightGrey" color="grey" relative>
<TopBar /> <TopBar />
<Container innerRef={n => (this._scrollContainer = n)} onScroll={this.handleScroll}> <Container innerRef={n => (this._scrollContainer = n)}>
<Route path="/" exact component={DashboardPage} /> <Route path="/" exact component={DashboardPage} />
<Route path="/settings" component={SettingsPage} /> <Route path="/settings" component={SettingsPage} />
<Route path="/manager" component={ManagerPage} /> <Route path="/manager" component={ManagerPage} />

Loading…
Cancel
Save