feat: add QR code login and enhance chat experience
- Add QR code login flow with scanner and confirmation screens - Implement swipe-to-reply in chat with SwipeableMessageBubble - Replace FlatList with FlashList for chat performance optimization - Add Schedule stack navigator with CourseDetail screen support - Configure deep linking for QR code login (carrotbbs://qrcode/login/:sessionId) - Update branding from 胡萝卜 to 萝卜社区 - Display dynamic app version in settings
This commit is contained in:
@@ -390,6 +390,16 @@ export const useChatScreen = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
// 禁用自动滚动到底部,防止加载历史消息后滚动位置跳转
|
||||
shouldAutoScrollOnEnterRef.current = false;
|
||||
// 清除所有待执行的自动滚动定时器
|
||||
autoScrollTimersRef.current.forEach(clearTimeout);
|
||||
autoScrollTimersRef.current = [];
|
||||
|
||||
// 保存加载前的滚动位置和内容高度
|
||||
const scrollYBefore = scrollPositionRef.current.scrollY;
|
||||
const contentHeightBefore = scrollPositionRef.current.contentHeight;
|
||||
|
||||
setLoadingMore(true);
|
||||
|
||||
try {
|
||||
@@ -400,6 +410,23 @@ export const useChatScreen = () => {
|
||||
const minSeq = Math.min(...messages.map(m => m.seq));
|
||||
setFirstSeq(minSeq);
|
||||
}
|
||||
|
||||
// 加载完成后,恢复滚动位置
|
||||
// 使用 setTimeout 确保 FlashList 已经更新
|
||||
setTimeout(() => {
|
||||
if (flatListRef.current) {
|
||||
// 计算新的滚动位置,保持相对位置不变
|
||||
const newContentHeight = scrollPositionRef.current.contentHeight;
|
||||
const heightDiff = newContentHeight - contentHeightBefore;
|
||||
const newScrollY = scrollYBefore + heightDiff;
|
||||
|
||||
// 滚动到计算后的位置
|
||||
flatListRef.current.scrollToOffset({
|
||||
offset: newScrollY,
|
||||
animated: false,
|
||||
});
|
||||
}
|
||||
}, 100);
|
||||
} catch (error) {
|
||||
console.error('加载历史消息失败:', error);
|
||||
} finally {
|
||||
@@ -409,13 +436,19 @@ export const useChatScreen = () => {
|
||||
|
||||
// 列表内容尺寸变化后触发首次自动滚动
|
||||
const handleMessageListContentSizeChange = useCallback((contentWidth: number, contentHeight: number) => {
|
||||
// 如果是加载更多历史消息,不要自动滚动
|
||||
if (loadingMore) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!shouldAutoScrollOnEnterRef.current) return;
|
||||
if (loading || loadingMore) return;
|
||||
if (loading) return;
|
||||
if (messages.length === 0) return;
|
||||
|
||||
const prevContentHeight = scrollPositionRef.current.contentHeight;
|
||||
scrollPositionRef.current.contentHeight = contentHeight;
|
||||
|
||||
// 如果内容高度增加(加载了更多消息),不要自动滚动到底部
|
||||
if (prevContentHeight > 0 && contentHeight > prevContentHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user