1
This commit is contained in:
@@ -129,15 +129,37 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
|
||||
// ScrollView 滚动处理
|
||||
const handleScrollViewScroll = useCallback(
|
||||
(e: any) => {
|
||||
|
||||
|
||||
const currentScrollTop = e?.detail?.scrollTop || 0;
|
||||
const scrollHeight = e?.detail?.scrollHeight || 0;
|
||||
const clientHeight = e?.detail?.clientHeight || 0;
|
||||
const lastScrollTop = lastScrollTopRef.current;
|
||||
const currentTime = Date.now();
|
||||
const timeDiff = currentTime - lastScrollTimeRef.current;
|
||||
|
||||
if (timeDiff < 100) return;
|
||||
|
||||
// 计算距离底部的距离,提前加载(距离底部600px时开始加载)
|
||||
// 注意:如果 scrollHeight 或 clientHeight 不可用,则使用 lowerThreshold 触发
|
||||
if (scrollHeight > 0 && clientHeight > 0) {
|
||||
const distanceToBottom = scrollHeight - currentScrollTop - clientHeight;
|
||||
const preloadThreshold = 600; // 提前加载阈值
|
||||
|
||||
// 如果距离底部小于阈值,且正在向下滚动,且有更多数据,则提前加载
|
||||
if (
|
||||
distanceToBottom < preloadThreshold &&
|
||||
distanceToBottom > 0 &&
|
||||
!loading &&
|
||||
!loadingMoreRef.current &&
|
||||
listPageState?.isHasMoreData &&
|
||||
currentScrollTop > lastScrollTop // 向下滚动
|
||||
) {
|
||||
loadingMoreRef.current = true;
|
||||
loadMoreMatches().finally(() => {
|
||||
loadingMoreRef.current = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const scrollDiff = currentScrollTop - lastScrollTop;
|
||||
let newDirection = scrollDirectionRef.current;
|
||||
if (Math.abs(scrollDiff) > 15) {
|
||||
@@ -195,7 +217,7 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
|
||||
lastScrollTopRef.current = currentScrollTop;
|
||||
lastScrollTimeRef.current = currentTime;
|
||||
},
|
||||
[updateListPageState, onNavStateChange]
|
||||
[updateListPageState, onNavStateChange, loading, loadMoreMatches, listPageState?.isHasMoreData]
|
||||
// 移除 showSearchBar 和 isShowInputCustomerNavBar 依赖,使用 ref 获取最新值
|
||||
);
|
||||
|
||||
@@ -550,7 +572,7 @@ const ListPageContent: React.FC<ListPageContentProps> = ({
|
||||
refresherEnabled={true}
|
||||
refresherTriggered={refreshing}
|
||||
onRefresherRefresh={handleRefresh}
|
||||
lowerThreshold={100}
|
||||
lowerThreshold={600}
|
||||
onScrollToLower={async () => {
|
||||
if (
|
||||
!loading &&
|
||||
|
||||
Reference in New Issue
Block a user