chore: 注释

This commit is contained in:
Junhui Chen 2025-08-06 15:34:42 +08:00
parent 7d59e20f39
commit 17a3e146ce

View File

@ -19,8 +19,7 @@ import {
TouchableOpacity, TouchableOpacity,
View View
} from 'react-native'; } from 'react-native';
import { Gesture, GestureDetector } from "react-native-gesture-handler"; import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated';
import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useSafeAreaInsets } from "react-native-safe-area-context";
export default function AskScreen() { export default function AskScreen() {
@ -42,60 +41,60 @@ export default function AskScreen() {
}>(); }>();
// 创建一个可复用的滚动函数 // 创建一个可复用的滚动函数
const scrollToEnd = useCallback((animated = true) => { // const scrollToEnd = useCallback((animated = true) => {
if (chatListRef.current) { // if (chatListRef.current) {
setTimeout(() => chatListRef.current?.scrollToEnd({ animated }), 100); // setTimeout(() => chatListRef.current?.scrollToEnd({ animated }), 100);
} // }
}, []); // }, []);
// 右滑 // 右滑
const gesture = Gesture.Pan() // const gesture = Gesture.Pan()
.onEnd((event) => { // .onEnd((event) => {
const { translationX } = event; // const { translationX } = event;
const threshold = 100; // 滑动阈值 // const threshold = 100; // 滑动阈值
if (translationX > threshold) { // if (translationX > threshold) {
// 从左向右滑动,跳转页面 // // 从左向右滑动,跳转页面
runOnJS(router.replace)("/memo-list"); // runOnJS(router.replace)("/memo-list");
} // }
}) // })
.minPointers(1) // .minPointers(1)
.activeOffsetX([-10, 10]); // 在 X 方向触发的范围 // .activeOffsetX([-10, 10]); // 在 X 方向触发的范围
useEffect(() => { // useEffect(() => {
if (!isHello && userMessages.length > 0) { // if (!isHello && userMessages.length > 0) {
scrollToEnd(); // scrollToEnd();
} // }
}, [userMessages, isHello, scrollToEnd]); // }, [userMessages, isHello, scrollToEnd]);
useEffect(() => { // useEffect(() => {
const keyboardDidShowListener = Keyboard.addListener( // const keyboardDidShowListener = Keyboard.addListener(
'keyboardDidShow', // 'keyboardDidShow',
(e) => { // (e) => {
setTimeout(() => { // setTimeout(() => {
if (!isHello) { // if (!isHello) {
scrollToEnd(); // scrollToEnd();
} // }
}, 100); // }, 100);
} // }
); // );
const keyboardDidHideListener = Keyboard.addListener( // const keyboardDidHideListener = Keyboard.addListener(
'keyboardDidHide', // 'keyboardDidHide',
() => { // () => {
setTimeout(() => { // setTimeout(() => {
if (!isHello) { // if (!isHello) {
scrollToEnd(false); // scrollToEnd(false);
} // }
}, 100); // }, 100);
} // }
); // );
return () => { // return () => {
keyboardDidShowListener.remove(); // keyboardDidShowListener.remove();
keyboardDidHideListener.remove(); // keyboardDidHideListener.remove();
}; // };
}, [isHello]); // }, [isHello]);
useFocusEffect( useFocusEffect(
useCallback(() => { useCallback(() => {
@ -219,13 +218,13 @@ export default function AskScreen() {
} }
}, [sessionId, newSession]); }, [sessionId, newSession]);
useEffect(() => { // useEffect(() => {
if (!isHello) { // if (!isHello) {
// 不再自动关闭键盘,让用户手动控制 // // 不再自动关闭键盘,让用户手动控制
// 这里可以添加其他需要在隐藏hello界面时执行的逻辑 // // 这里可以添加其他需要在隐藏hello界面时执行的逻辑
scrollToEnd(false); // scrollToEnd(false);
} // }
}, [isHello]); // }, [isHello]);
useFocusEffect( useFocusEffect(
useCallback(() => { useCallback(() => {
@ -237,7 +236,7 @@ export default function AskScreen() {
); );
return ( return (
<GestureDetector gesture={gesture}> // <GestureDetector gesture={gesture}>
<View style={[styles.container, { paddingTop: insets.top, paddingBottom: insets.bottom }]}> <View style={[styles.container, { paddingTop: insets.top, paddingBottom: insets.bottom }]}>
{/* 导航栏 */} {/* 导航栏 */}
<View style={[styles.navbar, isHello && styles.hiddenNavbar]}> <View style={[styles.navbar, isHello && styles.hiddenNavbar]}>
@ -283,7 +282,7 @@ export default function AskScreen() {
style={styles.chatContainer} style={styles.chatContainer}
contentContainerStyle={styles.chatContentContainer} contentContainerStyle={styles.chatContentContainer}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
onContentSizeChange={() => scrollToEnd()} // onContentSizeChange={() => scrollToEnd()}
/> />
</Animated.View> </Animated.View>
</View> </View>
@ -304,7 +303,7 @@ export default function AskScreen() {
</View> </View>
</KeyboardAvoidingView> </KeyboardAvoidingView>
</View > </View >
</GestureDetector> // </GestureDetector >
); );
} }