Skip to content

Commit

Permalink
fix(android): end reach check failed when set preloadItemNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Nov 4, 2024
1 parent e06b31f commit 6573f21
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ export default class ListExample extends React.Component {
interItemSpacing={interItemSpacing}
numberOfItems={dataSource.length}
contentInset={contentInset}
preloadItemNumber={4}
preloadItemNumber={12}
style={{ flex: 1 }}
onScroll={this.onScroll}
renderBanner={this.renderBanner}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ public void setListData() {
overPullHelper.enableOverPullUp(!listAdapter.hasFooter());
overPullHelper.enableOverPullDown(!listAdapter.hasHeader());
}
if (currentNodeCount > renderNodeCount) {
getRecyclerViewEventHelper().onListDataChanged();
}
renderNodeCount = currentNodeCount;
if (renderNodeCount > 0 && mInitialContentOffset > 0) {
scrollToInitContentOffset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class RecyclerViewEventHelper extends OnScrollListener implements OnLayou
private boolean isInitialListReadyNotified = false;
private ViewTreeObserver viewTreeObserver;
private OnPreDrawListener preDrawListener;
private boolean isLastTimeReachEnd;
private boolean hasEndReached = false;
private int preloadItemNumber;
private Rect reusableExposureStateRect = new Rect();

Expand Down Expand Up @@ -226,6 +226,10 @@ protected boolean scrollHappened(int dx, int dy) {
return dx != 0 || dy != 0;
}

public void onListDataChanged() {
hasEndReached = false;
}

/**
* 检查是否已经触底,发生onEndReached事件给前端 如果上次是没有到底,这次滑动底了,需要发事件通知,如果上一次已经是到底了,这次到底不会发事件
*/
Expand All @@ -236,10 +240,10 @@ private void checkSendReachEndEvent() {
} else {
isThisTimeReachEnd = isVerticalReachEnd();
}
if (!isLastTimeReachEnd && isThisTimeReachEnd) {
if (!hasEndReached && isThisTimeReachEnd) {
sendOnReachedEvent();
}
isLastTimeReachEnd = isThisTimeReachEnd;
hasEndReached = isThisTimeReachEnd;
}

private int findLastVisibleItemMaxPosition() {
Expand Down Expand Up @@ -296,6 +300,7 @@ private boolean isHorizontalReachEnd() {
}

protected void sendOnReachedEvent() {
LogUtils.d(TAG, "sendOnReachedEvent: ");
EventUtils.sendComponentEvent(getParentView(), EventUtils.EVENT_RECYCLER_END_REACHED, null);
EventUtils.sendComponentEvent(getParentView(), EventUtils.EVENT_RECYCLER_LOAD_MORE, null);
}
Expand Down Expand Up @@ -425,7 +430,6 @@ public HashMap<String, Object> generateWaterfallViewScrollEvent() {
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<>();
Expand Down

0 comments on commit 6573f21

Please sign in to comment.