From b0b30a3d7c476754fcf2c0ddd5417dd6d53d4bba Mon Sep 17 00:00:00 2001 From: maxli Date: Wed, 30 Oct 2024 14:46:41 +0800 Subject: [PATCH] fix(android): end reach check failed when set preloadItemNumber --- .../src/components/WaterfallView/index.jsx | 2 +- .../mtt/hippy/views/hippylist/HippyRecyclerView.java | 3 +++ .../views/hippylist/RecyclerViewEventHelper.java | 12 ++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/driver/js/examples/hippy-react-demo/src/components/WaterfallView/index.jsx b/driver/js/examples/hippy-react-demo/src/components/WaterfallView/index.jsx index 27cac7fc5b9..9b0824d2258 100644 --- a/driver/js/examples/hippy-react-demo/src/components/WaterfallView/index.jsx +++ b/driver/js/examples/hippy-react-demo/src/components/WaterfallView/index.jsx @@ -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} diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java index 60e66bf913c..2ebe3dd3739 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/HippyRecyclerView.java @@ -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(); diff --git a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java index 38e27a8f7f7..a2d369a9e4c 100644 --- a/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java +++ b/renderer/native/android/src/main/java/com/tencent/mtt/hippy/views/hippylist/RecyclerViewEventHelper.java @@ -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(); @@ -226,6 +226,10 @@ protected boolean scrollHappened(int dx, int dy) { return dx != 0 || dy != 0; } + public void onListDataChanged() { + hasEndReached = false; + } + /** * 检查是否已经触底,发生onEndReached事件给前端 如果上次是没有到底,这次滑动底了,需要发事件通知,如果上一次已经是到底了,这次到底不会发事件 */ @@ -236,10 +240,10 @@ private void checkSendReachEndEvent() { } else { isThisTimeReachEnd = isVerticalReachEnd(); } - if (!isLastTimeReachEnd && isThisTimeReachEnd) { + if (!hasEndReached && isThisTimeReachEnd) { sendOnReachedEvent(); } - isLastTimeReachEnd = isThisTimeReachEnd; + hasEndReached = isThisTimeReachEnd; } private int findLastVisibleItemMaxPosition() { @@ -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); } @@ -425,7 +430,6 @@ public HashMap generateWaterfallViewScrollEvent() { end = Math.max(0, (end - 1)); } } - LogUtils.d(TAG, "generateWaterfallViewScrollEvent: first " + first + ", end " + end); scrollEvent.put("firstVisibleRowIndex", first); scrollEvent.put("lastVisibleRowIndex", end); ArrayList rowFrames = new ArrayList<>();