Skip to content

Commit a5d9343

Browse files
committed
fix inertia issue
1 parent a3f29a7 commit a5d9343

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/modules/viewport.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,20 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
178178
},
179179

180180
onAfterPrepend(updates) {
181-
if (!updates.prepended.length)
181+
if (!updates.prepended.length) {
182182
return;
183+
}
183184
const height = buffer.effectiveHeight(updates.prepended);
184185
const paddingHeight = topPadding.height() - height;
185186
if (paddingHeight >= 0) {
186187
topPadding.height(paddingHeight);
188+
return;
187189
}
188-
else {
189-
topPadding.height(0);
190-
viewport.scrollTop(viewport.scrollTop() - paddingHeight);
191-
}
190+
const currentPosition = viewport.scrollTop();
191+
const newPosition = currentPosition - paddingHeight;
192+
topPadding.height(0);
193+
viewport.synthetic = { position: newPosition };
194+
viewport.scrollTop(newPosition);
192195
},
193196

194197
resetTopPadding() {

src/ui-scroll.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,25 @@ angular.module('ui.scroll', [])
485485
}
486486
}
487487

488+
function fixInertia() {
489+
if (!viewport.synthetic) {
490+
return;
491+
}
492+
const position = viewport.synthetic.position;
493+
if (viewport.scrollTop() !== position) {
494+
requestAnimationFrame(() => {
495+
viewport.scrollTop(position);
496+
viewport.synthetic = null;
497+
});
498+
return true;
499+
}
500+
viewport.synthetic = null;
501+
}
502+
488503
function resizeAndScrollHandler() {
504+
if (fixInertia()) {
505+
return;
506+
}
489507
if (!$rootScope.$$phase && !adapter.isLoading && !adapter.disabled) {
490508

491509
enqueueFetch(ridActual);

0 commit comments

Comments
 (0)