|
|
|
@ -65,6 +65,22 @@ export default class ScrollableList extends PureComponent { |
|
|
|
|
this.handleScroll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getScrollPosition = () => { |
|
|
|
|
if (this.node && this.node.scrollTop > 0) { |
|
|
|
|
return {height: this.node.scrollHeight, top: this.node.scrollTop}; |
|
|
|
|
} else { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
updateScrollBottom = (snapshot) => { |
|
|
|
|
const newScrollTop = this.node.scrollHeight - snapshot; |
|
|
|
|
|
|
|
|
|
if (this.node.scrollTop !== newScrollTop) { |
|
|
|
|
this.node.scrollTop = newScrollTop; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getSnapshotBeforeUpdate (prevProps, prevState) { |
|
|
|
|
const someItemInserted = React.Children.count(prevProps.children) > 0 && |
|
|
|
|
React.Children.count(prevProps.children) < React.Children.count(this.props.children) && |
|
|
|
@ -79,13 +95,7 @@ export default class ScrollableList extends PureComponent { |
|
|
|
|
componentDidUpdate (prevProps, prevState, snapshot) { |
|
|
|
|
// Reset the scroll position when a new child comes in in order not to
|
|
|
|
|
// jerk the scrollbar around if you're already scrolled down the page.
|
|
|
|
|
if (snapshot !== null) { |
|
|
|
|
const newScrollTop = this.node.scrollHeight - snapshot; |
|
|
|
|
|
|
|
|
|
if (this.node.scrollTop !== newScrollTop) { |
|
|
|
|
this.node.scrollTop = newScrollTop; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (snapshot !== null) this.updateScrollBottom(snapshot); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
componentWillUnmount () { |
|
|
|
@ -160,7 +170,7 @@ export default class ScrollableList extends PureComponent { |
|
|
|
|
intersectionObserverWrapper={this.intersectionObserverWrapper} |
|
|
|
|
saveHeightKey={trackScroll ? `${this.context.router.route.location.key}:${scrollKey}` : null} |
|
|
|
|
> |
|
|
|
|
{child} |
|
|
|
|
{React.cloneElement(child, {getScrollPosition: this.getScrollPosition, updateScrollBottom: this.updateScrollBottom})} |
|
|
|
|
</IntersectionObserverArticleContainer> |
|
|
|
|
))} |
|
|
|
|
|
|
|
|
|