Skip to content
Merged
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
22 changes: 19 additions & 3 deletions apps/mobile/src/features/threads/QuestionAttachments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useNativePaste } from "../../lib/useNativePaste";
import { convertPastedImagesToAttachments } from "../../lib/composerImages";
import { PROVIDER_SEND_TURN_MAX_ATTACHMENTS, type UserInputQuestion } from "@t3tools/contracts";
import { useAtomValue } from "@effect/atom-react";
import { View } from "react-native";
import { View, type TextInputInstance } from "react-native";
import { useEffect, useEffectEvent, useRef, useState } from "react";
import { ComposerAttachmentButton } from "./ComposerAttachmentButton";
import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
Expand Down Expand Up @@ -64,6 +64,18 @@ export function QuestionAttachments(props: {
});
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- releases keyboard ownership on unmount, since an unmounted native input never emits blur
useEffect(() => () => releaseFocus(), []);
// A controlled value makes Fabric rebuild the native text on every keystroke, which discards
// iOS's pending autocorrection. The input owns its text; the only outside write is an option
// selection clearing the draft.
const inputRef = useRef<TextInputInstance>(null);
const [initialText] = useState(props.value);
const nativeText = useRef(props.value);
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- pushes an option selection's cleared draft into the uncontrolled native input
useEffect(() => {
if (props.value !== "" || nativeText.current === "") return;
nativeText.current = "";
inputRef.current?.clear();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}, [props.value]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
const append = (
key: string,
attachments: Parameters<typeof appendComposerDraftAttachments>[1],
Expand Down Expand Up @@ -195,11 +207,15 @@ export function QuestionAttachments(props: {
<VideoPreviewModal source={previewVideo} onRequestClose={() => setPreviewVideo(null)} />
<TextInputWrapper onPaste={paste}>
<TextInput
value={props.value}
ref={inputRef}
defaultValue={initialText}
multiline={props.question.initialAnswer !== undefined}
submitBehavior={props.question.initialAnswer !== undefined ? "newline" : undefined}
editable={!props.disabled}
onChangeText={props.onChangeText}
onChangeText={(text) => {
nativeText.current = text;
props.onChangeText(text);
}}
onFocus={() => {
focusedRef.current = true;
onInputFocusChange?.(true);
Expand Down
Loading