Skip to content

Commit

Permalink
fix(infinitescroll): make sure more data is always loaded if scrolled…
Browse files Browse the repository at this point in the history
… to top/bottom quickly (#5183)
  • Loading branch information
Leah Bentley authored and JLLeitschuh committed May 27, 2016
1 parent d6d00c2 commit 4953622
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/features/infinite-scroll/js/infinite-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,28 @@
}

if (args.y) {
var percentage;
var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
percentage = args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);
}
} else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
percentage = 1 - args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);

// If the user is scrolling very quickly all the way to the top/bottom, the scroll handler can get confused
// about the direction. First we check if they've gone all the way, and data always is loaded in this case.
if (args.y.percentage === 0) {
args.grid.scrollDirection = uiGridConstants.scrollDirection.UP;
service.loadData(args.grid);
} else if (args.y.percentage === 1) {
args.grid.scrollDirection = uiGridConstants.scrollDirection.DOWN;
service.loadData(args.grid);
} else { // Scroll position is somewhere in between top/bottom, so determine whether it's far enough to load more data.
var percentage;
var targetPercentage = args.grid.options.infiniteScrollRowsFromEnd / args.grid.renderContainers.body.visibleRowCache.length;
if (args.grid.scrollDirection === uiGridConstants.scrollDirection.UP ) {
percentage = args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);
}
} else if (args.grid.scrollDirection === uiGridConstants.scrollDirection.DOWN) {
percentage = 1 - args.y.percentage;
if (percentage <= targetPercentage){
service.loadData(args.grid);
}
}
}
}
Expand Down

0 comments on commit 4953622

Please sign in to comment.