Skip to content

Commit 8353dba

Browse files
committed
generalize big viewport edge case for bottom Padding adjustment after setting user's minIndex
1 parent 8b27f48 commit 8353dba

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/modules/viewport.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,9 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
170170
if (buffer.minIndexUser !== null && buffer.minIndex > buffer.minIndexUser) {
171171
let diff = topPadding.height() - topPaddingHeightOld;
172172
viewport.scrollTop(viewport.scrollTop() + diff);
173-
diff -= viewport.scrollTop();
174-
if(diff > 0) {
173+
while((diff -= viewport.scrollTop()) > 0) {
175174
bottomPadding.height(bottomPadding.height() + diff);
176175
viewport.scrollTop(viewport.scrollTop() + diff);
177-
diff -= viewport.scrollTop();
178-
if(diff > 0) {
179-
bottomPadding.height(bottomPadding.height() + diff);
180-
viewport.scrollTop(viewport.scrollTop() + diff);
181-
}
182176
}
183177
}
184178
},

test/UserIndiciesSpec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,22 @@ describe('uiScroll user min/max indicies.', () => {
8989
const viewportHeight = 450;
9090
const _topItemsCount = Math.round(viewportHeight * 0.5 / itemHeight);
9191
const _topPackCount = Math.ceil(_topItemsCount / bufferSize);
92-
const _minIndex = (-1) * _topPackCount * bufferSize + 1
92+
const _minIndex = (-1) * _topPackCount * bufferSize + 1; // one additinal adjustment should occur
93+
datasource.minIndex = _minIndex;
94+
datasource.maxIndex = userMaxIndex;
95+
runTest(Object.assign({}, scrollSettings, { viewportHeight }),
96+
(viewport) => {
97+
expect(Helper.getTopPadding(viewport)).toBe(0);
98+
expect(viewport.scrollTop()).toBe(_topPackCount * bufferSize * itemHeight);
99+
}
100+
);
101+
});
102+
103+
it('should work when the viewport is big enough to include more than 1 pack of item', () => {
104+
const viewportHeight = 450;
105+
const _topItemsCount = Math.round(viewportHeight * 0.5 / itemHeight);
106+
const _topPackCount = Math.ceil(_topItemsCount / bufferSize);
107+
let _minIndex = -1; // ~9 additinal adjustments should occur
93108
datasource.minIndex = _minIndex;
94109
datasource.maxIndex = userMaxIndex;
95110
runTest(Object.assign({}, scrollSettings, { viewportHeight }),

0 commit comments

Comments
 (0)