From 49536222de1a0d0b710713b67eaf007d0f80232f Mon Sep 17 00:00:00 2001 From: Leah Bentley Date: Fri, 27 May 2016 09:22:51 -0600 Subject: [PATCH] fix(infinitescroll): make sure more data is always loaded if scrolled to top/bottom quickly (#5183) --- .../infinite-scroll/js/infinite-scroll.js | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/features/infinite-scroll/js/infinite-scroll.js b/src/features/infinite-scroll/js/infinite-scroll.js index f248db7be3..ab68de973b 100644 --- a/src/features/infinite-scroll/js/infinite-scroll.js +++ b/src/features/infinite-scroll/js/infinite-scroll.js @@ -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); + } } } }