Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): waterfall preloadItemNumber not working #3591

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ public void setListData() {
@Override
public void run() {
dispatchLayout();
// check end reached
int itemCount = mLayout.getItemCount();
boolean hasContent = itemCount > 1
|| (itemCount == 1 && !(mAdapter.getItemNode(0) instanceof PullFooterRenderNode));
if (hasContent) {
mEndChecker.reset();
mEndChecker.check(HippyWaterfallView.this);
}
}
};
}
Expand Down Expand Up @@ -264,7 +272,7 @@ public void onScrollStateChanged(int oldState, int newState) {
@Override
public void onScrolled(int x, int y) {
super.onScrolled(x, y);
mEndChecker.onScroll(this, y);
mEndChecker.check(this);
}

public void startRefresh(int type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.view.View;
import com.tencent.mtt.hippy.views.waterfalllist.HippyWaterfallView.HippyWaterfallEvent;
import com.tencent.mtt.supportui.views.recyclerview.RecyclerViewBase;

/**
* @author hengyangji
Expand All @@ -10,18 +11,28 @@
public class WaterfallEndChecker {

private boolean isVerticalEnd = false;
public void onScroll(HippyWaterfallView waterfallView, int y) {
boolean currentVerticalEnd = checkVerticalEnd(waterfallView, y);
public void reset() {
isVerticalEnd = false;
}

public void check(HippyWaterfallView waterfallView) {
boolean currentVerticalEnd = checkVerticalEnd(waterfallView);
if (!isVerticalEnd && currentVerticalEnd) {
new HippyWaterfallEvent("onEndReached").send(waterfallView, null);
}
isVerticalEnd = currentVerticalEnd;
}

private boolean checkVerticalEnd(HippyWaterfallView waterfallView, int y) {
private boolean checkVerticalEnd(HippyWaterfallView waterfallView) {
HippyWaterfallLayoutManager layoutManager = (HippyWaterfallLayoutManager)waterfallView.getLayoutManager();
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
boolean scrollToLastItem = lastVisibleItemPosition == layoutManager.getItemCount() - 1;
RecyclerViewBase.Adapter adapter = waterfallView.getAdapter();
int preloadItemNumber = adapter == null ? 0 : adapter.getPreloadThresholdInItemNumber();
int endPosition = layoutManager.getItemCount() - 1;
if (lastVisibleItemPosition > endPosition - preloadItemNumber) {
return true;
}
boolean scrollToLastItem = lastVisibleItemPosition == endPosition;
if (scrollToLastItem) { //滑到最后一位了
View lastView = waterfallView.findViewByPosition(lastVisibleItemPosition);
return lastView.getBottom() <= waterfallView.getBottom();
Expand Down
Loading