@@ -136,6 +136,7 @@ import {
136136} from "./pendingUserInputLayout" ;
137137import {
138138 COMPOSER_COLLAPSED_CHROME ,
139+ COMPOSER_DICTATION_REVIEW_CHROME ,
139140 COMPOSER_EXPANDED_CHROME ,
140141 COMPOSER_LAYOUT_TRANSITION ,
141142 COMPOSER_TRANSITION_DURATION_MS ,
@@ -411,7 +412,25 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
411412 const lastScrolledSubmittedMessageIdRef = useRef < MessageId | null > ( null ) ;
412413 const [ composerExpanded , setComposerExpanded ] = useState ( false ) ;
413414 const [ composerFocused , setComposerFocused ] = useState ( false ) ;
415+ const composerFocusedThreadKeyRef = useRef < string | null > ( null ) ;
416+ const [ dictationReviewThreadKey , setDictationReviewThreadKey ] = useState < string | null > ( null ) ;
417+ const isReviewingDictation = dictationReviewThreadKey === selectedThreadKey && ! composerFocused ;
418+ const dismissDictationReview = ( ) =>
419+ setDictationReviewThreadKey ( ( current ) => ( current === selectedThreadKey ? null : current ) ) ;
420+ const handleDictationComplete = ( ) => {
421+ // The voice session retains its startup callback. Focus must stay current and
422+ // belong to that thread, even when another composer is now on screen.
423+ if ( composerFocusedThreadKeyRef . current !== selectedThreadKey ) {
424+ setDictationReviewThreadKey ( selectedThreadKey ) ;
425+ }
426+ } ;
414427 const handleComposerFocusChange = ( focused : boolean ) => {
428+ if ( focused ) {
429+ composerFocusedThreadKeyRef . current = selectedThreadKey ;
430+ dismissDictationReview ( ) ;
431+ } else if ( composerFocusedThreadKeyRef . current === selectedThreadKey ) {
432+ composerFocusedThreadKeyRef . current = null ;
433+ }
415434 setComposerFocused ( focused ) ;
416435 handleOwnedInputFocusChange ( focused ) ;
417436 } ;
@@ -424,7 +443,9 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
424443 // the hide animation, so the composer would ride down flush to the screen edge and then snap up
425444 // into the inset.
426445 const composerBottomInset = (
427- Platform . OS === "android" ? isKeyboardVisible : composerExpanded || composerFocused
446+ Platform . OS === "android"
447+ ? isKeyboardVisible
448+ : ! isReviewingDictation && ( composerExpanded || composerFocused )
428449 )
429450 ? 0
430451 : Math . max ( insets . bottom , 12 ) ;
@@ -536,7 +557,11 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
536557 ) ||
537558 ( props . historyControls ?. hasMoreHistory === true &&
538559 props . selectedThread . latestUserMessageAt !== null ) ;
539- const composerChrome = composerExpanded ? COMPOSER_EXPANDED_CHROME : COMPOSER_COLLAPSED_CHROME ;
560+ const composerChrome = isReviewingDictation
561+ ? COMPOSER_DICTATION_REVIEW_CHROME
562+ : composerExpanded
563+ ? COMPOSER_EXPANDED_CHROME
564+ : COMPOSER_COLLAPSED_CHROME ;
540565 const composerOverlapHeight = composerChrome + composerBottomInset ;
541566 const [ collapsedUserInputRequestId , setCollapsedUserInputRequestId ] =
542567 useState < RuntimeRequestId | null > ( null ) ;
@@ -779,7 +804,9 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
779804
780805 useLayoutEffect ( ( ) => {
781806 selectedThreadKeyRef . current = selectedThreadKey ;
807+ composerEditorRef . current ?. blur ( ) ;
782808 // A replaced or unmounted native editor may not emit a blur event.
809+ composerFocusedThreadKeyRef . current = null ;
783810 setComposerFocused ( false ) ;
784811 } , [ selectedThreadKey , showContent ] ) ;
785812
@@ -900,10 +927,18 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
900927
901928 const handleSendMessage = async ( followUp ?: ActiveTurnComposerAction ) => {
902929 const targetThreadKey = selectedThreadKey ;
930+ const targetDraftKey = props . composerDraftKey ?? targetThreadKey ;
903931 const hasUserMessage = selectedThreadFeed . some (
904932 ( entry ) => entry . type === "message" && entry . message . role === "user" ,
905933 ) ;
906934 const messageId = await props . onSendMessage ( followUp ) ;
935+ const remainingDraft = getComposerDraftSnapshot ( targetDraftKey ) ;
936+ if (
937+ messageId !== null ||
938+ ( remainingDraft . text . length === 0 && remainingDraft . attachments . length === 0 )
939+ ) {
940+ dismissDictationReview ( ) ;
941+ }
907942 if ( messageId === null || selectedThreadKeyRef . current !== targetThreadKey ) {
908943 return messageId ;
909944 }
@@ -943,6 +978,7 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
943978 } ;
944979
945980 const collapseComposer = ( ) => {
981+ dismissDictationReview ( ) ;
946982 composerEditorRef . current ?. blur ( ) ;
947983 } ;
948984
@@ -1337,6 +1373,8 @@ export const ThreadDetailScreen = function ThreadDetailScreen(props: ThreadDetai
13371373 }
13381374 bottomInset = { composerBottomInset }
13391375 onChangeDraftMessage = { props . onChangeDraftMessage }
1376+ isReviewingDictation = { isReviewingDictation }
1377+ onDictationComplete = { handleDictationComplete }
13401378 onPickDraftMedia = { props . onPickDraftMedia }
13411379 onPickDraftFiles = { props . onPickDraftFiles }
13421380 onNativePasteImages = { props . onNativePasteImages }
0 commit comments