f
This commit is contained in:
parent
4f0fb96a9b
commit
c94fe202cc
@ -5,7 +5,7 @@ import SendMessage from "@/components/ask/send";
|
||||
import { ThemedText } from "@/components/ThemedText";
|
||||
import { Message } from "@/types/ask";
|
||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import { useRef, useState } from 'react';
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
FlatList,
|
||||
@ -44,45 +44,45 @@ export default function AskScreen() {
|
||||
}>();
|
||||
|
||||
// 创建一个安全的滚动函数
|
||||
const scrollToEnd = useCallback((animated = true) => {
|
||||
if (!isMountedRef.current || !chatListRef.current) return;
|
||||
// const scrollToEnd = useCallback((animated = true) => {
|
||||
// if (!isMountedRef.current || !chatListRef.current) return;
|
||||
|
||||
// 清理之前的定时器
|
||||
if (scrollTimeoutRef.current) {
|
||||
clearTimeout(scrollTimeoutRef.current);
|
||||
}
|
||||
// // 清理之前的定时器
|
||||
// if (scrollTimeoutRef.current) {
|
||||
// clearTimeout(scrollTimeoutRef.current);
|
||||
// }
|
||||
|
||||
scrollTimeoutRef.current = setTimeout(() => {
|
||||
if (isMountedRef.current && chatListRef.current) {
|
||||
try {
|
||||
chatListRef.current.scrollToEnd({ animated });
|
||||
} catch (error) {
|
||||
console.warn('滚动到底部失败:', error);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}, []);
|
||||
// scrollTimeoutRef.current = setTimeout(() => {
|
||||
// if (isMountedRef.current && chatListRef.current) {
|
||||
// try {
|
||||
// chatListRef.current.scrollToEnd({ animated });
|
||||
// } catch (error) {
|
||||
// console.warn('滚动到底部失败:', error);
|
||||
// }
|
||||
// }
|
||||
// }, 100);
|
||||
// }, []);
|
||||
|
||||
// 清理函数
|
||||
const cleanup = useCallback(() => {
|
||||
isMountedRef.current = false;
|
||||
// const cleanup = useCallback(() => {
|
||||
// isMountedRef.current = false;
|
||||
|
||||
// 清理定时器
|
||||
if (scrollTimeoutRef.current) {
|
||||
clearTimeout(scrollTimeoutRef.current);
|
||||
scrollTimeoutRef.current = null;
|
||||
}
|
||||
if (keyboardTimeoutRef.current) {
|
||||
clearTimeout(keyboardTimeoutRef.current);
|
||||
keyboardTimeoutRef.current = null;
|
||||
}
|
||||
// // 清理定时器
|
||||
// if (scrollTimeoutRef.current) {
|
||||
// clearTimeout(scrollTimeoutRef.current);
|
||||
// scrollTimeoutRef.current = null;
|
||||
// }
|
||||
// if (keyboardTimeoutRef.current) {
|
||||
// clearTimeout(keyboardTimeoutRef.current);
|
||||
// keyboardTimeoutRef.current = null;
|
||||
// }
|
||||
|
||||
// 取消API请求
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
abortControllerRef.current = null;
|
||||
}
|
||||
}, []);
|
||||
// // 取消API请求
|
||||
// if (abortControllerRef.current) {
|
||||
// abortControllerRef.current.abort();
|
||||
// abortControllerRef.current = null;
|
||||
// }
|
||||
// }, []);
|
||||
|
||||
// useEffect(() => {
|
||||
// if (!isHello && userMessages.length > 0 && isMountedRef.current) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user