Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions apps/mobile/src/screens/session-composer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, jest, test } from "@jest/globals";
import type { AgentInfo, ModelInfo, ModelRef } from "@opencode2-mobile/opencode-adapter";
import { fireEvent, render, screen, within } from "@testing-library/react-native";
import { useState } from "react";
import { Keyboard } from "react-native";

import type { PromptDelivery } from "./prompt-admission-model";
import { SessionComposer } from "./session-composer";
Expand Down Expand Up @@ -31,6 +32,22 @@ test("keeps the native prompt multiline and submits through an explicit control"
expect(onSubmit).toHaveBeenCalledTimes(1);
});

test("dismisses the keyboard and collapses the composer after sending", () => {
const dismissKeyboard = jest.spyOn(Keyboard, "dismiss").mockImplementation(() => undefined);
render(<ComposerHarness onSubmit={jest.fn()} />);

const input = screen.getByLabelText("Prompt");
fireEvent.changeText(input, "Ship it");
fireEvent(input, "focus");
expect(input.props.numberOfLines).toBe(4);

fireEvent.press(screen.getByRole("button", { name: "Send" }));

expect(dismissKeyboard).toHaveBeenCalledTimes(1);
expect(screen.getByLabelText("Prompt").props.numberOfLines).toBe(1);
dismissKeyboard.mockRestore();
});

test("keeps controls collapsed until the editor is focused", () => {
render(<ComposerHarness onSubmit={jest.fn()} />);

Expand Down
9 changes: 4 additions & 5 deletions apps/mobile/src/screens/session-composer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AgentInfo, ModelInfo, ModelRef } from "@opencode2-mobile/opencode-adapter";
import { useDeferredValue, useRef, useState } from "react";
import { Pressable, ScrollView, StyleSheet, Text, TextInput, View } from "react-native";
import { useDeferredValue, useState } from "react";
import { Keyboard, Pressable, ScrollView, StyleSheet, Text, TextInput, View } from "react-native";

import { ModalSheet } from "../components/modal-sheet";
import { palette, radius, space, typeRamp } from "../theme";
Expand Down Expand Up @@ -43,7 +43,6 @@ export function SessionComposer({
onModelChange: (model: ModelRef) => void;
onSubmit: () => void;
}) {
const inputRef = useRef<TextInput>(null);
const [agentPickerOpen, setAgentPickerOpen] = useState(false);
const [focused, setFocused] = useState(false);
const [modelPickerOpen, setModelPickerOpen] = useState(false);
Expand All @@ -69,7 +68,8 @@ export function SessionComposer({
function submit() {
if (!canSubmit) return;
onSubmit();
requestAnimationFrame(() => inputRef.current?.focus());
setFocused(false);
Keyboard.dismiss();
}

return (
Expand All @@ -91,7 +91,6 @@ export function SessionComposer({
onFocus={() => setFocused(true)}
placeholder={active ? "Add a follow-up" : "Ask OpenCode"}
placeholderTextColor={palette.dim}
ref={inputRef}
returnKeyType="default"
scrollEnabled={expanded}
selectionColor={palette.signal}
Expand Down