Skip to content

Commit 3614f1f

Browse files
juliusmarmingecodex
andcommitted
fix(mobile): make Android composer focus authoritative
Co-authored-by: codex <[email protected]>
1 parent 3624790 commit 3614f1f

2 files changed

Lines changed: 7 additions & 27 deletions

File tree

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,9 @@ export function NewTaskDraftScreen(props: {
613613

614614
const isAndroid = Platform.OS === "android";
615615
const isDarkMode = colorScheme === "dark";
616-
// Mirrors ThreadComposer: collapsed pill until focused, and typed content
617-
// keeps it expanded after blur.
618-
const hasContent = flow.prompt.trim().length > 0 || flow.attachments.length > 0;
619-
const isExpanded = !isAndroid || isComposerFocused || hasContent;
616+
// Android expansion follows native editor focus so relayout cannot race
617+
// the touch gesture that opens the keyboard.
618+
const isExpanded = !isAndroid || isComposerFocused;
620619
const canStart =
621620
Boolean(flow.selectedProject) &&
622621
Boolean(flow.selectedModel) &&

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

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -261,24 +261,15 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
261261
const fallbackInputRef = useRef<ComposerEditorHandle>(null);
262262
const inputRef = props.editorRef ?? fallbackInputRef;
263263
const [isFocused, setIsFocused] = useState(false);
264-
// Android: expansion starts on touch-down. Waiting for the native focus
265-
// event to round-trip through JS starts the 220ms morph after the IME is
266-
// already animating in, so the two play serially and look jittery.
267-
const [eagerExpand, setEagerExpand] = useState(false);
268264
const wasExpandedBeforePreviewRef = useRef(false);
269265
const inFlightThreadIdsRef = useRef(new Set<string>());
270266
const { onExpandedChange } = props;
271267

272268
const [previewImageUri, setPreviewImageUri] = useState<string | null>(null);
273269
const hasContent = props.draftMessage.trim().length > 0 || props.draftAttachments.length > 0;
274-
const isExpanded = isFocused || eagerExpand || (Platform.OS === "android" && hasContent);
270+
const isExpanded = isFocused;
275271
const canSend = hasContent;
276272

277-
useEffect(() => {
278-
if (Platform.OS !== "android") return;
279-
onExpandedChange?.(isExpanded);
280-
}, [isExpanded, onExpandedChange]);
281-
282273
const onPressImage = useCallback(
283274
(uri: string) => {
284275
wasExpandedBeforePreviewRef.current = isFocused;
@@ -296,17 +287,12 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
296287

297288
const handleFocus = useCallback(() => {
298289
setIsFocused(true);
299-
if (Platform.OS !== "android") {
300-
onExpandedChange?.(true);
301-
}
290+
onExpandedChange?.(true);
302291
}, [onExpandedChange]);
303292

304293
const handleBlur = useCallback(() => {
305294
setIsFocused(false);
306-
setEagerExpand(false);
307-
if (Platform.OS !== "android") {
308-
onExpandedChange?.(false);
309-
}
295+
onExpandedChange?.(false);
310296
}, [onExpandedChange]);
311297
const showStopAction =
312298
props.selectedThread.session?.status === "running" ||
@@ -778,12 +764,7 @@ export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposer
778764
</Animated.View>
779765
) : null}
780766

781-
<View
782-
className={isExpanded ? undefined : "min-w-0 flex-1"}
783-
onTouchStart={
784-
Platform.OS === "android" && !isExpanded ? () => setEagerExpand(true) : undefined
785-
}
786-
>
767+
<View className={isExpanded ? undefined : "min-w-0 flex-1"}>
787768
<ComposerEditor
788769
ref={inputRef}
789770
multiline

0 commit comments

Comments
 (0)