fix: bug
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useState, useEffect, useCallback, useRef } from 'react'
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
@@ -68,6 +68,16 @@ export default function My() {
|
||||
hasMore,
|
||||
} = useTemplateGenerations()
|
||||
|
||||
// 调试日志
|
||||
useEffect(() => {
|
||||
console.log('📊 作品列表状态:', {
|
||||
总数: generations.length,
|
||||
加载中: loading,
|
||||
加载更多中: loadingMore,
|
||||
还有更多: hasMore
|
||||
})
|
||||
}, [generations.length, loading, loadingMore, hasMore])
|
||||
|
||||
// 初始化加载作品列表
|
||||
useEffect(() => {
|
||||
refetch({ page: 1, limit: 20 })
|
||||
@@ -77,25 +87,41 @@ export default function My() {
|
||||
// 下拉刷新状态
|
||||
const [refreshing, setRefreshing] = useState(false)
|
||||
|
||||
// 防止重复触发加载更多
|
||||
const isLoadingMoreRef = useRef(false)
|
||||
|
||||
// 下拉刷新处理
|
||||
const onRefresh = useCallback(async () => {
|
||||
setRefreshing(true)
|
||||
await refetch({ page: 1, limit: 20 })
|
||||
setRefreshing(false)
|
||||
try {
|
||||
await refetch({ page: 1, limit: 20 })
|
||||
} finally {
|
||||
setRefreshing(false)
|
||||
}
|
||||
}, [refetch])
|
||||
|
||||
// 加载更多处理
|
||||
const handleEndReached = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const handleScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
||||
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent
|
||||
const paddingToBottom = 100 // 距离底部100px时触发加载更多
|
||||
if (
|
||||
layoutMeasurement.height + contentOffset.y >= contentSize.height - paddingToBottom &&
|
||||
!loadingMore &&
|
||||
hasMore
|
||||
) {
|
||||
loadMore()
|
||||
const paddingToBottom = 200 // 距离底部200px时触发加载更多
|
||||
|
||||
const isCloseToBottom =
|
||||
layoutMeasurement.height + contentOffset.y >= contentSize.height - paddingToBottom
|
||||
|
||||
// 使用 ref 防止重复触发
|
||||
if (isCloseToBottom && !loadingMore && hasMore && !loading && !isLoadingMoreRef.current) {
|
||||
console.log('🔄 触发加载更多', {
|
||||
layoutHeight: layoutMeasurement.height,
|
||||
offsetY: contentOffset.y,
|
||||
contentHeight: contentSize.height,
|
||||
distance: contentSize.height - (layoutMeasurement.height + contentOffset.y)
|
||||
})
|
||||
isLoadingMoreRef.current = true
|
||||
loadMore().finally(() => {
|
||||
isLoadingMoreRef.current = false
|
||||
})
|
||||
}
|
||||
}, [loadingMore, hasMore, loadMore])
|
||||
}, [loadingMore, hasMore, loadMore, loading])
|
||||
|
||||
// 处理设置菜单选择
|
||||
const handleSettingsSelect = async (value: string) => {
|
||||
@@ -155,7 +181,7 @@ export default function My() {
|
||||
]
|
||||
|
||||
return (
|
||||
<SafeAreaView style={styles.container} edges={['top']}>
|
||||
<SafeAreaView style={styles.container} edges={['top', 'bottom']}>
|
||||
<StatusBar style="light" />
|
||||
<RNStatusBar barStyle="light-content" />
|
||||
|
||||
@@ -219,11 +245,12 @@ export default function My() {
|
||||
<MySkeleton />
|
||||
) : (
|
||||
<ScrollView
|
||||
testID="my-scroll-view"
|
||||
style={styles.scrollView}
|
||||
contentContainerStyle={styles.scrollContent}
|
||||
showsVerticalScrollIndicator={false}
|
||||
onScroll={handleEndReached}
|
||||
scrollEventThrottle={400}
|
||||
onScroll={handleScroll}
|
||||
scrollEventThrottle={16}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
@@ -356,6 +383,7 @@ const styles = StyleSheet.create({
|
||||
scrollContent: {
|
||||
backgroundColor: '#090A0B',
|
||||
paddingHorizontal: GALLERY_HORIZONTAL_PADDING,
|
||||
paddingBottom: 20,
|
||||
},
|
||||
profileSection: {
|
||||
flexDirection: 'row',
|
||||
|
||||
Reference in New Issue
Block a user