From 3bc8dda46ff4e23a08a5b589d5b4eb296594ee54 Mon Sep 17 00:00:00 2001 From: Junhui Chen Date: Tue, 5 Aug 2025 19:25:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=97=AA=E9=80=80?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(tabs)/ask.tsx | 34 +++++++++----------------- app/(tabs)/index.tsx | 57 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 33 deletions(-) diff --git a/app/(tabs)/ask.tsx b/app/(tabs)/ask.tsx index 68d42d9..3213d12 100644 --- a/app/(tabs)/ask.tsx +++ b/app/(tabs)/ask.tsx @@ -6,7 +6,7 @@ import { ThemedText } from "@/components/ThemedText"; import { fetchApi } from "@/lib/server-api-util"; import { getWebSocketErrorMessage, webSocketManager, WsMessage } from "@/lib/websocket-util"; import { Assistant, Message } from "@/types/ask"; -import { router, useFocusEffect, useLocalSearchParams } from "expo-router"; +import { useFocusEffect, useLocalSearchParams, useRouter } from "expo-router"; import { useCallback, useEffect, useRef, useState } from 'react'; import { useTranslation } from "react-i18next"; import { @@ -25,6 +25,7 @@ import { runOnJS } from 'react-native-reanimated'; import { useSafeAreaInsets } from "react-native-safe-area-context"; export default function AskScreen() { + const router = useRouter(); const insets = useSafeAreaInsets(); const chatListRef = useRef(null); @@ -242,6 +243,15 @@ export default function AskScreen() { } }, [isHello]); + // 组件卸载时清理动画 + useEffect(() => { + return () => { + // 停止所有可能正在运行的动画 + fadeAnim.stopAnimation(); + fadeAnimChat.stopAnimation(); + }; + }, []); + useFocusEffect( useCallback(() => { if (!sessionId) { @@ -254,28 +264,6 @@ export default function AskScreen() { return ( - {/* 导航栏 */} - - { - try { - if (TextInput.State?.currentlyFocusedInput) { - const input = TextInput.State.currentlyFocusedInput(); - if (input) input.blur(); - } - } catch (error) { - console.log('失去焦点失败:', error); - } - Keyboard.dismiss(); - router.push('/memo-list'); - }} - > - - - { router.push('/owner') }}>MemoWake - - {/* 欢迎页面 */} diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index ac7cdaf..9bfada9 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -223,14 +223,36 @@ export default function HomeScreen() { // 组件挂载时启动动画 useEffect(() => { - setIsLoading(true); - checkAuthStatus(router, () => { - router.replace('/ask') - }, false).then(() => { - setIsLoading(false); - }).catch(() => { - setIsLoading(false); - }); + let isMounted = true; + + const initializeComponent = async () => { + try { + setIsLoading(true); + + // 添加延迟确保 AuthProvider 已经初始化 + await new Promise(resolve => setTimeout(resolve, 100)); + + if (!isMounted) return; + + await checkAuthStatus(router, () => { + if (isMounted) { + router.replace('/ask'); + } + }, false); + + if (!isMounted) return; + + setIsLoading(false); + } catch (error) { + console.error('初始化组件时出错:', error); + if (isMounted) { + setIsLoading(false); + } + } + }; + + initializeComponent(); + // IP图标的淡入动画 Animated.timing(fadeAnim, { toValue: 1, @@ -249,14 +271,29 @@ export default function HomeScreen() { startWaveAnimation(); }); - // 组件卸载时清理动画 + // 组件卸载时清理动画和状态 return () => { + isMounted = false; + + // 清理所有动画 if (buttonLoopAnim.current) { buttonLoopAnim.current.stop(); } if (animationRef.current) { animationRef.current.stop(); } + + // 重置所有动画值 + fadeAnim.setValue(0); + shakeAnim.setValue(0); + descriptionAnim.setValue(0); + buttonAnim.setValue(0); + buttonShakeAnim.setValue(0); + fadeInAnim.setValue(0); + waveAnim.setValue(0); + + // 重置文本动画 + Object.values(textAnimations).forEach(anim => anim.setValue(0)); }; }, []); @@ -532,4 +569,4 @@ const styles = StyleSheet.create({ fontWeight: 'bold', fontSize: 18, }, -}); \ No newline at end of file +});