Skip to content

Commit 8b27f48

Browse files
committed
adjust bottom padding after minIndex set, big viewport edge case
1 parent bf489a6 commit 8b27f48

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/modules/viewport.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ export default function Viewport(elementRoutines, buffer, element, viewportContr
174174
if(diff > 0) {
175175
bottomPadding.height(bottomPadding.height() + diff);
176176
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+
}
177182
}
178183
}
179184
},

test/UserIndiciesSpec.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('uiScroll user min/max indicies.', () => {
3030
describe('Setting\n', () => {
3131
injectDatasource('myInfiniteDatasource');
3232

33-
it('should calculate bottom padding element\'s height after user max index is set', () =>
33+
it('should set up bottom padding element\'s height after user max index is set', () =>
3434
runTest(scrollSettings,
3535
(viewport) => {
3636
expect(viewport.scrollTop()).toBe(itemHeight * bufferSize);
@@ -44,7 +44,7 @@ describe('uiScroll user min/max indicies.', () => {
4444
)
4545
);
4646

47-
it('should calculate top padding element\'s height after user min index is set', () =>
47+
it('should set up top padding element\'s height after user min index is set', () =>
4848
runTest(scrollSettings,
4949
(viewport) => {
5050
expect(viewport.scrollTop()).toBe(itemHeight * bufferSize);
@@ -85,6 +85,21 @@ describe('uiScroll user min/max indicies.', () => {
8585
);
8686
});
8787

88+
it('should work when the viewport is big enough to include more than 1 pack of item', () => {
89+
const viewportHeight = 450;
90+
const _topItemsCount = Math.round(viewportHeight * 0.5 / itemHeight);
91+
const _topPackCount = Math.ceil(_topItemsCount / bufferSize);
92+
const _minIndex = (-1) * _topPackCount * bufferSize + 1
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+
88103
});
89104

90105
describe('Reload\n', () => {

0 commit comments

Comments
 (0)