Skip to content

Commit 5ab1bdd

Browse files
juliusmarmingePixPMusicclaude
committed
fix(android): a question input that unmounts while focused releases the keyboard
A focused question input that unmounts (collapsed, submitted, or resolved elsewhere) never delivers its onBlur, so the screen kept treating the keyboard as owned and skipped the resume quarantine. The input now releases focus on unmount. The quarantine comment no longer claims every stranded case starts with a blur: Back hides the keyboard and keeps focus. Co-authored-by: Pixel Perfect <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2b4ca2b commit 5ab1bdd

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎apps/mobile/src/features/threads/QuestionAttachments.tsx‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { convertPastedImagesToAttachments } from "../../lib/composerImages";
66
import { PROVIDER_SEND_TURN_MAX_ATTACHMENTS, type UserInputQuestion } from "@t3tools/contracts";
77
import { useAtomValue } from "@effect/atom-react";
88
import { View } from "react-native";
9-
import { useEffect, useRef, useState } from "react";
9+
import { useEffect, useEffectEvent, useRef, useState } from "react";
1010
import { ComposerAttachmentButton } from "./ComposerAttachmentButton";
1111
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
1212
import { 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
/>

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
365365
// keyboard library's height AND visibility then stay frozen open, so gating the sticky
366366
// translation on visibility alone still strands the composer after resume. An input that kept
367367
// focus through the switch is exempt: Android restores its keyboard unchanged, so no keyboard
368-
// or focus event would ever lift the quarantine. The stranded case always starts with a blur.
368+
// or focus event would ever lift the quarantine. Hiding the keyboard with Back keeps focus, so
369+
// Back then Home mid-hide takes the exemption and can still strand the composer.
369370
const [keyboardStateSuspect, setKeyboardStateSuspect] = useState(false);
370371
const ownedInputFocusedRef = useRef(false);
371372
useEffect(() => {

0 commit comments

Comments
 (0)