Skip to content

Commit

Permalink
Various iOS scroll improvements (#2548)
Browse files Browse the repository at this point in the history
* Don't update scrubber while post pages loading

This alleviates the scrubber bouncing around when scrolling up on iOS

* Throttle loadMore loadPrevious

Throttle loadMore and loadPrevious functions to alleviate skipping over pages and pages of posts during one scroll. This sometimes happens on iOS
  • Loading branch information
askvortsov1 authored and KyrneDev committed Feb 20, 2021
1 parent e02a5c7 commit 64a0e69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 1 addition & 3 deletions js/src/forum/components/PostStream.js
Expand Up @@ -146,12 +146,10 @@ export default class PostStream extends Component {
* @param {Integer} top
*/
onscroll(top = window.pageYOffset) {
if (this.stream.paused) return;
if (this.stream.paused || this.stream.pagesLoading) return;

this.updateScrubber(top);

if (this.stream.pagesLoading) return;

this.loadPostsIfNeeded(top);

// Throttle calculation of our position (start/end numbers of posts in the
Expand Down
8 changes: 6 additions & 2 deletions js/src/forum/states/PostStreamState.js
@@ -1,3 +1,4 @@
import { throttle } from 'lodash-es';
import anchorScroll from '../../common/utils/anchorScroll';

class PostStreamState {
Expand Down Expand Up @@ -50,6 +51,9 @@ class PostStreamState {
*/
this.forceUpdateScrubber = false;

this.loadNext = throttle(this._loadNext, 300);
this.loadPrevious = throttle(this._loadPrevious, 300);

this.show(includedPosts);
}

Expand Down Expand Up @@ -189,7 +193,7 @@ class PostStreamState {
/**
* Load the next page of posts.
*/
loadNext() {
_loadNext() {
const start = this.visibleEnd;
const end = (this.visibleEnd = this.sanitizeIndex(this.visibleEnd + this.constructor.loadCount));

Expand All @@ -212,7 +216,7 @@ class PostStreamState {
/**
* Load the previous page of posts.
*/
loadPrevious() {
_loadPrevious() {
const end = this.visibleStart;
const start = (this.visibleStart = this.sanitizeIndex(this.visibleStart - this.constructor.loadCount));

Expand Down

0 comments on commit 64a0e69

Please sign in to comment.