Skip to content

Inertia fix #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ Pull Rerquest should include source code (./scr) changes, may include tests (./t

## Change log

### v1.8.0
* Reconsidered scroll event handling
* Fixed inertia scrolling issues

### v1.7.6
* Added immutableTop option for applyUpdates and prepend Adapter methods.

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-scroll",
"description": "AngularJS infinite scrolling module",
"version": "1.7.6",
"version": "1.8.0",
"main": "./dist/ui-scroll.js",
"homepage": "https://github.com/angular-ui/ui-scroll.git",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ui-scroll-grid.min.js.map

Large diffs are not rendered by default.

60 changes: 55 additions & 5 deletions dist/ui-scroll.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ui-scroll.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-scroll.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ui-scroll.min.js.map

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-ui-scroll",
"description": "AngularJS infinite scrolling module",
"version": "1.7.6",
"version": "1.8.0",
"src": "./src/",
"public": "./dist/",
"main": "./dist/ui-scroll.js",
Expand Down
13 changes: 8 additions & 5 deletions src/modules/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,20 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
},

onAfterPrepend(updates) {
if (!updates.prepended.length)
if (!updates.prepended.length) {
return;
}
const height = buffer.effectiveHeight(updates.prepended);
const paddingHeight = topPadding.height() - height;
if (paddingHeight >= 0) {
topPadding.height(paddingHeight);
return;
}
else {
topPadding.height(0);
viewport.scrollTop(viewport.scrollTop() - paddingHeight);
}
const position = viewport.scrollTop();
const newPosition = position - paddingHeight;
viewport.synthetic = { previous: position, next: newPosition };
topPadding.height(0);
viewport.scrollTop(newPosition);
},

resetTopPadding() {
Expand Down
32 changes: 32 additions & 0 deletions src/ui-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ angular.module('ui.scroll', [])
return parseNumber(result, defaultValue, isFloat);
}

function parseBooleanAttr(value, defaultValue) {
const result = $parse(value)($scope);
return typeof result === 'boolean' ? result : defaultValue;
}

const BUFFER_MIN = 3;
const BUFFER_DEFAULT = 10;
const PADDING_MIN = 0.3;
const PADDING_DEFAULT = 0.5;
const HANDLE_INERTIA_DEFAULT = true;
const START_INDEX_DEFAULT = 1;
const MAX_VIEWPORT_DELAY = 500;
const VIEWPORT_POLLING_INTERVAL = 50;
Expand All @@ -87,6 +93,7 @@ angular.module('ui.scroll', [])
const viewportController = controllers[0];
const bufferSize = Math.max(BUFFER_MIN, parseNumericAttr($attr.bufferSize, BUFFER_DEFAULT));
const padding = Math.max(PADDING_MIN, parseNumericAttr($attr.padding, PADDING_DEFAULT, true));
const handleInertia = parseBooleanAttr($attr.handleInertia, HANDLE_INERTIA_DEFAULT);
let startIndex = parseNumericAttr($attr.startIndex, START_INDEX_DEFAULT);
let ridActual = 0; // current data revision id
let pending = [];
Expand Down Expand Up @@ -485,7 +492,32 @@ angular.module('ui.scroll', [])
}
}

function fixInertia() {
if (!viewport.synthetic) {
return;
}
const oldPosition = viewport.synthetic.previous;
const newPosition = viewport.synthetic.next;
if (viewport.scrollTop() !== newPosition) {
requestAnimationFrame(() => {
const position = viewport.scrollTop();
const diff = oldPosition - position;
if (diff > 0) { // inertia over synthetic
viewport.scrollTop(newPosition - diff);
} else {
viewport.scrollTop(newPosition);
}
viewport.synthetic = null;
});
return true;
}
viewport.synthetic = null;
}

function resizeAndScrollHandler() {
if (handleInertia && fixInertia()) {
return;
}
if (!$rootScope.$$phase && !adapter.isLoading && !adapter.disabled) {

enqueueFetch(ridActual);
Expand Down
Loading