Skip to content

Commit

Permalink
fix(android): correct waterfall first and end item index in onScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Nov 4, 2024
1 parent 6a67d9c commit e06b31f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ public boolean hasPullHeader() {
return headerRefreshHelper != null;
}

public boolean hasPullFooter() {
return footerRefreshHelper != null;
}

public boolean hasBannerView() {
ListItemRenderNode node;
if (hasPullHeader()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
public class RecyclerViewEventHelper extends OnScrollListener implements OnLayoutChangeListener,
OnAttachStateChangeListener, HippyOverPullListener {

private static final String TAG = "RecyclerViewEventHelper";
private static final int WATERFALL_SCROLL_RELAYOUT_THRESHOLD = 4;
protected final HippyRecyclerView hippyRecyclerView;
private boolean scrollBeginDragEventEnable;
Expand Down Expand Up @@ -404,14 +405,28 @@ public HashMap<String, Object> generateWaterfallViewScrollEvent() {
first = positions[i];
}
}
scrollEvent.put("firstVisibleRowIndex", first);
positions = layoutManager.findLastVisibleItemPositions(null);
int end = positions[0];
for (int i = 0; i < positions.length; ++i) {
if (end < positions[i]) {
end = positions[i];
}
}
Adapter adapter = hippyRecyclerView.getAdapter();
if (adapter instanceof HippyRecyclerListAdapter) {
HippyRecyclerListAdapter listAdapter = ((HippyRecyclerListAdapter) adapter);
int count = listAdapter.getItemCount();
if (listAdapter.hasPullHeader()) {
first = Math.max(0, (first - 1));
end = Math.max(0, (end - 1));
count -= 1;
}
if (listAdapter.hasPullFooter() && (end == (count - 1))) {
end = Math.max(0, (end - 1));
}
}
LogUtils.d(TAG, "generateWaterfallViewScrollEvent: first " + first + ", end " + end);
scrollEvent.put("firstVisibleRowIndex", first);
scrollEvent.put("lastVisibleRowIndex", end);
ArrayList<Object> rowFrames = new ArrayList<>();
int total = hippyRecyclerView.getChildCount();
Expand Down

0 comments on commit e06b31f

Please sign in to comment.