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 all commits
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
@@ -1,7 +1,23 @@
/* Tencent is pleased to support the open source community by making Hippy available.
* Copyright (C) 2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tencent.mtt.hippy.views.waterfalllist;

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 +26,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