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