Skip to content

Commit

Permalink
Revert "Temporarily hold timeline if mouse moved recently (fixes #8630)…
Browse files Browse the repository at this point in the history
… (#9200)"

This reverts commit 6a1216d.
  • Loading branch information
Gargron committed Nov 7, 2018
1 parent 57b03f9 commit 1198c0a
Showing 1 changed file with 2 additions and 48 deletions.
50 changes: 2 additions & 48 deletions app/javascript/mastodon/components/scrollable_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { List as ImmutableList } from 'immutable';
import classNames from 'classnames';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../features/ui/util/fullscreen';

const MOUSE_IDLE_DELAY = 300;

export default class ScrollableList extends PureComponent {

static contextTypes = {
Expand Down Expand Up @@ -39,8 +37,6 @@ export default class ScrollableList extends PureComponent {

state = {
fullscreen: null,
mouseMovedRecently: false,
scrollToTopOnMouseIdle: false,
};

intersectionObserverWrapper = new IntersectionObserverWrapper();
Expand All @@ -64,47 +60,6 @@ export default class ScrollableList extends PureComponent {
trailing: true,
});

mouseIdleTimer = null;

clearMouseIdleTimer = () => {
if (this.mouseIdleTimer === null) {
return;
}
clearTimeout(this.mouseIdleTimer);
this.mouseIdleTimer = null;
};

handleMouseMove = throttle(() => {
// As long as the mouse keeps moving, clear and restart the idle timer.
this.clearMouseIdleTimer();
this.mouseIdleTimer =
setTimeout(this.handleMouseIdle, MOUSE_IDLE_DELAY);

this.setState(({
mouseMovedRecently,
scrollToTopOnMouseIdle,
}) => ({
mouseMovedRecently: true,
// Only set scrollToTopOnMouseIdle if we just started moving and were
// scrolled to the top. Otherwise, just retain the previous state.
scrollToTopOnMouseIdle:
mouseMovedRecently
? scrollToTopOnMouseIdle
: (this.node.scrollTop === 0),
}));
}, MOUSE_IDLE_DELAY / 2);

handleMouseIdle = () => {
if (this.state.scrollToTopOnMouseIdle) {
this.node.scrollTop = 0;
this.props.onScrollToTop();
}
this.setState({
mouseMovedRecently: false,
scrollToTopOnMouseIdle: false,
});
}

componentDidMount () {
this.attachScrollListener();
this.attachIntersectionObserver();
Expand All @@ -118,7 +73,7 @@ export default class ScrollableList extends PureComponent {
const someItemInserted = React.Children.count(prevProps.children) > 0 &&
React.Children.count(prevProps.children) < React.Children.count(this.props.children) &&
this.getFirstChildKey(prevProps) !== this.getFirstChildKey(this.props);
if ((someItemInserted && this.node.scrollTop > 0) || this.state.mouseMovedRecently) {
if (someItemInserted && this.node.scrollTop > 0) {
return this.node.scrollHeight - this.node.scrollTop;
} else {
return null;
Expand All @@ -138,7 +93,6 @@ export default class ScrollableList extends PureComponent {
}

componentWillUnmount () {
this.clearMouseIdleTimer();
this.detachScrollListener();
this.detachIntersectionObserver();
detachFullscreenListener(this.onFullScreenChange);
Expand Down Expand Up @@ -197,7 +151,7 @@ export default class ScrollableList extends PureComponent {

if (isLoading || childrenCount > 0 || !emptyMessage) {
scrollableArea = (
<div className={classNames('scrollable', { fullscreen })} ref={this.setRef} onMouseMove={this.handleMouseMove}>
<div className={classNames('scrollable', { fullscreen })} ref={this.setRef}>
<div role='feed' className='item-list'>
{prepend}

Expand Down

0 comments on commit 1198c0a

Please sign in to comment.