Closed soyuka closed 7 years ago
Excellent, I believe this was one of the points made in https://github.com/tbranyen/hyperlist/pull/20#issuecomment-298444117 wrt missing items. Any thoughts on how a test could be written to account for this behavior?
It was hard to reproduce but I'll come up with something!
@soyuka you can always merge this first and we can add a test later. Don't wanna hold up the code if we don't have to.
I'm having trouble finding a way to change the rendered elements according to the given scrollTop. You may have some idea for this?
For example:
@tbranyen Finally updated with a nice test!
The test prepares 100
items with heights between 100
and 50
. It then scrolls with a += minHeight
gap until it reaches the end. When the scrollHeight
is bigger then the container computed height, we check that it did show every 100
items!
Because this is really random and that I successfully ran this test with crazy values this is :+1:!
Also, I had to increase the mocha timeout. Indeed it takes ~2.3 seconds to scroll 50
by 50
until the end (approx. 7500px - can't say for sure because it's dynamic and random :D).
Feel free to merge!
I noted that when you have really different heights, there is a possibility that
_screenItemsLen
resolves to1
(then3
) and therefore you might be missing elements at the top/bottom (position start0
/ position endtotal
).To resolve this issue I've changed the height computation to use a median instead of a basic average. Also, we will keep the highest value of
_screenItemsLen
to avoid setting it less then required (really depends on the height of the elements currently shown).This may increase the number of rendered elements, but it has almost no performance overhead, and it's more important to guarantee that all the elements are shown.