tree: Improve logic around rendering child levels

* Don't bother creating a preload node when not using OnDemandList
* Create preload nodes at both ends of the child level and improve code flow
* Remove preloadNode argument from OnDemandList#renderQuery

Ported manually from 5f5dc8ea45a6044486115b378f314b14193f15bb
OnDemandList: Improve scroll-direction-detecting logic

When tree is used, its top preload node will also have a rowIndex of 0, so
this check wrongly assumed that it is above, even if it isn't.

We still check rowIndex first because it's cheaper than checking offsetTop,
and this is still not a 100% accurate fix if the user scrolls very fast.

Ported manually from 1ee538f0588dcd3541820e993b3c33b54db125d6