FXMisc / Flowless

Efficient VirtualFlow for JavaFX
BSD 2-Clause "Simplified" License
185 stars 38 forks source link

Crop cells only if memorizedRange is bigger than expected range #94

Closed tchudyk closed 3 years ago

tchudyk commented 3 years ago

When I added VirtualFlow.visibleCells() listener I'm receiving not ending stream of events, but visible cells list is not changing. The problem seemed to only affect lists where the cell is higher than the visible area (Maybe related to https://github.com/FXMisc/Flowless/pull/80).

VirtualFlow<T, C> view = ...;
//.....
view.visibleCells().addListener(new InvalidationListener() {
    @Override
    public void invalidated(Observable observable) {
        System.out.println("a"); // <--- Not ending stream of events (printing `a`).
    }
});

I think the problem may be in package org.reactfx:reactfx:2.0-M5: MemorizationListImpl.forget(int from, int to) https://github.com/TomasMikula/ReactFX/blob/537fffdbb2958a77dfbca08b712bb2192862e960/reactfx/src/main/java/org/reactfx/collection/MemoizationList.java#L176

It publish events (memoizedItems.fireRemoveRange(memoChangeFrom, memoRemoved)) even if memoRemoved list is empty.

I'm not sure if this behavior in reactfx is good or wrong, but I found workaround to apply in Flowless in CellListManager.cropTo(...) to forget items only when memorizedRange is bigger then our fromItem-toItem range.

Jugen commented 3 years ago

Hi @tchudyk thanks for looking into this and the PR, much appreciated :-)