chore: 注释
This commit is contained in:
parent
7d59e20f39
commit
17a3e146ce
@ -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,74 +236,74 @@ 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]}>
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.backButton}
|
style={styles.backButton}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
try {
|
try {
|
||||||
if (TextInput.State?.currentlyFocusedInput) {
|
if (TextInput.State?.currentlyFocusedInput) {
|
||||||
const input = TextInput.State.currentlyFocusedInput();
|
const input = TextInput.State.currentlyFocusedInput();
|
||||||
if (input) input.blur();
|
if (input) input.blur();
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log('失去焦点失败:', error);
|
|
||||||
}
|
}
|
||||||
Keyboard.dismiss();
|
} catch (error) {
|
||||||
router.push('/memo-list');
|
console.log('失去焦点失败:', error);
|
||||||
}}
|
}
|
||||||
>
|
Keyboard.dismiss();
|
||||||
<ReturnArrow />
|
router.push('/memo-list');
|
||||||
</TouchableOpacity>
|
}}
|
||||||
<ThemedText style={styles.title} onPress={() => { router.push('/owner') }}>MemoWake</ThemedText>
|
>
|
||||||
<View style={styles.placeholder} />
|
<ReturnArrow />
|
||||||
|
</TouchableOpacity>
|
||||||
|
<ThemedText style={styles.title} onPress={() => { router.push('/owner') }}>MemoWake</ThemedText>
|
||||||
|
<View style={styles.placeholder} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.contentContainer}>
|
||||||
|
{/* 欢迎页面 */}
|
||||||
|
<Animated.View
|
||||||
|
style={[styles.absoluteView, welcomeStyle, { zIndex: 1 }]}
|
||||||
|
>
|
||||||
|
<AskHello setUserMessages={setUserMessages} setConversationId={setConversationId} setIsHello={setIsHello} />
|
||||||
|
</Animated.View>
|
||||||
|
|
||||||
|
{/* 聊天页面 */}
|
||||||
|
<Animated.View
|
||||||
|
style={[styles.absoluteView, chatStyle, { zIndex: 0 }]}
|
||||||
|
>
|
||||||
|
<Chat
|
||||||
|
ref={chatListRef}
|
||||||
|
userMessages={userMessages}
|
||||||
|
sessionId={sessionId}
|
||||||
|
setSelectedImages={setSelectedImages}
|
||||||
|
selectedImages={selectedImages}
|
||||||
|
style={styles.chatContainer}
|
||||||
|
contentContainerStyle={styles.chatContentContainer}
|
||||||
|
showsVerticalScrollIndicator={false}
|
||||||
|
// onContentSizeChange={() => scrollToEnd()}
|
||||||
|
/>
|
||||||
|
</Animated.View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{/* 输入框区域 */}
|
||||||
|
<KeyboardAvoidingView
|
||||||
|
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
||||||
|
keyboardVerticalOffset={0} >
|
||||||
|
<View style={styles.inputContainer} key={conversationId}>
|
||||||
|
<SendMessage
|
||||||
|
setIsHello={setIsHello}
|
||||||
|
conversationId={conversationId}
|
||||||
|
setConversationId={setConversationId}
|
||||||
|
setUserMessages={setUserMessages}
|
||||||
|
selectedImages={selectedImages}
|
||||||
|
setSelectedImages={setSelectedImages}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
</KeyboardAvoidingView>
|
||||||
<View style={styles.contentContainer}>
|
</View >
|
||||||
{/* 欢迎页面 */}
|
// </GestureDetector >
|
||||||
<Animated.View
|
|
||||||
style={[styles.absoluteView, welcomeStyle, { zIndex: 1 }]}
|
|
||||||
>
|
|
||||||
<AskHello setUserMessages={setUserMessages} setConversationId={setConversationId} setIsHello={setIsHello} />
|
|
||||||
</Animated.View>
|
|
||||||
|
|
||||||
{/* 聊天页面 */}
|
|
||||||
<Animated.View
|
|
||||||
style={[styles.absoluteView, chatStyle, { zIndex: 0 }]}
|
|
||||||
>
|
|
||||||
<Chat
|
|
||||||
ref={chatListRef}
|
|
||||||
userMessages={userMessages}
|
|
||||||
sessionId={sessionId}
|
|
||||||
setSelectedImages={setSelectedImages}
|
|
||||||
selectedImages={selectedImages}
|
|
||||||
style={styles.chatContainer}
|
|
||||||
contentContainerStyle={styles.chatContentContainer}
|
|
||||||
showsVerticalScrollIndicator={false}
|
|
||||||
onContentSizeChange={() => scrollToEnd()}
|
|
||||||
/>
|
|
||||||
</Animated.View>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
{/* 输入框区域 */}
|
|
||||||
<KeyboardAvoidingView
|
|
||||||
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
|
||||||
keyboardVerticalOffset={0} >
|
|
||||||
<View style={styles.inputContainer} key={conversationId}>
|
|
||||||
<SendMessage
|
|
||||||
setIsHello={setIsHello}
|
|
||||||
conversationId={conversationId}
|
|
||||||
setConversationId={setConversationId}
|
|
||||||
setUserMessages={setUserMessages}
|
|
||||||
selectedImages={selectedImages}
|
|
||||||
setSelectedImages={setSelectedImages}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
</KeyboardAvoidingView>
|
|
||||||
</View >
|
|
||||||
</GestureDetector>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user