@@ -6,7 +6,7 @@ import { convertPastedImagesToAttachments } from "../../lib/composerImages";
66import { PROVIDER_SEND_TURN_MAX_ATTACHMENTS , type UserInputQuestion } from "@t3tools/contracts" ;
77import { useAtomValue } from "@effect/atom-react" ;
88import { View } from "react-native" ;
9- import { useEffect , useRef , useState } from "react" ;
9+ import { useEffect , useEffectEvent , useRef , useState } from "react" ;
1010import { ComposerAttachmentButton } from "./ComposerAttachmentButton" ;
1111import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip" ;
1212import { pickComposerFiles , pickComposerMedia } from "../../lib/composerImages" ;
@@ -49,6 +49,14 @@ export function QuestionAttachments(props: {
4949 props . requestId ,
5050 props . question . id ,
5151 ] ) ;
52+ // A focused input that unmounts never delivers its onBlur, so release focus here or
53+ // the screen would keep treating the keyboard as owned by a removed input.
54+ const focusedRef = useRef ( false ) ;
55+ const onInputFocusChange = props . onInputFocusChange ;
56+ const releaseFocus = useEffectEvent ( ( ) => {
57+ if ( focusedRef . current ) onInputFocusChange ?.( false ) ;
58+ } ) ;
59+ useEffect ( ( ) => ( ) => releaseFocus ( ) , [ ] ) ;
5260 const pickerScope = useRef < { key : string ; active : boolean } | null > ( null ) ;
5361 useEffect ( ( ) => {
5462 const scope = { key : scopeKey , active : true } ;
@@ -197,8 +205,14 @@ export function QuestionAttachments(props: {
197205 submitBehavior = { props . question . initialAnswer !== undefined ? "newline" : undefined }
198206 editable = { ! props . disabled }
199207 onChangeText = { props . onChangeText }
200- onFocus = { ( ) => props . onInputFocusChange ?.( true ) }
201- onBlur = { ( ) => props . onInputFocusChange ?.( false ) }
208+ onFocus = { ( ) => {
209+ focusedRef . current = true ;
210+ onInputFocusChange ?.( true ) ;
211+ } }
212+ onBlur = { ( ) => {
213+ focusedRef . current = false ;
214+ onInputFocusChange ?.( false ) ;
215+ } }
202216 placeholder = "Or type a custom answer"
203217 className = "min-h-[54px] rounded-2xl border border-input-border bg-input px-3.5 py-3 font-sans text-base text-foreground"
204218 />
0 commit comments