Open History to see the last commit
1import { DEFAULT_TERMINAL_ID, EnvironmentId, ThreadId } from "@t3tools/contracts";
2import { type KnownTerminalSession } from "@t3tools/client-runtime/state/terminal";
3import type { MenuAction } from "@react-native-menu/menu";
4import { SymbolView } from "../../components/AppSymbol";
5import { NativeHeaderToolbar, NativeStackScreenOptions } from "../../native/StackHeader";
6import { StackActions, useNavigation, type StaticScreenProps } from "@react-navigation/native";
7import { useCallback, useEffect, useMemo, useRef, useState } from "react";
8import { Platform, Pressable, View } from "react-native";
9import {
10 KeyboardController,
11 KeyboardEvents,
12 KeyboardStickyView,
13 useKeyboardState,
14} from "react-native-keyboard-controller";
15
16import { AndroidHeaderIconButton, AndroidScreenHeader } from "../../components/AndroidScreenHeader";
17import {
18 ComposerToolbarButton,
19 ComposerToolbarRow,
20 ComposerToolbarScroller,
21} from "../../components/ComposerToolbar";
22import { ControlPillMenu } from "../../components/ControlPill";
23import { EmptyState } from "../../components/EmptyState";
24import { GlassSurface } from "../../components/GlassSurface";
25import { LoadingScreen } from "../../components/LoadingScreen";
26import { environmentCatalog } from "../../connection/catalog";
27import { useEnvironmentPresentation } from "../../state/presentation";
28import { terminalEnvironment } from "../../state/terminal";
29import { useAtomCommand } from "../../state/use-atom-command";
30import { useWorkspaceState } from "../../state/workspace";
31import {
32 MAX_TERMINAL_FONT_SIZE,
33 MIN_TERMINAL_FONT_SIZE,
34 TERMINAL_FONT_SIZE_STEP,
35 stepTerminalFontSize,
36} from "../../lib/appearancePreferences";
37import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
38import {
39 useAttachedTerminalSession,
40 useKnownTerminalSessions,
41} from "../../state/use-terminal-session";
42import { useThreadSelection } from "../../state/use-thread-selection";
43import { useSelectedThreadDetail } from "../../state/use-thread-detail";
44import { EnvironmentConnectionNotice } from "../connection/EnvironmentConnectionNotice";
45import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
46import { TerminalSurface } from "./NativeTerminalSurface";
47import { getMobileTerminalTheme } from "./terminalTheme";
48import { terminalDebugLog } from "./terminalDebugLog";
49import {
50 getTerminalBufferReplayKey,
51 getTerminalSurfaceReplayBuffer,
52 TERMINAL_BUFFER_REPLAY_STABILITY_DELAY_MS,
53} from "./terminalBufferReplay";
54import {
55 resolveTerminalOpenLocation,
56 takePendingTerminalLaunch,
57 type PendingTerminalLaunch,
58} from "./terminalLaunchContext";
59import {
60 basename,
61 buildTerminalMenuSessions,
62 getTerminalStatusLabel,
63 nextOpenTerminalId,
64 previousLiveTerminalId,
65 resolveTerminalSessionLabel,
66 type TerminalMenuSession,
67} from "./terminalMenu";
68import { cacheTerminalGridSize, getCachedTerminalGridSize } from "./terminalUiState";
69
70const DEFAULT_TERMINAL_COLS = 80;
71const DEFAULT_TERMINAL_ROWS = 24;
72const TERMINAL_ACCESSORY_HEIGHT = 52;
73const SHOWCASE_ENABLED = process.env.EXPO_PUBLIC_SHOWCASE === "1";
74
75type PendingModifier = "ctrl" | "meta";
76type HostPlatform = "mac" | "linux" | "windows" | "unknown";
77
78type TerminalToolbarAction =
79 | { readonly kind: "send"; readonly key: string; readonly label: string; readonly data: string }
80 | { readonly kind: "clear"; readonly key: string; readonly label: string }
81 | {
82 readonly kind: "modifier";
83 readonly key: string;
84 readonly label: string;
85 readonly modifier: PendingModifier;
86 };
87
88function firstRouteParam(value: string | string[] | undefined): string | null {
89 if (Array.isArray(value)) {
90 return value[0] ?? null;
91 }
92
93 return value ?? null;
94}
95
96function inferHostPlatform(environmentLabel: string | null): HostPlatform {
97 const value = environmentLabel?.toLowerCase() ?? "";
98 if (
99 value.includes("mac") ||
100 value.includes("macbook") ||
101 value.includes("mac mini") ||
102 value.includes("imac") ||
103 value.includes("darwin")
104 ) {
105 return "mac";
106 }
107 if (value.includes("windows") || value.includes("win")) {
108 return "windows";
109 }
110 if (value.includes("linux") || value.includes("ubuntu") || value.includes("debian")) {
111 return "linux";
112 }
113
114 return "unknown";
115}
116
117function applyCtrlModifier(input: string): string {
118 const firstCharacter = input[0];
119 if (!firstCharacter) {
120 return input;
121 }
122
123 const lowerCharacter = firstCharacter.toLowerCase();
124 if (lowerCharacter >= "a" && lowerCharacter <= "z") {
125 return String.fromCharCode(lowerCharacter.charCodeAt(0) - 96);
126 }
127
128 if (firstCharacter === "@") return "\u0000";
129 if (firstCharacter === "[") return "\u001b";
130 if (firstCharacter === "\\") return "\u001c";
131 if (firstCharacter === "]") return "\u001d";
132 if (firstCharacter === "^") return "\u001e";
133 if (firstCharacter === "_") return "\u001f";
134 if (firstCharacter === "?") return "\u007f";
135
136 return input;
137}
138
139function pickRunningTerminalSessionForBootstrap(
140 sessions: ReadonlyArray<KnownTerminalSession>,
141): KnownTerminalSession | null {
142 const running = sessions.filter(
143 (session) => session.state.status === "running" || session.state.status === "starting",
144 );
145 if (running.length === 0) {
146 return null;
147 }
148 return (
149 running.find((session) => session.target.terminalId === DEFAULT_TERMINAL_ID) ??
150 running[0] ??
151 null
152 );
153}
154
155type ThreadTerminalRouteScreenProps = StaticScreenProps<{
156 readonly environmentId: string;
157 readonly threadId: string;
158 readonly terminalId?: string;
159}>;
160
161export function ThreadTerminalRouteScreen(props: ThreadTerminalRouteScreenProps) {
162 const navigation = useNavigation();
163 const writeTerminal = useAtomCommand(terminalEnvironment.write, "terminal write");
164 const resizeTerminal = useAtomCommand(terminalEnvironment.resize, "terminal resize");
165 const clearTerminal = useAtomCommand(terminalEnvironment.clear, "terminal clear");
166 const closeTerminal = useAtomCommand(terminalEnvironment.close, "terminal close");
167 const openTerminal = useAtomCommand(terminalEnvironment.open, "terminal open");
168 const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
169 const { state: workspaceState } = useWorkspaceState();
170 const { layout, panes, togglePrimarySidebar } = useAdaptiveWorkspaceLayout();
171 const params = props.route.params;
172 const { selectedThread, selectedThreadProject, selectedEnvironmentConnection } =
173 useThreadSelection();
174 const selectedThreadDetail = useSelectedThreadDetail();
175 const routeEnvironmentIdRaw = firstRouteParam(params.environmentId);
176 const routeThreadIdRaw = firstRouteParam(params.threadId);
177 const routeEnvironmentId = routeEnvironmentIdRaw
178 ? EnvironmentId.make(routeEnvironmentIdRaw)
179 : null;
180 const routeThreadId = routeThreadIdRaw ? ThreadId.make(routeThreadIdRaw) : null;
181 const environment = useEnvironmentPresentation(routeEnvironmentId);
182 const isEnvironmentReady = environment.presentation?.connection.phase === "connected";
183 const requestedTerminalId = firstRouteParam(params.terminalId);
184 const terminalId = requestedTerminalId ?? DEFAULT_TERMINAL_ID;
185 const {
186 isReady: hasResolvedFontPreference,
187 appearance,
188 themeAppearance: appearanceScheme,
189 themeId,
190 setTerminalFontSize,
191 } = useAppearancePreferences();
192 const fontSize = appearance.terminalFontSize;
193 const cachedRouteGridSize =
194 routeEnvironmentId && routeThreadId
195 ? getCachedTerminalGridSize({
196 environmentId: routeEnvironmentId,
197 threadId: routeThreadId,
198 terminalId,
199 })
200 : null;
201 const knownSessions = useKnownTerminalSessions({
202 environmentId: selectedThread?.environmentId ?? null,
203 threadId: selectedThread?.id ?? null,
204 });
205 const runningSession = useMemo(
206 () => pickRunningTerminalSessionForBootstrap(knownSessions),
207 [knownSessions],
208 );
209 const activeKnownSession = useMemo(
210 () => knownSessions.find((session) => session.target.terminalId === terminalId) ?? null,
211 [knownSessions, terminalId],
212 );
213 const launchTarget = useMemo(
214 () =>
215 selectedThread
216 ? {
217 environmentId: selectedThread.environmentId,
218 threadId: selectedThread.id,
219 terminalId,
220 }
221 : null,
222 [selectedThread, terminalId],
223 );
224 const launchTargetKey = launchTarget
225 ? `${launchTarget.environmentId}:${launchTarget.threadId}:${launchTarget.terminalId}`
226 : null;
227 const [pendingLaunchEntry, setPendingLaunchEntry] = useState<{
228 readonly key: string | null;
229 readonly launch: PendingTerminalLaunch | null;
230 }>(() => ({
231 key: launchTargetKey,
232 launch: launchTarget === null ? null : takePendingTerminalLaunch(launchTarget),
233 }));
234 const pendingLaunch =
235 pendingLaunchEntry.key === launchTargetKey ? pendingLaunchEntry.launch : null;
236 const hasResolvedPendingLaunch = pendingLaunchEntry.key === launchTargetKey;
237 const [initialAttachGridEntry, setInitialAttachGridEntry] = useState(() => ({
238 key: launchTargetKey,
239 size: cachedRouteGridSize ?? {
240 cols: DEFAULT_TERMINAL_COLS,
241 rows: DEFAULT_TERMINAL_ROWS,
242 },
243 }));
244 const initialAttachGridSize =
245 initialAttachGridEntry.key === launchTargetKey ? initialAttachGridEntry.size : null;
246 const [lastGridSize, setLastGridSize] = useState(
247 cachedRouteGridSize ?? {
248 cols: DEFAULT_TERMINAL_COLS,
249 rows: DEFAULT_TERMINAL_ROWS,
250 },
251 );
252 const [keyboardFocusRequest, setKeyboardFocusRequest] = useState(0);
253 const [isAccessoryDismissed, setIsAccessoryDismissed] = useState(false);
254 const bufferReplayTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
255 const firstNonEmptyBufferLoggedRef = useRef(false);
256 const lastBufferReplayKeyRef = useRef<string | null>(null);
257 const sentInitialInputKeyRef = useRef<string | null>(null);
258 const [readyBufferReplayKey, setReadyBufferReplayKey] = useState<string | null>(null);
259 /** Default grid is always valid for attach; onResize refines cols/rows. Requiring a cached size blocked bootstrap for new terminal routes. */
260 const [hasMeasuredSurface, setHasMeasuredSurface] = useState(true);
261 const [pendingModifierState, setPendingModifierState] = useState<{
262 readonly terminalId: string;
263 readonly value: PendingModifier | null;
264 }>({
265 terminalId,
266 value: null,
267 });
268 const shouldRedirectToRunningTerminal =
269 requestedTerminalId === null &&
270 runningSession !== null &&
271 runningSession.target.terminalId !== terminalId;
272 const launchLocationCandidate = useMemo(() => {
273 if (!selectedThread || !selectedThreadProject?.workspaceRoot) {
274 return null;
275 }
276 if (pendingLaunch) {
277 return {
278 cwd: pendingLaunch.cwd,
279 worktreePath: pendingLaunch.worktreePath,
280 };
281 }
282 return resolveTerminalOpenLocation({
283 terminalLocation: activeKnownSession?.state.summary ?? null,
284 activeSessionLocation: activeKnownSession?.state.summary ?? null,
285 workspaceRoot: selectedThreadProject.workspaceRoot,
286 threadShellWorktreePath: selectedThread.worktreePath ?? null,
287 threadDetailWorktreePath: selectedThreadDetail?.worktreePath ?? null,
288 });
289 }, [
290 activeKnownSession?.state.summary,
291 pendingLaunch,
292 selectedThread,
293 selectedThreadDetail?.worktreePath,
294 selectedThreadProject?.workspaceRoot,
295 ]);
296 const [initialLaunchLocationEntry, setInitialLaunchLocationEntry] = useState(() => ({
297 key: launchTargetKey,
298 location: launchLocationCandidate,
299 }));
300 const launchLocation =
301 initialLaunchLocationEntry.key === launchTargetKey ? initialLaunchLocationEntry.location : null;
302 const terminalAttachInput = useMemo(
303 () =>
304 selectedThread !== null &&
305 launchLocation !== null &&
306 hasResolvedPendingLaunch &&
307 initialAttachGridSize !== null &&
308 hasResolvedFontPreference &&
309 hasMeasuredSurface &&
310 isEnvironmentReady &&
311 !shouldRedirectToRunningTerminal
312 ? {
313 threadId: selectedThread.id,
314 terminalId,
315 cwd: launchLocation.cwd,
316 worktreePath: launchLocation.worktreePath,
317 cols: initialAttachGridSize.cols,
318 rows: initialAttachGridSize.rows,
319 ...(pendingLaunch?.env ? { env: pendingLaunch.env } : {}),
320 ...(pendingLaunch ? { restartIfNotRunning: true } : {}),
321 }
322 : null,
323 [
324 hasMeasuredSurface,
325 hasResolvedFontPreference,
326 hasResolvedPendingLaunch,
327 initialAttachGridSize,
328 isEnvironmentReady,
329 launchLocation,
330 pendingLaunch,
331 selectedThread,
332 shouldRedirectToRunningTerminal,
333 terminalId,
334 ],
335 );
336 const terminal = useAttachedTerminalSession({
337 environmentId: selectedThread?.environmentId ?? null,
338 terminal: terminalAttachInput,
339 });
340 const terminalKey = selectedThread
341 ? `${selectedThread.environmentId}:${selectedThread.id}:${terminalId}`
342 : terminalId;
343 const bufferReplayKey = useMemo(
344 () => getTerminalBufferReplayKey({ terminalKey, fontSize }),
345 [fontSize, terminalKey],
346 );
347 if (lastBufferReplayKeyRef.current === null) {
348 lastBufferReplayKeyRef.current = bufferReplayKey;
349 }
350 const terminalSurfaceBuffer = getTerminalSurfaceReplayBuffer({
351 buffer: terminal.buffer,
352 replayKey: bufferReplayKey,
353 readyReplayKey: readyBufferReplayKey,
354 });
355 const isRunning = terminal.status === "running" || terminal.status === "starting";
356
357 // When the process ends while this screen is attached (e.g. typing `exit`),
358 // close the session and leave the screen, mirroring the web drawer's
359 // onSessionExited flow. Only react to a running -> exited transition
360 // observed on this screen so already-exited sessions can still be opened
361 // (they restart on attach).
362 const runningTerminalKeyRef = useRef<string | null>(null);
363 const reopenedStaleTerminalKeyRef = useRef<string | null>(null);
364 const pendingExitNavigationRef = useRef<string | null>(null);
365
366 // Attach subscriptions are cached with an idle TTL, so revisiting a
367 // terminal whose session ended while unobserved reuses the stale stream
368 // without a new attach RPC — the server never respawns anything. Detect
369 // that (dead status with processed events, never seen running here) and
370 // issue an explicit open; its snapshot flows into the live subscription.
371 useEffect(() => {
372 if (isRunning) {
373 reopenedStaleTerminalKeyRef.current = null;
374 return;
375 }
376 if (
377 terminalAttachInput === null ||
378 !selectedThread ||
379 (terminal.status !== "closed" && terminal.status !== "exited") ||
380 terminal.version === 0 ||
381 runningTerminalKeyRef.current === terminalKey ||
382 reopenedStaleTerminalKeyRef.current === terminalKey
383 ) {
384 return;
385 }
386 reopenedStaleTerminalKeyRef.current = terminalKey;
387 void openTerminal({
388 environmentId: selectedThread.environmentId,
389 input: {
390 threadId: selectedThread.id,
391 terminalId,
392 cwd: terminalAttachInput.cwd,
393 worktreePath: terminalAttachInput.worktreePath,
394 cols: terminalAttachInput.cols,
395 rows: terminalAttachInput.rows,
396 ...(terminalAttachInput.env ? { env: terminalAttachInput.env } : {}),
397 },
398 }).then((result) => {
399 // Release the guard on failure so a later render can retry the respawn.
400 if (result._tag === "Failure" && reopenedStaleTerminalKeyRef.current === terminalKey) {
401 reopenedStaleTerminalKeyRef.current = null;
402 }
403 });
404 }, [
405 isRunning,
406 openTerminal,
407 selectedThread,
408 terminal.status,
409 terminal.version,
410 terminalAttachInput,
411 terminalId,
412 terminalKey,
413 ]);
414
415 useEffect(() => {
416 terminalDebugLog("surface:props", {
417 terminalKey,
418 atomBufferLen: terminal.buffer.length,
419 surfaceBufferLen: terminalSurfaceBuffer.length,
420 replayKey: bufferReplayKey,
421 readyReplayKey: readyBufferReplayKey,
422 status: terminal.status,
423 version: terminal.version,
424 });
425 }, [
426 bufferReplayKey,
427 readyBufferReplayKey,
428 terminal.buffer.length,
429 terminal.status,
430 terminal.version,
431 terminalKey,
432 terminalSurfaceBuffer.length,
433 ]);
434
435 useEffect(() => {
436 terminalDebugLog("session:status", {
437 terminalKey,
438 status: terminal.status,
439 error: terminal.error,
440 summary: terminal.summary?.cwd ?? null,
441 bufferLen: terminal.buffer.length,
442 version: terminal.version,
443 });
444 }, [
445 terminal.buffer.length,
446 terminal.error,
447 terminal.status,
448 terminal.summary?.cwd,
449 terminal.version,
450 terminalKey,
451 ]);
452
453 useEffect(() => {
454 if (terminal.buffer.length === 0 || firstNonEmptyBufferLoggedRef.current) {
455 return;
456 }
457 firstNonEmptyBufferLoggedRef.current = true;
458 terminalDebugLog("session:first-nonempty-buffer", {
459 terminalKey,
460 length: terminal.buffer.length,
461 preview: terminal.buffer.slice(0, 160),
462 });
463 }, [terminal.buffer, terminal.buffer.length, terminalKey]);
464 const cwd = terminal.summary?.cwd ?? selectedThreadProject?.workspaceRoot ?? null;
465 const hostPlatform = useMemo(
466 () => inferHostPlatform(selectedEnvironmentConnection?.environmentLabel ?? null),
467 [selectedEnvironmentConnection?.environmentLabel],
468 );
469
470 const terminalTheme = getMobileTerminalTheme(themeId, appearanceScheme);
471 const usesNativeHeaderGlass = Platform.OS === "ios";
472 const pendingModifier =
473 pendingModifierState.terminalId === terminalId ? pendingModifierState.value : null;
474 const headerSubtitle = selectedThreadProject?.title ?? "";
475 const terminalToolbarActions = useMemo<ReadonlyArray<TerminalToolbarAction>>(() => {
476 const modifierActions: ReadonlyArray<TerminalToolbarAction> =
477 hostPlatform === "mac"
478 ? [
479 { kind: "modifier", key: "cmd", label: "cmd", modifier: "meta" },
480 { kind: "modifier", key: "ctrl", label: "ctrl", modifier: "ctrl" },
481 ]
482 : [
483 { kind: "modifier", key: "ctrl", label: "ctrl", modifier: "ctrl" },
484 { kind: "modifier", key: "alt", label: "alt", modifier: "meta" },
485 ];
486
487 return [
488 { kind: "send", key: "esc", label: "esc", data: "\u001b" },
489 ...modifierActions,
490 { kind: "send", key: "tab", label: "tab", data: "\t" },
491 { kind: "clear", key: "clear", label: "clear" },
492 { kind: "send", key: "up", label: "↑", data: "\u001b[A" },
493 { kind: "send", key: "down", label: "↓", data: "\u001b[B" },
494 { kind: "send", key: "left", label: "←", data: "\u001b[D" },
495 { kind: "send", key: "right", label: "→", data: "\u001b[C" },
496 { kind: "send", key: "tilde", label: "~", data: "~" },
497 { kind: "send", key: "pipe", label: "|", data: "|" },
498 { kind: "send", key: "slash", label: "/", data: "/" },
499 { kind: "send", key: "dash", label: "-", data: "-" },
500 ];
501 }, [hostPlatform]);
502 const keyboardState = useKeyboardState((state) => ({
503 height: state.height,
504 isVisible: state.isVisible,
505 }));
506 const isAccessoryVisible = keyboardState.isVisible && !isAccessoryDismissed;
507 const terminalBottomInset =
508 (keyboardState.isVisible ? keyboardState.height : 0) +
509 (isAccessoryVisible ? TERMINAL_ACCESSORY_HEIGHT : 0);
510
511 useEffect(() => {
512 const keyboardWillShow = KeyboardEvents.addListener("keyboardWillShow", () => {
513 setIsAccessoryDismissed(false);
514 });
515 const keyboardWillHide = KeyboardEvents.addListener("keyboardWillHide", () => {
516 setIsAccessoryDismissed(true);
517 });
518
519 return () => {
520 keyboardWillShow.remove();
521 keyboardWillHide.remove();
522 };
523 }, []);
524
525 const terminalMenuSessions = useMemo<ReadonlyArray<TerminalMenuSession>>(
526 () =>
527 buildTerminalMenuSessions({
528 knownSessions,
529 workspaceRoot: selectedThreadProject?.workspaceRoot ?? null,
530 currentSession: {
531 terminalId,
532 cwd: cwd ?? null,
533 status: terminal.status,
534 hasRunningSubprocess: terminal.hasRunningSubprocess,
535 displayLabel: resolveTerminalSessionLabel(terminalId, terminal.summary),
536 updatedAt: terminal.updatedAt,
537 },
538 }),
539 [
540 cwd,
541 knownSessions,
542 selectedThreadProject?.workspaceRoot,
543 terminal.hasRunningSubprocess,
544 terminal.summary,
545 terminal.status,
546 terminal.updatedAt,
547 terminalId,
548 ],
549 );
550
551 useEffect(() => {
552 if (pendingLaunchEntry.key === launchTargetKey) {
553 return;
554 }
555 setPendingLaunchEntry({
556 key: launchTargetKey,
557 launch: launchTarget === null ? null : takePendingTerminalLaunch(launchTarget),
558 });
559 }, [launchTarget, launchTargetKey, pendingLaunchEntry.key]);
560
561 useEffect(() => {
562 if (initialAttachGridEntry.key === launchTargetKey) {
563 return;
564 }
565 setInitialAttachGridEntry({
566 key: launchTargetKey,
567 size: cachedRouteGridSize ?? {
568 cols: DEFAULT_TERMINAL_COLS,
569 rows: DEFAULT_TERMINAL_ROWS,
570 },
571 });
572 }, [cachedRouteGridSize, initialAttachGridEntry.key, launchTargetKey]);
573
574 useEffect(() => {
575 if (
576 initialLaunchLocationEntry.key === launchTargetKey &&
577 initialLaunchLocationEntry.location !== null
578 ) {
579 return;
580 }
581 if (initialLaunchLocationEntry.key === launchTargetKey && launchLocationCandidate === null) {
582 return;
583 }
584 setInitialLaunchLocationEntry({
585 key: launchTargetKey,
586 location: launchLocationCandidate,
587 });
588 }, [
589 initialLaunchLocationEntry.key,
590 initialLaunchLocationEntry.location,
591 launchLocationCandidate,
592 launchTargetKey,
593 ]);
594
595 useEffect(() => {
596 if (!shouldRedirectToRunningTerminal || !selectedThread || !runningSession) {
597 return;
598 }
599 navigation.dispatch(
600 StackActions.replace("ThreadTerminal", {
601 environmentId: String(selectedThread.environmentId),
602 threadId: String(selectedThread.id),
603 terminalId: runningSession.target.terminalId,
604 }),
605 );
606 }, [navigation, runningSession, selectedThread, shouldRedirectToRunningTerminal]);
607
608 useEffect(() => {
609 const initialInput = pendingLaunch?.initialInput;
610 if (
611 !initialInput ||
612 !selectedThread ||
613 terminal.version === 0 ||
614 sentInitialInputKeyRef.current === launchTargetKey
615 ) {
616 return;
617 }
618 sentInitialInputKeyRef.current = launchTargetKey;
619 void writeTerminal({
620 environmentId: selectedThread.environmentId,
621 input: {
622 threadId: selectedThread.id,
623 terminalId,
624 data: initialInput,
625 },
626 });
627 }, [
628 launchTargetKey,
629 pendingLaunch?.initialInput,
630 selectedThread,
631 terminal.version,
632 terminalId,
633 writeTerminal,
634 ]);
635
636 useEffect(() => {
637 firstNonEmptyBufferLoggedRef.current = false;
638 sentInitialInputKeyRef.current = null;
639 }, [terminalKey]);
640
641 const clearBufferReplayTimer = useCallback(() => {
642 if (bufferReplayTimerRef.current !== null) {
643 clearTimeout(bufferReplayTimerRef.current);
644 bufferReplayTimerRef.current = null;
645 }
646 }, []);
647
648 const scheduleBufferReplayReady = useCallback(() => {
649 clearBufferReplayTimer();
650 const replayKey = bufferReplayKey;
651 terminalDebugLog("replay:schedule-ready", {
652 replayKey,
653 delayMs: TERMINAL_BUFFER_REPLAY_STABILITY_DELAY_MS,
654 });
655 bufferReplayTimerRef.current = setTimeout(() => {
656 bufferReplayTimerRef.current = null;
657 setReadyBufferReplayKey(replayKey);
658 terminalDebugLog("replay:ready", { replayKey });
659 }, TERMINAL_BUFFER_REPLAY_STABILITY_DELAY_MS);
660 }, [bufferReplayKey, clearBufferReplayTimer]);
661
662 useEffect(() => {
663 if (lastBufferReplayKeyRef.current === bufferReplayKey) {
664 return;
665 }
666
667 lastBufferReplayKeyRef.current = bufferReplayKey;
668 clearBufferReplayTimer();
669 setReadyBufferReplayKey(null);
670 }, [bufferReplayKey, clearBufferReplayTimer]);
671
672 useEffect(() => clearBufferReplayTimer, [clearBufferReplayTimer]);
673
674 useEffect(() => {
675 if (!routeEnvironmentId || !routeThreadId) {
676 setLastGridSize({
677 cols: DEFAULT_TERMINAL_COLS,
678 rows: DEFAULT_TERMINAL_ROWS,
679 });
680 return;
681 }
682
683 setLastGridSize(
684 getCachedTerminalGridSize({
685 environmentId: routeEnvironmentId,
686 threadId: routeThreadId,
687 terminalId,
688 }) ?? {
689 cols: DEFAULT_TERMINAL_COLS,
690 rows: DEFAULT_TERMINAL_ROWS,
691 },
692 );
693 setHasMeasuredSurface(true);
694 }, [routeEnvironmentId, routeThreadId, terminalId]);
695
696 const writeInput = useCallback(
697 (data: string) => {
698 if (!selectedThread || !isRunning) {
699 return;
700 }
701
702 void writeTerminal({
703 environmentId: selectedThread.environmentId,
704 input: {
705 threadId: selectedThread.id,
706 terminalId,
707 data,
708 },
709 });
710 },
711 [isRunning, selectedThread, terminalId, writeTerminal],
712 );
713
714 const handleInput = useCallback(
715 (data: string) => {
716 if (data.length === 0) {
717 return;
718 }
719
720 if (pendingModifier === "ctrl") {
721 setPendingModifierState({ terminalId, value: null });
722 writeInput(applyCtrlModifier(data));
723 } else if (pendingModifier === "meta") {
724 setPendingModifierState({ terminalId, value: null });
725 writeInput(`\u001b${data}`);
726 } else {
727 writeInput(data);
728 }
729 },
730 [pendingModifier, terminalId, writeInput],
731 );
732
733 const handleResize = useCallback(
734 (size: { readonly cols: number; readonly rows: number }) => {
735 terminalDebugLog("native:onResize", {
736 cols: size.cols,
737 rows: size.rows,
738 terminalKey,
739 });
740 setHasMeasuredSurface(true);
741 if (readyBufferReplayKey !== bufferReplayKey) {
742 scheduleBufferReplayReady();
743 }
744 if (routeEnvironmentId && routeThreadId) {
745 cacheTerminalGridSize(
746 {
747 environmentId: routeEnvironmentId,
748 threadId: routeThreadId,
749 terminalId,
750 },
751 size,
752 );
753 }
754 if (size.cols === lastGridSize.cols && size.rows === lastGridSize.rows) {
755 return;
756 }
757
758 setLastGridSize(size);
759 if (!selectedThread || !isRunning) {
760 return;
761 }
762
763 void resizeTerminal({
764 environmentId: selectedThread.environmentId,
765 input: {
766 threadId: selectedThread.id,
767 terminalId,
768 cols: size.cols,
769 rows: size.rows,
770 },
771 });
772 },
773 [
774 isRunning,
775 lastGridSize.cols,
776 lastGridSize.rows,
777 bufferReplayKey,
778 readyBufferReplayKey,
779 routeEnvironmentId,
780 routeThreadId,
781 resizeTerminal,
782 scheduleBufferReplayReady,
783 selectedThread,
784 terminalId,
785 terminalKey,
786 ],
787 );
788
789 const handleSelectTerminal = useCallback(
790 (nextTerminalId: string) => {
791 if (!selectedThread || nextTerminalId === terminalId) {
792 return;
793 }
794
795 navigation.dispatch(
796 StackActions.replace("ThreadTerminal", {
797 environmentId: String(selectedThread.environmentId),
798 threadId: String(selectedThread.id),
799 terminalId: nextTerminalId,
800 }),
801 );
802 },
803 [navigation, selectedThread, terminalId],
804 );
805
806 const navigateAwayAfterExit = useCallback(() => {
807 // With other shells still live, fall through to the previous one instead
808 // of dropping the user back on the thread.
809 const fallbackTerminalId = previousLiveTerminalId({
810 sessions: terminalMenuSessions,
811 exitedTerminalId: terminalId,
812 });
813 if (fallbackTerminalId !== null && selectedThread) {
814 navigation.dispatch(
815 StackActions.replace("ThreadTerminal", {
816 environmentId: String(selectedThread.environmentId),
817 threadId: String(selectedThread.id),
818 terminalId: fallbackTerminalId,
819 }),
820 );
821 return;
822 }
823 if (navigation.canGoBack()) {
824 navigation.goBack();
825 return;
826 }
827 // Deep-linked/root mounts have nothing to pop; land on the thread
828 // instead of stranding the user on a dead terminal.
829 if (selectedThread) {
830 navigation.dispatch(
831 StackActions.replace("Thread", {
832 environmentId: String(selectedThread.environmentId),
833 threadId: String(selectedThread.id),
834 }),
835 );
836 }
837 }, [navigation, selectedThread, terminalId, terminalMenuSessions]);
838
839 useEffect(() => {
840 // Detached (hidden surface or environment drop): forget the running
841 // marker so a reattach takes the stale-reopen path instead of misreading
842 // the dead snapshot as an exit observed on this screen. A pending exit
843 // navigation stays armed — it only clears once the session runs again —
844 // so refocusing a dead screen still leaves it.
845 if (terminalAttachInput === null) {
846 runningTerminalKeyRef.current = null;
847 return;
848 }
849 if (isRunning) {
850 runningTerminalKeyRef.current = terminalKey;
851 // The session came back (e.g. respawned elsewhere) before the user
852 // returned; a stale pending exit must not eject a live terminal.
853 pendingExitNavigationRef.current = null;
854 return;
855 }
856 // The web drawer treats both exited and closed as session end.
857 const sessionEnded = terminal.status === "exited" || terminal.status === "closed";
858 if (!sessionEnded || runningTerminalKeyRef.current !== terminalKey) {
859 return;
860 }
861 runningTerminalKeyRef.current = null;
862 // Mark this key handled so the stale-attach effect doesn't respawn the
863 // session the user just ended.
864 reopenedStaleTerminalKeyRef.current = terminalKey;
865 if (selectedThread) {
866 void closeTerminal({
867 environmentId: selectedThread.environmentId,
868 input: {
869 threadId: selectedThread.id,
870 terminalId,
871 },
872 });
873 }
874 if (navigation.isFocused()) {
875 navigateAwayAfterExit();
876 return;
877 }
878 // An unfocused screen can't navigate; leave when the user returns so
879 // they never land on the dead session.
880 pendingExitNavigationRef.current = terminalKey;
881 }, [
882 closeTerminal,
883 isRunning,
884 navigateAwayAfterExit,
885 navigation,
886 selectedThread,
887 terminal.status,
888 terminalAttachInput,
889 terminalId,
890 terminalKey,
891 ]);
892
893 useEffect(
894 () =>
895 navigation.addListener("focus", () => {
896 if (pendingExitNavigationRef.current !== terminalKey) {
897 return;
898 }
899 pendingExitNavigationRef.current = null;
900 navigateAwayAfterExit();
901 }),
902 [navigateAwayAfterExit, navigation, terminalKey],
903 );
904
905 const handleOpenNewTerminal = useCallback(() => {
906 if (!selectedThread) {
907 return;
908 }
909
910 navigation.dispatch(
911 StackActions.replace("ThreadTerminal", {
912 environmentId: String(selectedThread.environmentId),
913 threadId: String(selectedThread.id),
914 terminalId: nextOpenTerminalId({
915 listedTerminalIds: terminalMenuSessions.map((session) => session.terminalId),
916 activeRouteTerminalId: terminalId,
917 }),
918 }),
919 );
920 }, [navigation, selectedThread, terminalId, terminalMenuSessions]);
921
922 const handleDecreaseFontSize = useCallback(() => {
923 setTerminalFontSize(stepTerminalFontSize(fontSize, -1));
924 }, [fontSize, setTerminalFontSize]);
925
926 const handleIncreaseFontSize = useCallback(() => {
927 setTerminalFontSize(stepTerminalFontSize(fontSize, 1));
928 }, [fontSize, setTerminalFontSize]);
929
930 // Android mirror of the iOS NativeHeaderToolbar terminal menu below: text
931 // size, session switching, and "Open new terminal", rendered through the
932 // token-styled anchored menu (the native header items are iOS-only).
933 const androidTerminalMenuActions = useMemo<MenuAction[]>(
934 () => [
935 {
936 id: "text-size",
937 title: "Text size",
938 subactions: [
939 {
940 id: "font-decrease",
941 title: `A- ${Math.max(MIN_TERMINAL_FONT_SIZE, fontSize - TERMINAL_FONT_SIZE_STEP).toFixed(1)} pt`,
942 attributes: fontSize <= MIN_TERMINAL_FONT_SIZE ? { disabled: true } : undefined,
943 },
944 {
945 id: "font-increase",
946 title: `A+ ${Math.min(MAX_TERMINAL_FONT_SIZE, fontSize + TERMINAL_FONT_SIZE_STEP).toFixed(1)} pt`,
947 attributes: fontSize >= MAX_TERMINAL_FONT_SIZE ? { disabled: true } : undefined,
948 },
949 ],
950 },
951 ...terminalMenuSessions.map((session): MenuAction => ({
952 id: `terminal-session:${session.terminalId}`,
953 title: session.displayLabel,
954 subtitle: [getTerminalStatusLabel({ status: session.status }), basename(session.cwd)]
955 .filter(Boolean)
956 .join(" · "),
957 state: session.terminalId === terminalId ? ("on" as const) : undefined,
958 })),
959 {
960 id: "terminal-new",
961 title: "Open new terminal",
962 image: "plus",
963 subtitle: `Start another shell in ${basename(selectedThreadProject?.workspaceRoot ?? null) ?? "this workspace"}`,
964 },
965 ],
966 [fontSize, selectedThreadProject?.workspaceRoot, terminalId, terminalMenuSessions],
967 );
968
969 const handleAndroidTerminalMenuAction = useCallback(
970 (event: { nativeEvent: { event: string } }) => {
971 const id = event.nativeEvent.event;
972 if (id === "font-decrease") {
973 handleDecreaseFontSize();
974 return;
975 }
976 if (id === "font-increase") {
977 handleIncreaseFontSize();
978 return;
979 }
980 if (id === "terminal-new") {
981 handleOpenNewTerminal();
982 return;
983 }
984 if (id.startsWith("terminal-session:")) {
985 handleSelectTerminal(id.slice("terminal-session:".length));
986 }
987 },
988 [handleDecreaseFontSize, handleIncreaseFontSize, handleOpenNewTerminal, handleSelectTerminal],
989 );
990
991 const handleClearTerminal = useCallback(() => {
992 if (!selectedThread) {
993 return;
994 }
995
996 setPendingModifierState({ terminalId, value: null });
997 void clearTerminal({
998 environmentId: selectedThread.environmentId,
999 input: {
1000 threadId: selectedThread.id,
1001 terminalId,
1002 },
1003 });
1004 }, [clearTerminal, selectedThread, terminalId]);
1005
1006 const handleToolbarActionPress = useCallback(
1007 (action: TerminalToolbarAction) => {
1008 if (action.kind === "modifier") {
1009 setPendingModifierState((current) => ({
1010 terminalId,
1011 value:
1012 (current.terminalId === terminalId ? current.value : null) === action.modifier
1013 ? null
1014 : action.modifier,
1015 }));
1016 return;
1017 }
1018
1019 if (action.kind === "clear") {
1020 handleClearTerminal();
1021 return;
1022 }
1023
1024 setPendingModifierState({ terminalId, value: null });
1025 if (pendingModifier === "ctrl") {
1026 writeInput(applyCtrlModifier(action.data));
1027 } else if (pendingModifier === "meta") {
1028 writeInput(`\u001b${action.data}`);
1029 } else {
1030 writeInput(action.data);
1031 }
1032 },
1033 [handleClearTerminal, pendingModifier, terminalId, writeInput],
1034 );
1035
1036 const handleDismissKeyboard = useCallback(() => {
1037 setIsAccessoryDismissed(true);
1038 void KeyboardController.dismiss();
1039 }, []);
1040
1041 const handleShowKeyboard = useCallback(() => {
1042 setKeyboardFocusRequest((current) => current + 1);
1043 }, []);
1044 const handleRetryEnvironment = useCallback(() => {
1045 if (routeEnvironmentId !== null) {
1046 void retryEnvironment(routeEnvironmentId);
1047 }
1048 }, [retryEnvironment, routeEnvironmentId]);
1049
1050 if (!selectedThread) {
1051 if (workspaceState.isLoadingConnections) {
1052 return <LoadingScreen message="Opening terminal…" />;
1053 }
1054
1055 return (
1056 <View className="flex-1 bg-screen">
1057 <EmptyState
1058 title="Thread unavailable"
1059 detail="This terminal route needs an active thread and workspace."
1060 />
1061 </View>
1062 );
1063 }
1064
1065 if (!selectedThreadProject?.workspaceRoot) {
1066 return (
1067 <View className="flex-1 bg-screen">
1068 <EmptyState
1069 title="Terminal unavailable"
1070 detail="This thread does not have a workspace root yet, so there is nowhere to open a shell."
1071 />
1072 </View>
1073 );
1074 }
1075
1076 if (!environment.isReady && environment.presentation === null) {
1077 return <LoadingScreen message="Opening terminal…" />;
1078 }
1079
1080 return (
1081 <>
1082 <NativeStackScreenOptions
1083 options={{
1084 // Static header config lives in Stack.tsx (SOLID_HEADER_OPTIONS — the pty
1085 // scrolls internally, nothing for glass to sample). Default title/subtitle
1086 // styling, like every other page.
1087 // Android draws its own in-flow header (AndroidScreenHeader below);
1088 // the native stack header stays iOS-only.
1089 headerShown: Platform.OS !== "android",
1090 title: "Terminal",
1091 unstable_headerSubtitle:
1092 usesNativeHeaderGlass && headerSubtitle.length > 0 ? headerSubtitle : undefined,
1093 }}
1094 />
1095
1096 {Platform.OS === "android" ? (
1097 <AndroidScreenHeader
1098 title="Terminal"
1099 subtitle={headerSubtitle}
1100 onBack={navigation.canGoBack() ? () => navigation.goBack() : undefined}
1101 trailing={
1102 <>
1103 {layout.usesSplitView ? (
1104 <AndroidHeaderIconButton
1105 accessibilityLabel={
1106 panes.primarySidebarVisible ? "Maximize terminal" : "Show threads"
1107 }
1108 icon={
1109 panes.primarySidebarVisible
1110 ? "arrow.up.left.and.arrow.down.right"
1111 : "sidebar.left"
1112 }
1113 onPress={togglePrimarySidebar}
1114 />
1115 ) : null}
1116 {isEnvironmentReady ? (
1117 <ControlPillMenu
1118 actions={androidTerminalMenuActions}
1119 isAnchoredToRight
1120 title={getTerminalStatusLabel({
1121 status: terminal.status,
1122 hasRunningSubprocess: terminal.hasRunningSubprocess,
1123 })}
1124 onPressAction={handleAndroidTerminalMenuAction}
1125 >
1126 <AndroidHeaderIconButton accessibilityLabel="Terminal options" icon="terminal" />
1127 </ControlPillMenu>
1128 ) : null}
1129 </>
1130 }
1131 />
1132 ) : null}
1133
1134 {layout.usesSplitView ? (
1135 <NativeHeaderToolbar placement="left">
1136 <NativeHeaderToolbar.Button
1137 accessibilityLabel={panes.primarySidebarVisible ? "Maximize terminal" : "Show threads"}
1138 icon={
1139 panes.primarySidebarVisible ? "arrow.up.left.and.arrow.down.right" : "sidebar.left"
1140 }
1141 onPress={togglePrimarySidebar}
1142 separateBackground
1143 />
1144 </NativeHeaderToolbar>
1145 ) : null}
1146
1147 {isEnvironmentReady ? (
1148 <NativeHeaderToolbar placement="right">
1149 <NativeHeaderToolbar.Menu icon="terminal" title="Terminal options" separateBackground>
1150 <NativeHeaderToolbar.Label>
1151 {getTerminalStatusLabel({
1152 status: terminal.status,
1153 hasRunningSubprocess: terminal.hasRunningSubprocess,
1154 })}
1155 </NativeHeaderToolbar.Label>
1156 <NativeHeaderToolbar.Menu icon="textformat.size" inline title="Text size">
1157 <NativeHeaderToolbar.Label>Text size</NativeHeaderToolbar.Label>
1158 <NativeHeaderToolbar.MenuAction
1159 disabled={fontSize <= MIN_TERMINAL_FONT_SIZE}
1160 discoverabilityLabel="Decrease terminal text size"
1161 onPress={handleDecreaseFontSize}
1162 >
1163 <NativeHeaderToolbar.Label>{`A- ${Math.max(MIN_TERMINAL_FONT_SIZE, fontSize - TERMINAL_FONT_SIZE_STEP).toFixed(1)} pt`}</NativeHeaderToolbar.Label>
1164 </NativeHeaderToolbar.MenuAction>
1165 <NativeHeaderToolbar.MenuAction
1166 disabled={fontSize >= MAX_TERMINAL_FONT_SIZE}
1167 discoverabilityLabel="Increase terminal text size"
1168 onPress={handleIncreaseFontSize}
1169 >
1170 <NativeHeaderToolbar.Label>{`A+ ${Math.min(MAX_TERMINAL_FONT_SIZE, fontSize + TERMINAL_FONT_SIZE_STEP).toFixed(1)} pt`}</NativeHeaderToolbar.Label>
1171 </NativeHeaderToolbar.MenuAction>
1172 </NativeHeaderToolbar.Menu>
1173 {terminalMenuSessions.map((session) => (
1174 <NativeHeaderToolbar.MenuAction
1175 key={session.terminalId}
1176 icon={session.terminalId === terminalId ? "checkmark" : "terminal"}
1177 onPress={() => handleSelectTerminal(session.terminalId)}
1178 subtitle={[
1179 getTerminalStatusLabel({ status: session.status }),
1180 basename(session.cwd),
1181 ]
1182 .filter(Boolean)
1183 .join(" · ")}
1184 >
1185 <NativeHeaderToolbar.Label>{session.displayLabel}</NativeHeaderToolbar.Label>
1186 </NativeHeaderToolbar.MenuAction>
1187 ))}
1188 <NativeHeaderToolbar.MenuAction
1189 icon="plus"
1190 onPress={handleOpenNewTerminal}
1191 subtitle={`Start another shell in ${basename(selectedThreadProject.workspaceRoot) ?? "this workspace"}`}
1192 >
1193 <NativeHeaderToolbar.Label>Open new terminal</NativeHeaderToolbar.Label>
1194 </NativeHeaderToolbar.MenuAction>
1195 </NativeHeaderToolbar.Menu>
1196 </NativeHeaderToolbar>
1197 ) : null}
1198
1199 <View className="flex-1" style={{ backgroundColor: terminalTheme.background }}>
1200 {!isEnvironmentReady ? (
1201 <EnvironmentConnectionNotice
1202 environmentLabel={
1203 environment.presentation?.entry.target.label ??
1204 selectedEnvironmentConnection?.environmentLabel ??
1205 "Environment"
1206 }
1207 connection={
1208 environment.presentation?.connection ?? {
1209 phase: "available",
1210 error: null,
1211 traceId: null,
1212 }
1213 }
1214 resourceName="terminal"
1215 onRetry={handleRetryEnvironment}
1216 />
1217 ) : (
1218 <>
1219 <View className="flex-1" style={{ paddingBottom: terminalBottomInset }}>
1220 <TerminalSurface
1221 autoFocus={!SHOWCASE_ENABLED}
1222 buffer={terminalSurfaceBuffer}
1223 fontSize={fontSize}
1224 isRunning={isRunning}
1225 keyboardFocusRequest={keyboardFocusRequest}
1226 onInput={handleInput}
1227 onResize={handleResize}
1228 style={{ flex: 1 }}
1229 terminalKey={terminalKey}
1230 theme={terminalTheme}
1231 />
1232 </View>
1233
1234 {isAccessoryVisible ? (
1235 <KeyboardStickyView
1236 style={{ position: "absolute", bottom: 0, left: 0, right: 0 }}
1237 offset={{ closed: 0, opened: 0 }}
1238 >
1239 <View
1240 className="border-t"
1241 style={{
1242 backgroundColor: terminalTheme.background,
1243 borderTopColor: terminalTheme.border,
1244 minHeight: TERMINAL_ACCESSORY_HEIGHT,
1245 }}
1246 >
1247 <ComposerToolbarRow paddingBottom={4} paddingHorizontal={8} paddingTop={4}>
1248 <ComposerToolbarScroller
1249 contentPaddingRight={2}
1250 fadeOpaque={terminalTheme.background}
1251 fadeTransparent={`${terminalTheme.background}00`}
1252 >
1253 {terminalToolbarActions.map((action) => {
1254 const active =
1255 action.kind === "modifier" && pendingModifier === action.modifier;
1256
1257 return (
1258 <ComposerToolbarButton
1259 key={action.key}
1260 active={active}
1261 label={action.label}
1262 maxWidth={120}
1263 minWidth={action.label.length > 1 ? 56 : 44}
1264 onPress={() => handleToolbarActionPress(action)}
1265 showChevron={false}
1266 textTransform={
1267 action.kind === "modifier" || action.kind === "clear"
1268 ? "uppercase"
1269 : "none"
1270 }
1271 />
1272 );
1273 })}
1274 </ComposerToolbarScroller>
1275 <ComposerToolbarButton
1276 accessibilityLabel="Dismiss keyboard"
1277 icon={{ ios: "keyboard.chevron.compact.down", android: "keyboard_hide" }}
1278 onPress={handleDismissKeyboard}
1279 showChevron={false}
1280 />
1281 </ComposerToolbarRow>
1282 </View>
1283 </KeyboardStickyView>
1284 ) : !keyboardState.isVisible ? (
1285 <Pressable
1286 accessibilityLabel="Show keyboard"
1287 accessibilityRole="button"
1288 onPress={handleShowKeyboard}
1289 style={({ pressed }) => ({
1290 bottom: 16,
1291 borderRadius: 28,
1292 opacity: pressed ? 0.72 : 1,
1293 position: "absolute",
1294 right: 16,
1295 })}
1296 >
1297 <GlassSurface
1298 chrome="none"
1299 glassEffectStyle="regular"
1300 tintColor="transparent"
1301 style={{
1302 alignItems: "center",
1303 borderRadius: 24,
1304 height: 48,
1305 justifyContent: "center",
1306 width: 48,
1307 }}
1308 pointerEvents="none"
1309 >
1310 <SymbolView
1311 name={{ ios: "keyboard", android: "keyboard" }}
1312 size={20}
1313 tintColor={terminalTheme.foreground}
1314 type="monochrome"
1315 />
1316 </GlassSurface>
1317 </Pressable>
1318 ) : null}
1319 </>
1320 )}
1321 </View>
1322 </>
1323 );
1324}