Currently I am observing a room database with the paging library and using this code to scroll when a new item is inserted at the top
RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
if (positionStart == 0 && itemCount == 1) {
layoutManager.scrollToPositionWithOffset(0, 0);
}
}
});
which works fine normally. However, when scrolling to a page further down, positionStart is no longer 0 but some higher number (what I assume to be the "top" of what's loaded) when inserting to the front of the list. Is this the intended behavior and is there a way around it?
Either way - APIs to handle loadState (which you can filter for PREPEND loads), are now available in Paging3:
PagingDataAdapter.loadStateFlow / .addLoadStateListener()
Currently I am observing a room database with the paging library and using this code to scroll when a new item is inserted at the top
which works fine normally. However, when scrolling to a page further down, positionStart is no longer 0 but some higher number (what I assume to be the "top" of what's loaded) when inserting to the front of the list. Is this the intended behavior and is there a way around it?