From 517848e7e192245385ae352eae461bf3392a18dc Mon Sep 17 00:00:00 2001 From: maxli Date: Wed, 30 Oct 2024 18:05:18 +0800 Subject: [PATCH] fix(android): add comments for waterfall onScroll event params --- .../hippy/views/hippylist/RecyclerViewEventHelper.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 a2d369a9e4c..a7345aab68f 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 @@ -186,7 +186,8 @@ private void relayoutWaterfallIfNeeded() { LayoutManager layoutManager = hippyRecyclerView.getLayoutManager(); if (layoutManager instanceof HippyStaggeredGridLayoutManager) { int[] firstVisibleItem = null; - firstVisibleItem = ((HippyStaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(firstVisibleItem); + firstVisibleItem = ((HippyStaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions( + firstVisibleItem); if (firstVisibleItem != null && (firstVisibleItem[0] <= WATERFALL_SCROLL_RELAYOUT_THRESHOLD)) { Adapter adapter = hippyRecyclerView.getAdapter(); if (adapter != null) { @@ -421,11 +422,16 @@ public HashMap generateWaterfallViewScrollEvent() { if (adapter instanceof HippyRecyclerListAdapter) { HippyRecyclerListAdapter listAdapter = ((HippyRecyclerListAdapter) adapter); int count = listAdapter.getItemCount(); + // Android includes a pull header and a pull footer when calculating the position of an item. In order to + // align with iOS, if a pull header is included, the first item and last item position needs to be + // subtracted by 1 if (listAdapter.hasPullHeader()) { first = Math.max(0, (first - 1)); end = Math.max(0, (end - 1)); count -= 1; } + // For align with iOS, if a pull footer is included, the last item position needs to be + // subtracted by 1 if (listAdapter.hasPullFooter() && (end == (count - 1))) { end = Math.max(0, (end - 1)); }