Skip to content

Commit 62834cd

Browse files
shivamhwpclaude
andcommitted
fix(mobile): keep iOS autocorrect in custom question answers
The custom-answer field was a controlled TextInput, so every keystroke changed its text prop and Fabric rebuilt the native attributed string. That reassignment drops the pending autocorrection, so typos stayed as typed while the native composer, which syncs by revision, corrected them. Setting autoCorrect and spellCheck did not help and is removed. The input is now uncontrolled: it starts from the stored draft and reports changes to it as before. The only outside write while it is mounted, an option selection clearing the draft, clears the native input through its ref. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7c6330f commit 62834cd

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useNativePaste } from "../../lib/useNativePaste";
77
import { convertPastedImagesToAttachments } from "../../lib/composerImages";
88
import { PROVIDER_SEND_TURN_MAX_ATTACHMENTS, type UserInputQuestion } from "@t3tools/contracts";
99
import { useAtomValue } from "@effect/atom-react";
10-
import { View } from "react-native";
10+
import { View, type TextInputInstance } from "react-native";
1111
import { useEffect, useEffectEvent, useRef, useState } from "react";
1212
import { ComposerAttachmentButton } from "./ComposerAttachmentButton";
1313
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
@@ -64,6 +64,18 @@ export function QuestionAttachments(props: {
6464
});
6565
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- releases keyboard ownership on unmount, since an unmounted native input never emits blur
6666
useEffect(() => () => releaseFocus(), []);
67+
// A controlled value makes Fabric rebuild the native text on every keystroke, which discards
68+
// iOS's pending autocorrection. The input owns its text; the only outside write is an option
69+
// selection clearing the draft.
70+
const inputRef = useRef<TextInputInstance>(null);
71+
const [initialText] = useState(props.value);
72+
const nativeText = useRef(props.value);
73+
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- pushes an option selection's cleared draft into the uncontrolled native input
74+
useEffect(() => {
75+
if (props.value !== "" || nativeText.current === "") return;
76+
nativeText.current = "";
77+
inputRef.current?.clear();
78+
}, [props.value]);
6779
const append = (
6880
key: string,
6981
attachments: Parameters<typeof appendComposerDraftAttachments>[1],
@@ -195,13 +207,15 @@ export function QuestionAttachments(props: {
195207
<VideoPreviewModal source={previewVideo} onRequestClose={() => setPreviewVideo(null)} />
196208
<TextInputWrapper onPaste={paste}>
197209
<TextInput
198-
value={props.value}
210+
ref={inputRef}
211+
defaultValue={initialText}
199212
multiline={props.question.initialAnswer !== undefined}
200213
submitBehavior={props.question.initialAnswer !== undefined ? "newline" : undefined}
201214
editable={!props.disabled}
202-
autoCorrect
203-
spellCheck
204-
onChangeText={props.onChangeText}
215+
onChangeText={(text) => {
216+
nativeText.current = text;
217+
props.onChangeText(text);
218+
}}
205219
onFocus={() => {
206220
focusedRef.current = true;
207221
onInputFocusChange?.(true);

0 commit comments

Comments
 (0)