mirror of
https://github.com/flarum/framework.git
synced 2024-11-29 12:43:52 +08:00
NotificationList: Fix load on mobile
Followup to https://github.com/flarum/core/pull/2524. In that PR, we fixed infinite scroll for the panel, but accidentially used document.body. Since scrollTop on body is (almost always) 0, this means that new pages of notifications were loaded on every scroll, which quickly becomes overwhelming. Instead, we can use `document.documentElement` for getting scrollTop, which results in the expected behavior.
This commit is contained in:
parent
a008734b63
commit
35e7876f09
|
@ -114,11 +114,13 @@ export default class NotificationList extends Component {
|
||||||
scrollHandler() {
|
scrollHandler() {
|
||||||
const state = this.attrs.state;
|
const state = this.attrs.state;
|
||||||
|
|
||||||
const notificationsElement = this.inPanel() ? this.$scrollParent[0] : document.querySelector('body');
|
// Whole-page scroll events are listened to on `window`, but we need to get the actual
|
||||||
|
// scrollHeight, scrollTop, and clientHeight from the document element.
|
||||||
|
const scrollParent = this.inPanel() ? this.$scrollParent[0] : document.documentElement;
|
||||||
|
|
||||||
// On very short screens, the scrollHeight + scrollTop might not reach the clientHeight
|
// On very short screens, the scrollHeight + scrollTop might not reach the clientHeight
|
||||||
// by a fraction of a pixel, so we compensate for that.
|
// by a fraction of a pixel, so we compensate for that.
|
||||||
const atBottom = Math.abs(notificationsElement.scrollHeight - notificationsElement.scrollTop - notificationsElement.clientHeight) <= 1;
|
const atBottom = Math.abs(scrollParent.scrollHeight - scrollParent.scrollTop - scrollParent.clientHeight) <= 1;
|
||||||
|
|
||||||
if (state.hasMoreResults() && !state.isLoading() && atBottom) {
|
if (state.hasMoreResults() && !state.isLoading() && atBottom) {
|
||||||
state.loadMore();
|
state.loadMore();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user