feat: 键盘唤起bug

This commit is contained in:
jinyaqiu 2025-07-25 19:45:10 +08:00
parent 1498e9c6a8
commit 5139bce8c6
2 changed files with 26 additions and 21 deletions

View File

@ -3,13 +3,13 @@ import Chat from "@/components/ask/chat";
import AskHello from "@/components/ask/hello";
import SendMessage from "@/components/ask/send";
import { ThemedText } from "@/components/ThemedText";
import { checkAuthStatus } from '@/lib/auth';
import { fetchApi } from "@/lib/server-api-util";
import { Message } from "@/types/ask";
import { router, useLocalSearchParams } from "expo-router";
import React, { useEffect, useRef, useState } from 'react';
import {
Animated,
Keyboard,
KeyboardAvoidingView,
Platform,
ScrollView,
@ -21,9 +21,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
export default function AskScreen() {
const insets = useSafeAreaInsets();
useEffect(() => {
checkAuthStatus(router);
}, []);
// 在组件内部添加 ref
const scrollViewRef = useRef<ScrollView>(null);
const [isHello, setIsHello] = useState(true);
@ -56,11 +54,11 @@ export default function AskScreen() {
setUserMessages(res);
});
}
// if (newSession) {
// setIsHello(false);
// createNewConversation();
// }
}, [sessionId]);
if (newSession) {
setIsHello(true);
setConversationId(null);
}
}, [sessionId, newSession]);
// 动画效果
useEffect(() => {
@ -101,7 +99,10 @@ export default function AskScreen() {
<View style={[styles.navbar, isHello && styles.hiddenNavbar]}>
<TouchableOpacity
style={styles.backButton}
onPress={() => router.push('/memo-list')}
onPress={() => {
router.push('/memo-list')
Keyboard.dismiss();
}}
>
<ReturnArrow />
</TouchableOpacity>
@ -148,7 +149,7 @@ export default function AskScreen() {
</View>
{/* 输入框 */}
<View style={styles.inputContainer}>
<View style={styles.inputContainer} key={conversationId}>
<SendMessage
setIsHello={setIsHello}
setUserMessages={setUserMessages}

View File

@ -91,22 +91,26 @@ export default function SendMessage(props: Props) {
const keyboardWillShowListener = Keyboard.addListener(
'keyboardWillShow',
() => {
console.log('Keyboard will show');
setIsHello(false);
setUserMessages([{
content: {
text: "快来寻找你的记忆吧。。。"
},
role: 'Assistant',
timestamp: new Date().toISOString()
}])
if (!conversationId) {
console.log('Keyboard will show');
setIsHello(false);
setUserMessages([{
content: {
text: "快来寻找你的记忆吧。。。"
},
role: 'Assistant',
timestamp: new Date().toISOString()
}])
} else {
console.log('Keyboard will show1213');
}
}
);
return () => {
keyboardWillShowListener.remove();
};
}, []);
}, [conversationId]);
return (
<View style={styles.container}>