// Shared by Mail, Contacts and Files. Wait for the next committed revision and // settled ListView geometry before requesting another page. Errors retry only // after a fresh user gesture, preventing an automatic request loop. export component InfiniteScrollController inherits Rectangle { width: 0px; height: 0px; in property active: true; in property can-load-more; in property loading; in property row-count; in property revision; in property content-height; in property content-y; in property visible-height; in property prefetch-distance: 246px; callback load-more; private property armed: true; private property request-rows: -1; private property request-revision: -1; private property request-height: -1px; function check() { if root.active && root.visible-height > 0px && root.can-load-more && !root.loading && root.armed && root.content-height + root.content-y - root.visible-height <= root.prefetch-distance { root.armed = false; root.request-rows = root.row-count; root.request-revision = root.revision; root.request-height = root.content-height; root.load-more(); } } public function reset() { root.armed = true; root.request-rows = -1; root.request-revision = -1; root.request-height = -1px; check-timer.restart(); } public function user-scrolled() { if !root.loading && !root.armed && root.revision == root.request-revision { root.armed = true; } root.check(); } changed content-height => { if !root.armed && root.revision != root.request-revision && root.content-height != root.request-height { root.armed = true; } check-timer.restart(); } changed revision => { if !root.armed && root.revision != root.request-revision && (root.row-count == root.request-rows || root.content-height != root.request-height) { root.armed = true; } check-timer.restart(); } changed can-load-more => { check-timer.restart(); } changed loading => { if !root.loading { check-timer.restart(); } } changed active => { check-timer.restart(); } changed visible-height => { check-timer.restart(); } check-timer := Timer { interval: 1ms; running: true; triggered => { self.stop(); root.check(); } } }