Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadComposer.tsx

745 lines28.1 KB

1import type {
2 EnvironmentId,
3 MessageId,
4 ModelSelection,
5 OrchestrationThreadShell,
6 ProviderInteractionMode,
7 RuntimeMode,
8 ServerConfig as T3ServerConfig,
9} from "@t3tools/contracts";
10import { StackActions, useFocusEffect, useNavigation } from "@react-navigation/native";
11import type { ReactNode } from "react";
12import {
13 memo,
14 useCallback,
15 useEffect,
16 useLayoutEffect,
17 useMemo,
18 useRef,
19 useState,
20 type RefObject,
21} from "react";
22import {
23 ActivityIndicator,
24 Alert,
25 Image,
26 Platform,
27 Pressable,
28 View,
29 type ViewStyle,
30} from "react-native";
31import ImageViewing from "react-native-image-viewing";
32import Animated, {
33 FadeIn,
34 FadeInDown,
35 FadeOut,
36 FadeOutDown,
37 LinearTransition,
38 useAnimatedStyle,
39 useSharedValue,
40 withTiming,
41} from "react-native-reanimated";
42import { useUniwindTheme } from "../../lib/useUniwindTheme";
43import { armAgentAwarenessLiveActivityForLocalWork } from "../agent-awareness/remoteRegistration";
44import { scopedThreadKey } from "../../lib/scopedEntities";
45​
46import { AppText as Text } from "../../components/AppText";
47import { SymbolView } from "../../components/AppSymbol";
48import { ComposerAttachmentStrip } from "../../components/ComposerAttachmentStrip";
49import { GlassSurface } from "../../components/GlassSurface";
50import { ComposerEditor, type ComposerEditorHandle } from "../../components/ComposerEditor";
51import {
52 ComposerInlineControl,
53 ComposerToolbarButton,
54 ComposerToolbarRow,
55} from "../../components/ComposerToolbar";
56import { ControlPill } from "../../components/ControlPill";
57import { ProviderIcon } from "../../components/ProviderIcon";
58import type { DraftComposerAttachment } from "../../lib/composerImages";
59import { buildModelOptions, groupByProvider } from "../../lib/modelOptions";
60import { useScaledTextRole } from "../settings/appearance/useScaledTextRole";
61import type { RemoteClientConnectionState } from "../../lib/connection";
62import { resolveProviderOptionDescriptors } from "../../lib/providerOptions";
63import { ComposerCommandPopover } from "./ComposerCommandPopover";
64import { useComposerCommandMenu } from "./use-composer-command-menu";
65import {
66 type ExistingThreadSettingsRouteSession,
67 useExistingThreadSettingsRoutePresentation,
68} from "./ThreadSettingsSheet";
69import {
70 useThreadSettingsSheetPresentation,
71 type NavigationWithFinishTransitioning,
72} from "./use-thread-settings-sheet-presentation";
73​
74/**
75 * Height of the collapsed composer (pill + vertical padding, excluding safe-area inset).
76 * Exported so the parent can compute feed overlap / content insets.
77 */
78export const COMPOSER_COLLAPSED_CHROME = 60;
79​
80/**
81 * Height of the expanded composer (card + toolbar + vertical padding, excluding safe-area inset).
82 * Used by the parent to compute the larger feed bottom inset when the composer is focused.
83 */
84export const COMPOSER_EXPANDED_CHROME = 156;
85​
86export interface ThreadComposerProps {
87 readonly draftMessage: string;
88 readonly draftAttachments: ReadonlyArray<DraftComposerAttachment>;
89 readonly placeholder: string;
90 readonly contentMaxWidth?: number;
91 readonly bottomInset?: number;
92 readonly connectionState: RemoteClientConnectionState;
93 readonly connectionError: string | null;
94 readonly environmentLabel: string | null;
95 /**
96 * Message sync phase for the selected thread (drives the status pill):
97 * "loading" = first fetch, nothing to show yet; "syncing" = cached messages
98 * are on screen while they reconcile with the server.
99 */
100 readonly threadSyncPhase?: "loading" | "syncing" | null;
101 readonly selectedThread: OrchestrationThreadShell;
102 readonly serverConfig: T3ServerConfig | null;
103 readonly queueCount: number;
104 readonly environmentId: EnvironmentId;
105 readonly projectCwd: string | null;
106 readonly editorRef?: RefObject<ComposerEditorHandle | null>;
107 readonly onChangeDraftMessage: (value: string) => void;
108 readonly onPickDraftImages: () => Promise<void>;
109 readonly onPickDraftFiles: () => Promise<void>;
110 readonly onNativePasteImages: (uris: ReadonlyArray<string>) => Promise<void>;
111 readonly onRemoveDraftImage: (imageId: string) => void;
112 readonly onStopThread: () => void;
113 readonly onSendMessage: () => Promise<MessageId | null>;
114 readonly onUpdateModelSelection: (modelSelection: ModelSelection) => void;
115 readonly onUpdateRuntimeMode: (runtimeMode: RuntimeMode) => void;
116 readonly onUpdateInteractionMode: (interactionMode: ProviderInteractionMode) => void;
117 readonly onReconnectEnvironment: () => void;
118 readonly onExpandedChange?: (expanded: boolean) => void;
119 /** Fires on editor focus/blur; hosts use it to vet stale keyboard state. */
120 readonly onEditorFocusChange?: (focused: boolean) => void;
122​
123/**
124 * The pill / card container — renders with Expo's native GlassView on supported
125 * iOS 26+ devices and keeps the existing opaque fallback elsewhere.
126 * Exported so NewTaskDraftScreen can render the same composer chrome.
127 */
128// The bottom-anchored dock position and clipped surface height use the same
129// transition so the card grows upward without exposing its final-size content.
130// Android gets NO layout transition: the composer rides the keyboard via
131// KeyboardStickyView (frame-synced to the IME), and a time-based morph
132// running alongside that translate reads as jitter. Snapping the layout and
133// letting the keyboard-synced slide be the only motion looks native there.
134export const COMPOSER_TRANSITION_DURATION_MS = 220;
135export const COMPOSER_LAYOUT_TRANSITION =
136 Platform.OS === "android"
137 ? undefined
138 : LinearTransition.duration(COMPOSER_TRANSITION_DURATION_MS);
139​
140export function ComposerSurface(props: {
141 readonly children: ReactNode;
142 readonly style: ViewStyle;
143 /** Existing thread composers morph between pill and card layouts. */
144 readonly animateLayout?: boolean;
145}) {
146 const targetBorderRadius =
147 typeof props.style.borderRadius === "number" ? props.style.borderRadius : 0;
148 const animatedBorderRadius = useSharedValue(targetBorderRadius);
149 const shouldAnimate = props.animateLayout !== false && Platform.OS !== "android";
150 useLayoutEffect(() => {
151 animatedBorderRadius.value = shouldAnimate
152 ? withTiming(targetBorderRadius, {
153 duration: COMPOSER_TRANSITION_DURATION_MS,
154 })
155 : targetBorderRadius;
156 }, [animatedBorderRadius, shouldAnimate, targetBorderRadius]);
157 const animatedShapeStyle = useAnimatedStyle(() => ({
158 borderRadius: animatedBorderRadius.value,
159 }));
160​
161 // Clipping here keeps the expanded toolbar inside the glass while the
162 // bottom-anchored host owns the geometry transition.
163 return (
164 <Animated.View
165 className="shadow-[0_6px_28px] shadow-adaptive-black-a15-a35"
166 layout={props.animateLayout === false ? undefined : COMPOSER_LAYOUT_TRANSITION}
167 style={[
168 animatedShapeStyle,
169 {
170 overflow: "hidden",
171 // Android versions before 9 do not support outset box shadows.
172 elevation: Platform.OS === "android" && Platform.Version < 28 ? 10 : undefined,
173 },
174 ]}
175 >
176 <GlassSurface
177 chrome="none"
178 fallbackClassName="border border-border bg-card-translucent"
179 glassEffectStyle="regular"
180 // The composer is a passive material containing interactive controls.
181 // Keep native glass out of the interactive content's layout path.
182 pointerEvents="none"
183 tintColor="transparent"
184 style={{
185 position: "absolute",
186 inset: 0,
187 borderRadius: targetBorderRadius,
188 }}
189 >
190 {null}
191 </GlassSurface>
192 <View style={props.style}>{props.children}</View>
193 </Animated.View>
194 );
196​
197type ComposerStatusPillState = {
198 readonly kind: "unavailable" | "reconnecting" | "syncing";
199 readonly label: string;
200};
201​
202function composerConnectionStatus(input: {
203 readonly connectionError: string | null;
204 readonly connectionState: RemoteClientConnectionState;
205 readonly environmentLabel: string | null;
206 readonly threadSyncPhase?: "loading" | "syncing" | null;
207}): ComposerStatusPillState | null {
208 const environmentLabel = input.environmentLabel ?? "Environment";
209​
210 switch (input.connectionState) {
211 case "connecting":
212 case "reconnecting":
213 return {
214 kind: "reconnecting",
215 label:
216 input.connectionError === null
217 ? `Reconnecting to ${environmentLabel}...`
218 : `Failed to connect. Retrying ${environmentLabel}...`,
219 };
220 case "offline":
221 return { kind: "unavailable", label: "You are offline" };
222 case "error":
223 return {
224 kind: "unavailable",
225 label: input.connectionError
226 ? `Failed to connect to ${environmentLabel}: ${input.connectionError}`
227 : `Failed to connect to ${environmentLabel}`,
228 };
229 case "available":
230 return { kind: "unavailable", label: `${environmentLabel} is not connected` };
231 case "connected":
232 break;
233 }
234​
235 // Connected: the pill is the single loading/sync indicator. One stable
236 // label per open — "Loading" when starting from scratch, "Syncing" when
237 // cached messages are already visible.
238 switch (input.threadSyncPhase) {
239 case "loading":
240 return { kind: "syncing", label: "Loading messages..." };
241 case "syncing":
242 return { kind: "syncing", label: "Syncing messages..." };
243 default:
244 return null;
245 }
247​
248const ComposerConnectionStatusPill = memo(function ComposerConnectionStatusPill(props: {
249 readonly onPress: () => void;
250 readonly status: ComposerStatusPillState;
251}) {
252 const isReconnecting = props.status.kind !== "unavailable";
253 return (
254 <Animated.View
255 className="absolute inset-x-0 bottom-full items-center pb-2"
256 entering={FadeInDown.duration(180)}
257 exiting={FadeOutDown.duration(140)}
258 pointerEvents="box-none"
259 >
260 <Pressable
261 accessibilityRole="button"
262 onPress={props.onPress}
263 className="max-w-full flex-row items-center gap-2 rounded-full bg-card px-3 py-2 shadow-sm active:opacity-70"
264 >
265 {isReconnecting ? (
266 <ActivityIndicator size="small" colorClassName={"accent-icon-muted"} />
267 ) : (
268 <View className="h-2 w-2 rounded-full bg-red-500" />
269 )}
270 <Text
271 className="max-w-[260px] text-sm font-t3-bold leading-snug text-foreground"
272 numberOfLines={1}
273 >
274 {props.status.label}
275 </Text>
276 </Pressable>
277 </Animated.View>
278 );
279});
280​
281export const ThreadComposer = memo(function ThreadComposer(props: ThreadComposerProps) {
282 const navigation = useNavigation();
283 const foregroundColor = useUniwindTheme()["--color-foreground"];
284 const bodyText = useScaledTextRole("body");
285 const fallbackInputRef = useRef<ComposerEditorHandle>(null);
286 const inputRef = props.editorRef ?? fallbackInputRef;
287 const [isFocused, setIsFocused] = useState(false);
288 const settingsSheetPresentation = useThreadSettingsSheetPresentation({
289 editorRef: inputRef,
290 isEditorFocused: isFocused,
291 });
292 const settingsRoutePresentation = useExistingThreadSettingsRoutePresentation();
293 const settingsRoutePresentedRef = useRef(false);
294 const wasExpandedBeforePreviewRef = useRef(false);
295 const inFlightThreadIdsRef = useRef(new Set<string>());
296 const { onExpandedChange } = props;
297​
298 const [previewImageUri, setPreviewImageUri] = useState<string | null>(null);
299 const hasContent = props.draftMessage.trim().length > 0 || props.draftAttachments.length > 0;
300 // Opening and presentation count as active so the composer stays expanded
301 // while focus moves between its native editor and the settings picker.
302 const isExpanded = isFocused || settingsSheetPresentation.isActive;
303 const canSend = hasContent;
304​
305 // Keep the parent's feed inset synchronized while the settings sheet keeps
306 // the composer expanded between editor focus events.
307 useEffect(() => {
308 onExpandedChange?.(isExpanded);
309 }, [isExpanded, onExpandedChange]);
310​
311 const onPressImage = useCallback(
312 (uri: string) => {
313 wasExpandedBeforePreviewRef.current = isFocused;
314 setPreviewImageUri(uri);
315 },
316 [isFocused],
317 );
318​
319 const closePreview = useCallback(() => {
320 setPreviewImageUri(null);
321 if (wasExpandedBeforePreviewRef.current) {
322 setTimeout(() => inputRef.current?.focus(), 100);
323 }
324 }, [inputRef]);
325​
326 const onEditorFocusChange = props.onEditorFocusChange;
327 const handleFocus = useCallback(() => {
328 setIsFocused(true);
329 onExpandedChange?.(true);
330 onEditorFocusChange?.(true);
331 }, [onEditorFocusChange, onExpandedChange]);
332​
333 const handleBlur = useCallback(() => {
334 setIsFocused(false);
335 if (!settingsSheetPresentation.isActive) {
336 onExpandedChange?.(false);
337 }
338 onEditorFocusChange?.(false);
339 }, [onEditorFocusChange, onExpandedChange, settingsSheetPresentation.isActive]);
340 const showStopAction =
341 props.selectedThread.session?.status === "running" ||
342 props.selectedThread.session?.status === "starting";
343​
344 const sendLabel =
345 props.connectionState !== "connected" || props.queueCount > 0 ? "Queue" : "Send";
346 const currentModelSelection = props.selectedThread.modelSelection;
347 const currentRuntimeMode = props.selectedThread.runtimeMode;
348 const connectionStatus = composerConnectionStatus({
349 connectionError: props.connectionError,
350 connectionState: props.connectionState,
351 environmentLabel: props.environmentLabel,
352 threadSyncPhase: props.threadSyncPhase,
353 });
354 const selectedProviderStatus = useMemo(() => {
355 if (!props.serverConfig) return null;
356 return (
357 props.serverConfig.providers.find(
358 (p) => p.instanceId === props.selectedThread.modelSelection.instanceId,
359 ) ?? null
360 );
361 }, [props.serverConfig, props.selectedThread.modelSelection.instanceId]);
362​
363 const composerMenu = useComposerCommandMenu({
364 draftMessage: props.draftMessage,
365 environmentId: props.environmentId,
366 projectCwd: props.projectCwd,
367 selectedProviderStatus,
368 hasThread: true,
369 onChangeDraftMessage: props.onChangeDraftMessage,
370 onUpdateInteractionMode: props.onUpdateInteractionMode,
371 });
372 const { onSendMessage } = props;
373​
374 const handleSend = useCallback(async () => {
375 const threadKey = scopedThreadKey(props.environmentId, props.selectedThread.id);
376 if (inFlightThreadIdsRef.current.has(threadKey)) return;
377 inFlightThreadIdsRef.current.add(threadKey);
378 try {
379 const messageId = await onSendMessage();
380 if (messageId === null) {
381 return;
382 }
383 // Sending a prompt starts agent work: arm the lock-screen card while the
384 // app is foregrounded and the activity token can be registered. Armed
385 // after the send so its preference read and native Activity start don't
386 // contend with the queued-message feedback on the tap frame.
387 armAgentAwarenessLiveActivityForLocalWork({
388 environmentId: props.environmentId,
389 threadTitle: props.selectedThread.title,
390 projectTitle: props.environmentLabel ?? "T3 Code",
391 });
392 } finally {
393 inFlightThreadIdsRef.current.delete(threadKey);
394 }
395 }, [
396 onSendMessage,
397 props.environmentId,
398 props.environmentLabel,
399 props.selectedThread.id,
400 props.selectedThread.title,
401 ]);
402​
403 // ── Model menu ───────────────────────────────────────────
404 const modelOptions = useMemo(
405 () => buildModelOptions(props.serverConfig, currentModelSelection),
406 [props.serverConfig, currentModelSelection],
407 );
408 const providerGroups = useMemo(() => groupByProvider(modelOptions), [modelOptions]);
409 // An existing thread is bound to its harness: sessions can't move between
410 // provider instances, so the picker only offers the thread's own group.
411 const threadProviderGroups = useMemo(
412 () => providerGroups.filter((group) => group.providerKey === currentModelSelection.instanceId),
413 [providerGroups, currentModelSelection.instanceId],
414 );
415 const currentModelOption =
416 modelOptions.find(
417 (option) =>
418 option.selection.instanceId === currentModelSelection.instanceId &&
419 option.selection.model === currentModelSelection.model,
420 ) ?? null;
421 const providerOptionDescriptors = useMemo(
422 () =>
423 resolveProviderOptionDescriptors({
424 capabilities: currentModelOption?.capabilities,
425 selections: currentModelSelection.options,
426 }),
427 [currentModelOption?.capabilities, currentModelSelection.options],
428 );
429 const settingsOwnerId = scopedThreadKey(props.environmentId, props.selectedThread.id);
430 const settingsRouteSession = useMemo<ExistingThreadSettingsRouteSession>(
431 () => ({
432 ownerId: settingsOwnerId,
433 environmentId: props.environmentId,
434 providerGroups: threadProviderGroups,
435 selectedModel: currentModelSelection,
436 onSelectModel: (option) => props.onUpdateModelSelection(option.selection),
437 optionDescriptors: providerOptionDescriptors,
438 onUpdateOptionSelections: (options) =>
439 props.onUpdateModelSelection({ ...currentModelSelection, options }),
440 runtimeMode: currentRuntimeMode,
441 onUpdateRuntimeMode: props.onUpdateRuntimeMode,
442 }),
443 [
444 currentModelSelection,
445 currentRuntimeMode,
446 props.onUpdateModelSelection,
447 props.onUpdateRuntimeMode,
448 providerOptionDescriptors,
449 settingsOwnerId,
450 threadProviderGroups,
451 ],
452 );
453 const openSettings = useCallback(() => {
454 settingsRoutePresentation.present(settingsRouteSession);
455 settingsSheetPresentation.open();
456 }, [settingsRoutePresentation.present, settingsRouteSession, settingsSheetPresentation.open]);
457​
458 useEffect(() => {
459 if (settingsSheetPresentation.isActive) {
460 settingsRoutePresentation.present(settingsRouteSession);
461 }
462 }, [settingsRoutePresentation.present, settingsRouteSession, settingsSheetPresentation.isActive]);
463​
464 useEffect(() => {
465 if (!settingsSheetPresentation.isVisible || settingsRoutePresentedRef.current) {
466 return;
467 }
468​
469 settingsRoutePresentedRef.current = true;
470 navigation.dispatch(StackActions.push("ThreadSettingsSheet"));
471 }, [navigation, settingsSheetPresentation.isVisible]);
472​
473 useFocusEffect(
474 useCallback(() => {
475 if (!settingsRoutePresentedRef.current) {
476 return;
477 }
478​
479 settingsRoutePresentedRef.current = false;
480 settingsSheetPresentation.onDismissed();
481 settingsRoutePresentation.clear(settingsOwnerId);
482 }, [settingsOwnerId, settingsRoutePresentation.clear, settingsSheetPresentation.onDismissed]),
483 );
484​
485 useEffect(
486 () =>
487 // UIKit's completion callback for the sheet dismissal, surfaced by the
488 // native-stack patch. This is when the queued keyboard restore runs.
489 (navigation as unknown as NavigationWithFinishTransitioning).addListener(
490 "finishTransitioning",
491 settingsSheetPresentation.onStackTransitionsFinished,
492 ),
493 [navigation, settingsSheetPresentation.onStackTransitionsFinished],
494 );
495​
496 return (
497 <Animated.View
498 className="px-4"
499 style={{
500 paddingTop: isExpanded ? 8 : 6,
501 paddingBottom: (props.bottomInset ?? 0) + (isExpanded ? 8 : 6),
502 }}
503 >
504 {/* The backdrop gradient lives on a plain View: Reanimated's Animated.View
505 silently drops experimental_backgroundImage on Android, which left this
506 strip fully transparent and the feed text legible through the composer. */}
507 <View
508 className="absolute inset-0 bg-linear-to-b from-screen/0 via-screen/60 to-screen/90"
509 pointerEvents="none"
510 />
511 <Animated.View
512 className="relative w-full self-center"
513 style={{ maxWidth: props.contentMaxWidth }}
514 >
515 {composerMenu.trigger && composerMenu.items.length > 0 ? (
516 <View className="absolute inset-x-0 bottom-full z-10 mb-2">
517 <ComposerCommandPopover
518 items={composerMenu.items}
519 triggerKind={composerMenu.trigger.kind}
520 isLoading={composerMenu.isLoading}
521 onSelect={composerMenu.onSelect}
522 />
523 </View>
524 ) : null}
525​
526 {connectionStatus ? (
527 <ComposerConnectionStatusPill
528 status={connectionStatus}
529 onPress={props.onReconnectEnvironment}
530 />
531 ) : null}
532​
533 <ComposerSurface
534 style={
535 isExpanded
536 ? {
537 borderRadius: 26,
538 minHeight: 140,
539 overflow: "hidden" as const,
540 paddingBottom: 6,
541 paddingHorizontal: 14,
542 paddingTop: 14,
543 }
544 : {
545 // Keep the numeric radius close to the expanded card so the
546 // shape morph stays bounded while rendering as a capsule.
547 borderRadius: 27,
548 overflow: "hidden" as const,
549 paddingHorizontal: 14,
550 paddingVertical: 5,
551 }
552 }
553 >
554 {/* Attachment strip — inside the card, above the text input */}
555 {isExpanded ? (
556 <Animated.View
557 className={props.draftAttachments.length > 0 ? "pb-2.5" : undefined}
558 entering={FadeIn.duration(160)}
559 exiting={FadeOut.duration(120)}
560 >
561 <ComposerAttachmentStrip
562 attachments={props.draftAttachments}
563 onRemove={props.onRemoveDraftImage}
564 onPressImage={onPressImage}
565 />
566 </Animated.View>
567 ) : null}
568​
569 <View className={isExpanded ? undefined : "flex-row items-center"}>
570 <View className={isExpanded ? undefined : "min-w-0 flex-1"}>
571 <ComposerEditor
572 ref={inputRef}
573 multiline
574 value={props.draftMessage}
575 skills={selectedProviderStatus?.skills ?? []}
576 selection={composerMenu.selection}
577 onChangeText={props.onChangeDraftMessage}
578 onSelectionChange={composerMenu.onSelectionChange}
579 onPasteImages={(uris) => void props.onNativePasteImages(uris)}
580 placeholder={props.placeholder}
581 onFocus={handleFocus}
582 onBlur={handleBlur}
583 onSubmit={handleSend}
584 scrollEnabled={isExpanded}
585 // Android: collapsed single line centers natively (gravity) in
586 // a pill-height box matching the send button; iOS keeps insets.
587 singleLineCentered={!isExpanded}
588 contentInsetVertical={isExpanded || Platform.OS === "android" ? 0 : 6}
589 style={
590 isExpanded
591 ? {
592 minHeight: 72,
593 maxHeight: 160,
594 paddingHorizontal: 4,
595 paddingVertical: 4,
596 }
597 : {
598 height: 36,
599 paddingHorizontal: 4,
600 }
601 }
602 textStyle={{
603 ...bodyText,
604 color: foregroundColor,
605 }}
606 />
607 </View>
608 {!isExpanded && props.draftAttachments.length > 0 ? (
609 <View className="flex-row gap-1 pl-1">
610 {props.draftAttachments.slice(0, 3).map((attachment) =>
611 attachment.type === "image" ? (
612 <Pressable
613 key={attachment.id}
614 onPress={() => onPressImage(attachment.previewUri)}
615 >
616 <Image
617 source={{ uri: attachment.previewUri }}
618 className="size-[30px] rounded-lg bg-subtle"
619 resizeMode="cover"
620 />
621 </Pressable>
622 ) : (
623 <View
624 key={attachment.id}
625 className="size-[30px] items-center justify-center rounded-lg bg-subtle"
626 >
627 <SymbolView name="doc.text" size={15} tintColor="#a3a3a3" type="monochrome" />
628 </View>
629 ),
630 )}
631 {props.draftAttachments.length > 3 ? (
632 <View className="size-[30px] items-center justify-center rounded-lg bg-subtle-strong">
633 <Text className="text-foreground-muted text-2xs font-t3-bold">
634 +{props.draftAttachments.length - 3}
635 </Text>
636 </View>
637 ) : null}
638 </View>
639 ) : null}
640 {!isExpanded ? (
641 <Animated.View entering={FadeIn.duration(180)} exiting={FadeOut.duration(100)}>
642 {showStopAction ? (
643 <ControlPill icon="stop.fill" variant="danger" onPress={props.onStopThread} />
644 ) : (
645 <ControlPill
646 icon="arrow.up"
647 variant="primary"
648 disabled={!canSend}
649 onPress={handleSend}
650 />
651 )}
652 </Animated.View>
653 ) : null}
654 </View>
655 <View
656 accessibilityElementsHidden={!isExpanded}
657 collapsable={false}
658 importantForAccessibility={isExpanded ? "auto" : "no-hide-descendants"}
659 pointerEvents={isExpanded ? "auto" : "none"}
660 style={
661 isExpanded
662 ? undefined
663 : {
664 height: 0,
665 opacity: 0,
666 overflow: "hidden",
667 }
668 }
669 >
670 <ComposerToolbarRow paddingBottom={0} paddingHorizontal={0} paddingTop={4}>
671 <View className="min-w-0 flex-1 flex-row items-center gap-2">
672 <ComposerToolbarButton
673 accessibilityLabel="Add attachment"
674 icon="plus"
675 onPress={() => {
676 if (props.serverConfig?.environment.capabilities.fileAttachments) {
677 Alert.alert("Add attachment", undefined, [
678 { text: "Photos", onPress: () => void props.onPickDraftImages() },
679 { text: "Files", onPress: () => void props.onPickDraftFiles() },
680 { text: "Cancel", style: "cancel" },
681 ]);
682 return;
683 }
684 void props.onPickDraftImages();
685 }}
686 showChevron={false}
687 />
688 <View className="min-w-0 flex-1" style={{ maxWidth: 152 }}>
689 <ComposerInlineControl
690 accessibilityLabel="Model and reasoning settings"
691 emphasized
692 iconNode={
693 <ProviderIcon provider={currentModelOption?.providerDriver} size={16} />
694 }
695 label={currentModelOption?.label ?? currentModelSelection.model}
696 maxWidth={152}
697 onPress={openSettings}
698 />
699 </View>
700 </View>
701 <View className="shrink-0 flex-row items-center gap-2">
702 <ComposerToolbarButton
703 accessibilityLabel={sendLabel}
704 icon="arrow.up"
705 variant="primary"
706 disabled={!canSend}
707 onPress={handleSend}
708 showChevron={false}
709 />
710 {showStopAction ? (
711 <ComposerToolbarButton
712 accessibilityLabel="Stop"
713 icon="stop.fill"
714 variant="danger"
715 onPress={props.onStopThread}
716 showChevron={false}
717 />
718 ) : null}
719 </View>
720 </ComposerToolbarRow>
721 </View>
722 </ComposerSurface>
723​
724 {/* Queue count */}
725 {props.queueCount > 0 ? (
726 <Animated.View entering={FadeIn.duration(180)} exiting={FadeOut.duration(120)}>
727 <Text className="pt-2 text-xs text-foreground-muted">
728 {props.queueCount} queued message{props.queueCount === 1 ? "" : "s"} will send
729 automatically.
730 </Text>
731 </Animated.View>
732 ) : null}
733 </Animated.View>
734​
735 <ImageViewing
736 images={previewImageUri ? [{ uri: previewImageUri }] : []}
737 imageIndex={0}
738 visible={previewImageUri !== null}
739 onRequestClose={closePreview}
740 swipeToCloseEnabled
741 doubleTapToZoomEnabled
742 />
743 </Animated.View>
744 );
745});