Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mobile-web/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export const messages: Record<MobileLanguage, MessageTree> = {
fileDownloading: 'Downloading...',
fileDownloaded: 'Downloaded',
clickToDownload: 'Click to download',
scrollToBottom: 'Scroll to bottom',
},
tools: {
explore: 'Explore',
Expand Down Expand Up @@ -297,6 +298,7 @@ export const messages: Record<MobileLanguage, MessageTree> = {
fileDownloading: '下载中...',
fileDownloaded: '已下载',
clickToDownload: '点击下载',
scrollToBottom: '滚动到底部',
},
tools: {
explore: '探索',
Expand Down Expand Up @@ -451,6 +453,7 @@ export const messages: Record<MobileLanguage, MessageTree> = {
fileDownloading: '下載中...',
fileDownloaded: '已下載',
clickToDownload: '點擊下載',
scrollToBottom: '捲動到底部',
},
tools: {
explore: '探索',
Expand Down
42 changes: 41 additions & 1 deletion src/mobile-web/src/pages/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,7 @@ const ChatPage: React.FC<ChatPageProps> = ({ sessionMgr, sessionId, sessionName,
const messagesContainerRef = useRef<HTMLDivElement>(null);
const [expandedMsgIds, setExpandedMsgIds] = useState<Set<string>>(new Set());
const [infoToast, setInfoToast] = useState<string | null>(null);
const [showScrollToBottom, setShowScrollToBottom] = useState(false);

const isStreaming = activeTurn != null && activeTurn.status === 'active';

Expand Down Expand Up @@ -2137,21 +2138,42 @@ const ChatPage: React.FC<ChatPageProps> = ({ sessionMgr, sessionId, sessionName,
}, [sessionMgr, sessionId, setMessages, setError, getMessages]);

const isNearBottomRef = useRef(true);
const programmaticScrollRef = useRef(false);
const lastShowScrollToBottomRef = useRef(false);
const BOTTOM_THRESHOLD = 80;

const handleScroll = useCallback(() => {
const container = messagesContainerRef.current;
if (!container) return;

const gap = container.scrollHeight - container.scrollTop - container.clientHeight;
isNearBottomRef.current = gap < BOTTOM_THRESHOLD;
const nearBottom = gap < BOTTOM_THRESHOLD;
isNearBottomRef.current = nearBottom;
if (nearBottom) {
programmaticScrollRef.current = false;
}
if (!programmaticScrollRef.current) {
const show = !nearBottom;
if (show !== lastShowScrollToBottomRef.current) {
lastShowScrollToBottomRef.current = show;
setShowScrollToBottom(show);
}
}

if (container.scrollTop < 100 && hasMore && !isLoadingMore) {
const msgs = getMessages(sessionId);
if (msgs.length > 0) loadMessages(msgs[0].id);
}
}, [hasMore, isLoadingMore, getMessages, sessionId, loadMessages]);

const scrollToBottom = useCallback(() => {
programmaticScrollRef.current = true;
isNearBottomRef.current = true;
setShowScrollToBottom(false);
lastShowScrollToBottomRef.current = false;
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
}, []);

// Initial load + start poller
const initialScrollDone = useRef(false);
const pendingInitialScroll = useRef(false);
Expand Down Expand Up @@ -2231,6 +2253,7 @@ const ChatPage: React.FC<ChatPageProps> = ({ sessionMgr, sessionId, sessionName,
const isNewAppend = messages.length > prevMsgCountRef.current;
prevMsgCountRef.current = messages.length;
if (isNewAppend && !isLoadingMore && isNearBottomRef.current) {
programmaticScrollRef.current = true;
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
}
}
Expand All @@ -2239,11 +2262,13 @@ const ChatPage: React.FC<ChatPageProps> = ({ sessionMgr, sessionId, sessionName,
useEffect(() => {
if (!initialScrollDone.current || !isStreaming) return;
if (!isNearBottomRef.current) return;
programmaticScrollRef.current = true;
messagesEndRef.current?.scrollIntoView({ behavior: 'auto' });
}, [activeTurn, isStreaming]);

useEffect(() => {
if (optimisticMsg) {
programmaticScrollRef.current = true;
isNearBottomRef.current = true;
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
}
Expand All @@ -2257,6 +2282,7 @@ const ChatPage: React.FC<ChatPageProps> = ({ sessionMgr, sessionId, sessionName,
if (!isNearBottomRef.current) return;
const gap = container.scrollHeight - container.scrollTop - container.clientHeight;
if (gap > 10 && gap < 400) {
programmaticScrollRef.current = true;
container.scrollTo({ top: container.scrollHeight, behavior: 'smooth' });
}
}, 300);
Expand Down Expand Up @@ -2692,8 +2718,22 @@ const ChatPage: React.FC<ChatPageProps> = ({ sessionMgr, sessionId, sessionName,
)}

<div ref={messagesEndRef} />

</div>

{showScrollToBottom && (
<button
type="button"
className="chat-page__scroll-to-bottom"
onClick={scrollToBottom}
aria-label={t('chat.scrollToBottom')}
>
<svg aria-hidden="true" focusable="false" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<polyline points="6 9 12 15 18 9" />
</svg>
</button>
)}

{/* Floating Input Bar — two-stage (matches desktop ChatInput) */}
<input
ref={fileInputRef}
Expand Down
46 changes: 46 additions & 0 deletions src/mobile-web/src/styles/components/chat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
display: flex;
flex-direction: column;
gap: var(--size-gap-4);
position: relative;
}

.chat-page__load-more-indicator {
Expand All @@ -142,6 +143,51 @@
padding: var(--size-gap-2) 0;
}

.chat-page__scroll-to-bottom {
position: fixed;
bottom: 110px;
left: 50%;
transform: translateX(-50%);
width: 40px;
height: 40px;
border-radius: 50%;
border: 1px solid var(--border-subtle);
background: var(--color-bg-elevated);
color: var(--color-text-primary);
box-shadow: var(--shadow-md);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
z-index: 15;
animation: scrollBtnIn 200ms var(--easing-standard);

&:active {
transform: translateX(-50%) scale(0.92);
box-shadow: var(--shadow-sm);
}

&:focus-visible {
outline: 2px solid var(--color-accent-500);
outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
animation: none;
}

@media (forced-colors: active) {
border: 2px solid ButtonText;
background: ButtonFace;
color: ButtonText;
}
}

@keyframes scrollBtnIn {
from { opacity: 0; transform: translateX(-50%) scale(0.7); }
to { opacity: 1; transform: translateX(-50%) scale(1); }
}

// Message items — FlowChat style (no bubbles)
.chat-msg {
display: flex;
Expand Down
Loading