fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import SearchBar from "@/components/SearchBar";
|
||||
import FilterPopup from "@/components/FilterPopup";
|
||||
import styles from "./index.module.scss";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useEffect, useRef, useCallback } from "react";
|
||||
import Taro, { usePageScroll } from "@tarojs/taro";
|
||||
import { useListStore } from "@/store/listStore";
|
||||
import { useGlobalState } from "@/store/global";
|
||||
@@ -44,24 +44,52 @@ const ListPage = () => {
|
||||
fetchGetGamesCount
|
||||
} = store;
|
||||
|
||||
// 简化的滚动处理函数
|
||||
usePageScroll((res) => {
|
||||
const shouldShowInputNav = res?.scrollTop >= totalHeight;
|
||||
|
||||
// 只有当状态需要改变时才更新
|
||||
if (shouldShowInputNav && !isShowInputCustomerNavBar) {
|
||||
updateState({ isShowInputCustomerNavBar: true });
|
||||
} else {
|
||||
updateState({ isShowInputCustomerNavBar: false });
|
||||
// 防抖的滚动处理函数
|
||||
const handleScroll = useCallback((res) => {
|
||||
const currentScrollTop = res?.scrollTop || 0;
|
||||
|
||||
// 添加缓冲区,避免临界点频繁切换
|
||||
const buffer = 10; // 10px 缓冲区
|
||||
const shouldShowInputNav = currentScrollTop >= (totalHeight + buffer);
|
||||
const shouldHideInputNav = currentScrollTop < (totalHeight - buffer);
|
||||
|
||||
// 清除之前的定时器
|
||||
if (scrollTimeoutRef.current) {
|
||||
clearTimeout(scrollTimeoutRef.current);
|
||||
}
|
||||
});
|
||||
|
||||
// 防抖处理,避免频繁更新状态
|
||||
scrollTimeoutRef.current = setTimeout(() => {
|
||||
// 只有在状态真正需要改变时才更新
|
||||
if (shouldShowInputNav && !isShowInputCustomerNavBar) {
|
||||
updateState({ isShowInputCustomerNavBar: true });
|
||||
} else if (shouldHideInputNav && isShowInputCustomerNavBar) {
|
||||
updateState({ isShowInputCustomerNavBar: false });
|
||||
}
|
||||
|
||||
lastScrollTopRef.current = currentScrollTop;
|
||||
}, 16); // 约60fps的防抖间隔
|
||||
}, [totalHeight, isShowInputCustomerNavBar, updateState]);
|
||||
|
||||
usePageScroll(handleScroll);
|
||||
|
||||
const scrollContextRef = useRef(null)
|
||||
const scrollTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||
const lastScrollTopRef = useRef(0)
|
||||
|
||||
useEffect(() => {
|
||||
getLocation()
|
||||
}, []);
|
||||
|
||||
// 清理定时器
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (scrollTimeoutRef.current) {
|
||||
clearTimeout(scrollTimeoutRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
// 监听距离和排序方式变化,自动调用接口
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user