Various iOS scroll improvements (#2548)

* 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
This commit is contained in:
Alexander Skvortsov 2021-02-17 10:36:30 -05:00 committed by GitHub
parent 73a8efaec2
commit 09076e005b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -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

View File

@ -1,3 +1,4 @@
import { throttle } from 'lodash-es';
import anchorScroll from '../../common/utils/anchorScroll';
class PostStreamState {
@ -49,6 +50,9 @@ class PostStreamState {
*/
this.forceUpdateScrubber = false;
this.loadNext = throttle(this._loadNext, 300);
this.loadPrevious = throttle(this._loadPrevious, 300);
this.show(includedPosts);
}
@ -187,7 +191,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));
@ -210,7 +214,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));