Open History to see the last commit
1import type { ThreadMoveDestination } from "../threads/threadOrder";
2import { createThreadMovePlanner } from "../threads/threadOrder";
3import {
4 LegendList,
5 type LegendListRef,
6 type LegendListRenderItemProps,
7} from "@legendapp/list/react-native";
8import {
9 type EnvironmentProject,
10 type EnvironmentThreadShell,
11} from "@t3tools/client-runtime/state/shell";
12import {
13 threadSearchMatchKey,
14 type EnvironmentThreadSearchMatch,
15} from "@t3tools/client-runtime/state/thread-search";
16import {
17 type EnvironmentId,
18 resolveEnvironmentMachineKind,
19 type SidebarProjectGroupingMode,
20 type SidebarThreadSortOrder,
21} from "@t3tools/contracts";
22import { useAtomSet, useAtomValue } from "@effect/atom-react";
23import { AsyncResult } from "effect/unstable/reactivity";
24import { useFocusEffect } from "@react-navigation/native";
25import { useCallback, useEffect, useMemo, useRef, useState } from "react";
26import { ActivityIndicator, FlatList, Platform, View } from "react-native";
27import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
28import { useSafeAreaInsets } from "react-native-safe-area-context";
29
30import { cn } from "../../lib/cn";
31import { EmptyState } from "../../components/EmptyState";
32import { MaterialFloatingActionButton } from "../../components/MaterialFloatingActionButton";
33import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspaceModel";
34import type { SavedRemoteConnection } from "../../lib/connection";
35import { scopedProjectKey } from "../../lib/scopedEntities";
36import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
37import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
38import { useThreadSearch } from "../../state/queries";
39import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
40import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
41import { usePendingThreadOrder } from "../../state/thread-order";
42import { environmentServerConfigsAtom } from "../../state/server";
43import type { PendingNewTask } from "../../state/use-pending-new-tasks";
44import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
45import {
46 PendingTaskListRow,
47 ThreadListGroupHeader,
48 ThreadListRow,
49 ThreadListShowMoreRow,
50} from "../threads/thread-list-items";
51import {
52 ThreadListV2PendingRow,
53 ThreadListV2Row,
54 ThreadListV2SettledShelfHeader,
55 ThreadListV2ShowMoreRow,
56 ThreadListV2SnoozedShelfHeader,
57} from "../threads/thread-list-v2-items";
58import { resolveThreadProviderInstance } from "../threads/thread-provider-instance";
59import {
60 buildThreadListV2Items,
61 getThreadListV2OrderedSection,
62 buildThreadListV2ListItems,
63 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
64 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
65 type ThreadListV2ListItem,
66} from "../threads/threadListV2";
67import { useThreadListV2ShelfPreferences } from "../threads/use-thread-list-v2-shelf-preferences";
68import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu";
69import {
70 buildHomeListLayout,
71 DEFAULT_GROUP_DISPLAY_STATE,
72 EMPTY_HOME_LIST_LAYOUT,
73 homeListItemsAreEqual,
74 nextGroupDisplayState,
75 type HomeGroupDisplayAction,
76 type HomeGroupDisplayState,
77 type HomeListItem,
78} from "./homeListItems";
79import {
80 buildHomeProjectScopes,
81 buildHomeThreadGroups,
82 sortHomeProjectScopes,
83 type HomeProjectSortOrder,
84} from "./homeThreadList";
85import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "./thread-swipe-actions";
86import { useMaterialFabScroll } from "./MaterialFabScrollContext";
87
88/* ─── Types ──────────────────────────────────────────────────────────── */
89
90interface HomeScreenProps {
91 readonly projects: ReadonlyArray<EnvironmentProject>;
92 readonly threads: ReadonlyArray<EnvironmentThreadShell>;
93 readonly pendingTasks: ReadonlyArray<PendingNewTask>;
94 readonly catalogState: WorkspaceState;
95 readonly savedConnectionsById: Readonly<Record<string, SavedRemoteConnection>>;
96 readonly environments: ReadonlyArray<
97 HomeListFilterMenuEnvironment & Pick<WorkspaceEnvironment, "connectionState">
98 >;
99 readonly searchQuery: string;
100 readonly selectedEnvironmentId: EnvironmentId | null;
101 readonly selectedProjectKey: string | null;
102 readonly projectSortOrder: HomeProjectSortOrder;
103 readonly threadSortOrder: SidebarThreadSortOrder;
104 readonly projectGroupingMode: SidebarProjectGroupingMode;
105 readonly onSearchQueryChange: (query: string) => void;
106 readonly onEnvironmentChange: (environmentId: EnvironmentId | null) => void;
107 readonly onProjectChange: (projectKey: string | null) => void;
108 readonly onProjectSortOrderChange: (sortOrder: HomeProjectSortOrder) => void;
109 readonly onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void;
110 readonly onAddConnection: () => void;
111 readonly onOpenSettings: () => void;
112 readonly onStartNewTask: () => void;
113 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
114 readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
115 readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
116 /** Resolves true iff the settle was dispatched and succeeded. */
117 readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
118 readonly onSnoozeThread: (
119 thread: EnvironmentThreadShell,
120 snoozedUntil: string,
121 ) => Promise<boolean>;
122 readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
123 readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
124 readonly onPinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
125 readonly onUnpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
126 readonly onMoveThread: (
127 thread: EnvironmentThreadShell,
128 direction: ThreadMoveDestination,
129 ) => Promise<boolean>;
130 readonly onRenameThread: (thread: EnvironmentThreadShell) => void;
131 readonly onRegenerateThreadTitle: (thread: EnvironmentThreadShell) => Promise<boolean>;
132 readonly onSelectPendingTask: (pendingTask: PendingNewTask) => void;
133 readonly onDeletePendingTask: (pendingTask: PendingNewTask) => void;
134 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
135 readonly onNewThreadInProject: (project: EnvironmentProject) => void;
136}
137
138/* ─── Layout constants ───────────────────────────────────────────────── */
139
140const ESTIMATED_THREAD_ROW_HEIGHT = 72;
141const PRE_LIQUID_GLASS_BOTTOM_TOOLBAR_HEIGHT = 44;
142/**
143 * Top spacing between the list and the Android custom header. The Android
144 * header is rendered in-flow above this screen and
145 * already consumes the top safe-area inset, so the list only needs breathing
146 * room here.
147 */
148
149function deriveEmptyState(props: {
150 readonly catalogState: WorkspaceState;
151 readonly projectCount: number;
152}): { readonly title: string; readonly detail: string; readonly loading: boolean } {
153 const { catalogState } = props;
154 if (catalogState.isLoadingConnections) {
155 return {
156 title: "Loading environments",
157 detail: "Checking saved environments on this device.",
158 loading: true,
159 };
160 }
161
162 if (!catalogState.hasConnections) {
163 return {
164 title: "No environments connected",
165 detail: "Add an environment to load projects and start coding sessions.",
166 loading: false,
167 };
168 }
169
170 if (
171 (catalogState.connectionState === "available" ||
172 catalogState.connectionState === "offline" ||
173 catalogState.connectionState === "error" ||
174 catalogState.connectionState === "unsupported") &&
175 !catalogState.hasLoadedShellSnapshot
176 ) {
177 return {
178 title:
179 catalogState.connectionState === "unsupported"
180 ? "Client not supported"
181 : "Environment unavailable",
182 detail:
183 catalogState.connectionError ??
184 "The saved environment is offline. Check the URL or start the environment, then retry.",
185 loading: false,
186 };
187 }
188
189 if (
190 catalogState.hasConnectingEnvironment &&
191 !catalogState.hasLoadedShellSnapshot &&
192 catalogState.connectionError === null
193 ) {
194 return {
195 title: "Connecting to environment",
196 detail: "Loading projects and threads from the saved environment.",
197 loading: true,
198 };
199 }
200
201 if (props.projectCount === 0 && catalogState.hasLoadedShellSnapshot) {
202 return {
203 title: "No projects found",
204 detail: "The connected environment did not report any projects.",
205 loading: false,
206 };
207 }
208
209 return {
210 title: "No threads yet",
211 detail: "Create a task to start a new coding session in one of your connected projects.",
212 loading: false,
213 };
214}
215
216function HomeTopContentSpacer() {
217 return <View className="h-4" />;
218}
219
220/* ─── Main screen ────────────────────────────────────────────────────── */
221
222export function HomeScreen(props: HomeScreenProps) {
223 const [groupDisplayStates, setGroupDisplayStates] = useState<
224 ReadonlyMap<string, HomeGroupDisplayState>
225 >(() => new Map());
226 const preferencesResult = useAtomValue(mobilePreferencesAtom);
227 const threadListV2Enabled = useThreadListV2Enabled();
228 const queuedThreadKeys = useQueuedThreadKeys();
229 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
230 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
231 const listRef = useRef<LegendListRef | null>(null);
232 const insets = useSafeAreaInsets();
233 const iosBottomToolbarClearance =
234 Platform.OS === "ios" && !NATIVE_LIQUID_GLASS_SUPPORTED
235 ? PRE_LIQUID_GLASS_BOTTOM_TOOLBAR_HEIGHT
236 : 0;
237 const searchEnvironmentIds = useMemo(
238 () =>
239 props.selectedEnvironmentId === null
240 ? props.environments
241 .filter((environment) => environment.connectionState === "connected")
242 .map((environment) => environment.environmentId)
243 : props.environments.some(
244 (environment) =>
245 environment.environmentId === props.selectedEnvironmentId &&
246 environment.connectionState === "connected",
247 )
248 ? [props.selectedEnvironmentId]
249 : [],
250 [props.environments, props.selectedEnvironmentId],
251 );
252 const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
253 const threadSearchMatchByKey = useMemo(() => {
254 const matches = new Map<string, EnvironmentThreadSearchMatch>();
255 for (const match of threadSearch.matches) {
256 if (match.source === "user" || match.source === "assistant") {
257 matches.set(threadSearchMatchKey(match), match);
258 }
259 }
260 return matches;
261 }, [threadSearch.matches]);
262 const matchedThreadKeys = useMemo(
263 () => new Set(threadSearch.matches.map(threadSearchMatchKey)),
264 [threadSearch.matches],
265 );
266 const effectiveGroupDisplayStates = useMemo(() => {
267 const next = new Map(groupDisplayStates);
268 if (!AsyncResult.isSuccess(preferencesResult)) {
269 return next;
270 }
271 for (const key of preferencesResult.value.collapsedProjectGroups ?? []) {
272 const existing = next.get(key);
273 next.set(key, {
274 ...(existing ?? DEFAULT_GROUP_DISPLAY_STATE),
275 collapsed: true,
276 });
277 }
278 return next;
279 }, [groupDisplayStates, preferencesResult]);
280 const effectiveGroupDisplayStatesRef = useRef(effectiveGroupDisplayStates);
281 effectiveGroupDisplayStatesRef.current = effectiveGroupDisplayStates;
282
283 const updateGroupDisplay = useCallback(
284 (key: string, action: HomeGroupDisplayAction) => {
285 const next = new Map(effectiveGroupDisplayStatesRef.current);
286 next.set(key, nextGroupDisplayState(next.get(key) ?? DEFAULT_GROUP_DISPLAY_STATE, action));
287 effectiveGroupDisplayStatesRef.current = next;
288 setGroupDisplayStates(next);
289 if (action === "toggle-collapsed") {
290 const collapsedProjectGroups: string[] = [];
291 for (const [groupKey, state] of next) {
292 if (state.collapsed) {
293 collapsedProjectGroups.push(groupKey);
294 }
295 }
296 savePreferences({ collapsedProjectGroups });
297 }
298 },
299 [savePreferences],
300 );
301
302 const handleSwipeableWillOpen = useCallback((methods: SwipeableMethods) => {
303 if (openSwipeableRef.current !== methods) {
304 openSwipeableRef.current?.close();
305 openSwipeableRef.current = methods;
306 }
307 }, []);
308
309 const handleSwipeableClose = useCallback((methods: SwipeableMethods) => {
310 if (openSwipeableRef.current === methods) {
311 openSwipeableRef.current = null;
312 }
313 }, []);
314
315 const handleScrollBeginDrag = useCallback(() => {
316 openSwipeableRef.current?.close();
317 }, []);
318 const onMaterialFabScroll = useMaterialFabScroll();
319 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
320 onScroll: onMaterialFabScroll,
321 onScrollBeginDrag: handleScrollBeginDrag,
322 });
323
324 const projectScopes = useMemo(
325 () =>
326 buildHomeProjectScopes({
327 projects: props.projects,
328 environmentId: props.selectedEnvironmentId,
329 projectGroupingMode: props.projectGroupingMode,
330 }),
331 [props.projectGroupingMode, props.projects, props.selectedEnvironmentId],
332 );
333 const selectedProjectScope = useMemo(
334 () =>
335 props.selectedProjectKey === null
336 ? null
337 : (projectScopes.find(
338 (scope) =>
339 scope.key === props.selectedProjectKey ||
340 scope.projectRefs.some(
341 (projectRef) =>
342 scopedProjectKey(projectRef.environmentId, projectRef.projectId) ===
343 props.selectedProjectKey,
344 ),
345 ) ?? null),
346 [projectScopes, props.selectedProjectKey],
347 );
348 const selectedProjectRefKeys = useMemo(
349 () =>
350 selectedProjectScope === null
351 ? null
352 : new Set(
353 selectedProjectScope.projectRefs.map((projectRef) =>
354 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
355 ),
356 ),
357 [selectedProjectScope],
358 );
359 const scopedProjects = useMemo(
360 () =>
361 threadListV2Enabled
362 ? []
363 : selectedProjectRefKeys === null
364 ? props.projects
365 : props.projects.filter((project) =>
366 selectedProjectRefKeys.has(scopedProjectKey(project.environmentId, project.id)),
367 ),
368 [threadListV2Enabled, props.projects, selectedProjectRefKeys],
369 );
370 const scopedThreads = useMemo(
371 () =>
372 threadListV2Enabled
373 ? []
374 : selectedProjectRefKeys === null
375 ? props.threads
376 : props.threads.filter((thread) =>
377 selectedProjectRefKeys.has(scopedProjectKey(thread.environmentId, thread.projectId)),
378 ),
379 [threadListV2Enabled, props.threads, selectedProjectRefKeys],
380 );
381 const scopedPendingTasks = useMemo(
382 () =>
383 threadListV2Enabled
384 ? []
385 : selectedProjectRefKeys === null
386 ? props.pendingTasks
387 : props.pendingTasks.filter((pendingTask) =>
388 selectedProjectRefKeys.has(
389 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
390 ),
391 ),
392 [threadListV2Enabled, props.pendingTasks, selectedProjectRefKeys],
393 );
394
395 const projectGroups = useMemo(
396 () =>
397 threadListV2Enabled
398 ? []
399 : buildHomeThreadGroups({
400 projects: scopedProjects,
401 threads: scopedThreads,
402 pendingTasks: scopedPendingTasks,
403 queuedThreadKeys,
404 environmentId: props.selectedEnvironmentId,
405 searchQuery: props.searchQuery,
406 matchedThreadKeys,
407 projectSortOrder: props.projectSortOrder,
408 threadSortOrder: props.threadSortOrder,
409 projectGroupingMode: props.projectGroupingMode,
410 }),
411 [
412 threadListV2Enabled,
413 queuedThreadKeys,
414 props.projectGroupingMode,
415 props.projectSortOrder,
416 props.searchQuery,
417 props.selectedEnvironmentId,
418 props.threadSortOrder,
419 matchedThreadKeys,
420 scopedPendingTasks,
421 scopedProjects,
422 scopedThreads,
423 ],
424 );
425
426 const hasSearchQuery = props.searchQuery.trim().length > 0;
427 const listLayout = useMemo(
428 () =>
429 threadListV2Enabled
430 ? EMPTY_HOME_LIST_LAYOUT
431 : buildHomeListLayout({
432 groups: projectGroups,
433 displayStates: effectiveGroupDisplayStates,
434 showAllThreads: hasSearchQuery,
435 }),
436 [threadListV2Enabled, projectGroups, effectiveGroupDisplayStates, hasSearchQuery],
437 );
438
439 const projectByKey = useMemo(() => {
440 const map = new Map<string, EnvironmentProject>();
441 for (const project of props.projects) {
442 map.set(scopedProjectKey(project.environmentId, project.id), project);
443 }
444 return map;
445 }, [props.projects]);
446
447 const v2ProjectScopeKey = props.selectedProjectKey;
448 const v2ScopeProjects = useMemo(
449 () =>
450 sortHomeProjectScopes({
451 scopes: projectScopes,
452 threads: props.threads,
453 pendingTasks: props.pendingTasks,
454 projectSortOrder: props.projectSortOrder,
455 }),
456 [
457 props.pendingTasks,
458 props.projects,
459 props.projectSortOrder,
460 props.selectedEnvironmentId,
461 props.threads,
462 projectScopes,
463 ],
464 );
465 const v2ScopedProjectGroup = useMemo(
466 () =>
467 v2ProjectScopeKey === null
468 ? null
469 : (v2ScopeProjects.find(
470 (scope) =>
471 scope.key === v2ProjectScopeKey ||
472 scope.projectRefs.some(
473 (projectRef) =>
474 scopedProjectKey(projectRef.environmentId, projectRef.projectId) ===
475 v2ProjectScopeKey,
476 ),
477 ) ?? null),
478 [v2ProjectScopeKey, v2ScopeProjects],
479 );
480 const v2ProjectTitleByProjectKey = useMemo(
481 () =>
482 new Map(
483 v2ScopeProjects.flatMap((scope) =>
484 scope.projectRefs.map(
485 (projectRef) =>
486 [
487 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
488 scope.title,
489 ] as const,
490 ),
491 ),
492 ),
493 [v2ScopeProjects],
494 );
495 const v2ScopedProjectKeys = useMemo(
496 () =>
497 v2ScopedProjectGroup === null
498 ? null
499 : new Set(
500 v2ScopedProjectGroup.projectRefs.map((projectRef) =>
501 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
502 ),
503 ),
504 [v2ScopedProjectGroup],
505 );
506 // Thread List v2 (beta): one flat list in creation order, no grouping.
507 // Settled threads collapse into a recency tail below the card block.
508 // Settled threads stay in the live shell stream (settled ≠ archived), so
509 // the partition works directly off live shells — no snapshot merging or
510 // optimistic holds.
511 const handleSettleThread = props.onSettleThread;
512 const handleSnoozeThread = useCallback(
513 (thread: EnvironmentThreadShell, snoozedUntil: string) => {
514 void props.onSnoozeThread(thread, snoozedUntil);
515 },
516 [props.onSnoozeThread],
517 );
518 const handleUnsnoozeThread = useCallback(
519 (thread: EnvironmentThreadShell) => {
520 void props.onUnsnoozeThread(thread);
521 },
522 [props.onUnsnoozeThread],
523 );
524 const handlePinThread = useCallback(
525 (thread: EnvironmentThreadShell) => {
526 void props.onPinThread(thread);
527 },
528 [props.onPinThread],
529 );
530 const handleMoveThread = useCallback(
531 (thread: EnvironmentThreadShell, direction: ThreadMoveDestination) => {
532 void props.onMoveThread(thread, direction);
533 },
534 [props.onMoveThread],
535 );
536 const handleUnpinThread = useCallback(
537 (thread: EnvironmentThreadShell) => {
538 void props.onUnpinThread(thread);
539 },
540 [props.onUnpinThread],
541 );
542 const handleRegenerateThreadTitle = useCallback(
543 (thread: EnvironmentThreadShell) => {
544 void props.onRegenerateThreadTitle(thread);
545 },
546 [props.onRegenerateThreadTitle],
547 );
548 const handleRenameThread = useCallback(
549 (thread: EnvironmentThreadShell) => props.onRenameThread(thread),
550 [props.onRenameThread],
551 );
552 const handleDeleteThread = props.onDeleteThread;
553 const handleUnsettleThread = props.onUnsettleThread;
554 // The settled tail renders in pages; expansion resets when the filter
555 // context changes so environment/search flips never inherit a deep page.
556 const [settledVisibleCount, setSettledVisibleCount] = useState(
557 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
558 );
559 const settledResetKey = `${props.selectedEnvironmentId ?? "all"}:${v2ProjectScopeKey ?? "all"}:${props.searchQuery.trim()}`;
560 const lastSettledResetKeyRef = useRef(settledResetKey);
561 if (lastSettledResetKeyRef.current !== settledResetKey) {
562 lastSettledResetKeyRef.current = settledResetKey;
563 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
564 }
565 const showMoreSettled = useCallback(
566 () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT),
567 [],
568 );
569 const {
570 loaded: shelfPreferencesLoaded,
571 settledShelfExpanded,
572 snoozedShelfExpanded,
573 toggleSettledShelf,
574 toggleSnoozedShelf,
575 } = useThreadListV2ShelfPreferences();
576 // The queued-start and snooze helpers need a clock while the list stays open.
577 const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
578 // Snooze wake times are second-precise; a counter bumped exactly at the
579 // next wake boundary re-runs the partition with a fresh clock so a woken
580 // thread reappears immediately instead of on the next minute tick.
581 const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
582 useFocusEffect(
583 useCallback(() => {
584 if (!threadListV2Enabled) return;
585 // Refresh immediately on enable or focus because the previous value can be hours old.
586 setNowMinute(new Date().toISOString().slice(0, 16));
587 const id = setInterval(() => setNowMinute(new Date().toISOString().slice(0, 16)), 60_000);
588 return () => clearInterval(id);
589 }, [threadListV2Enabled]),
590 );
591 // Threads on servers without the settlement capability never classify as
592 // settled (the user could neither un-settle nor pin them).
593 const serverConfigs = useAtomValue(environmentServerConfigsAtom);
594 const settlementEnvironmentIds = useMemo(() => {
595 const supported = new Set<EnvironmentId>();
596 for (const [environmentId, config] of serverConfigs) {
597 if (config.environment.capabilities.threadSettlement === true) {
598 supported.add(environmentId);
599 }
600 }
601 return supported;
602 }, [serverConfigs]);
603 const snoozeEnvironmentIds = useMemo(() => {
604 const supported = new Set<EnvironmentId>();
605 for (const [environmentId, config] of serverConfigs) {
606 if (config.environment.capabilities.threadSnooze === true) {
607 supported.add(environmentId);
608 }
609 }
610 return supported;
611 }, [serverConfigs]);
612 const pinningEnvironmentIds = useMemo(() => {
613 const supported = new Set<EnvironmentId>();
614 for (const [environmentId, config] of serverConfigs) {
615 if (config.environment.capabilities.threadPinning === true) {
616 supported.add(environmentId);
617 }
618 }
619 return supported;
620 }, [serverConfigs]);
621 const pinReorderEnvironmentIds = useMemo(() => {
622 const supported = new Set<EnvironmentId>();
623 for (const [environmentId, config] of serverConfigs) {
624 if (config.environment.capabilities.threadPinReorder === true) {
625 supported.add(environmentId);
626 }
627 }
628 return supported;
629 }, [serverConfigs]);
630 const activeReorderEnvironmentIds = useMemo(() => {
631 const supported = new Set<EnvironmentId>();
632 for (const [environmentId, config] of serverConfigs) {
633 if (config.environment.capabilities.threadActiveReorder === true) {
634 supported.add(environmentId);
635 }
636 }
637 return supported;
638 }, [serverConfigs]);
639 const titleRegenerationEnvironmentIds = useMemo(() => {
640 const supported = new Set<EnvironmentId>();
641 for (const [environmentId, config] of serverConfigs) {
642 if (config.environment.capabilities.threadTitleRegeneration === true) {
643 supported.add(environmentId);
644 }
645 }
646 return supported;
647 }, [serverConfigs]);
648 const machineByEnvironmentId = useMemo(
649 () =>
650 new Map(
651 [...serverConfigs].map(
652 ([environmentId, config]) =>
653 [environmentId, resolveEnvironmentMachineKind(config)] as const,
654 ),
655 ),
656 [serverConfigs],
657 );
658 const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
659 const threadMovePlanners = useMemo(() => {
660 const sectionPlanner = (section: "pinned" | "active") =>
661 createThreadMovePlanner({
662 allThreads: props.threads,
663 section,
664 reorderableEnvironmentIds: new Set(
665 [...serverConfigs].flatMap(([id, config]) =>
666 (section === "pinned"
667 ? config.environment.capabilities.threadPinReorder
668 : config.environment.capabilities.threadActiveReorder) === true
669 ? [id]
670 : [],
671 ),
672 ),
673 ordered: getThreadListV2OrderedSection({
674 threads: props.threads,
675 section,
676 pendingOrder,
677 now: new Date().toISOString(),
678 settlementEnvironmentIds,
679 snoozeEnvironmentIds,
680 queuedThreadKeys,
681 }),
682 });
683 return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
684 }, [
685 serverConfigs,
686 props.threads,
687 pendingOrder,
688 queuedThreadKeys,
689 settlementEnvironmentIds,
690 snoozeEnvironmentIds,
691 nowMinute,
692 snoozeWakeTick,
693 ]);
694 const threadListV2Layout = useMemo(() => {
695 if (!threadListV2Enabled)
696 return {
697 items: [],
698 hiddenSettledCount: 0,
699 snoozedCount: 0,
700 snoozedShelfHeaderIndex: null,
701 settledCount: 0,
702 settledShelfHeaderIndex: null,
703 nextSnoozeWakeAt: null,
704 };
705 // Settled threads are live shells; archived threads keep their original
706 // "hidden from lists" meaning.
707 return buildThreadListV2Items({
708 pendingOrder,
709 threads: props.threads.filter((thread) => thread.archivedAt === null),
710 environmentId: props.selectedEnvironmentId,
711 projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs,
712 searchQuery: props.searchQuery,
713 matchedThreadKeys,
714 settlementEnvironmentIds,
715 snoozeEnvironmentIds,
716 queuedThreadKeys,
717 settledLimit: settledVisibleCount,
718 now: new Date().toISOString(),
719 snoozedShelfExpanded,
720 settledShelfExpanded,
721 selectedThreadKey: null,
722 });
723 }, [
724 pendingOrder,
725 queuedThreadKeys,
726 nowMinute,
727 snoozeWakeTick,
728 snoozedShelfExpanded,
729 settledShelfExpanded,
730 settledVisibleCount,
731 settlementEnvironmentIds,
732 snoozeEnvironmentIds,
733 props.searchQuery,
734 props.selectedEnvironmentId,
735 props.threads,
736 matchedThreadKeys,
737 threadListV2Enabled,
738 v2ScopedProjectGroup,
739 ]);
740 // Re-partition the moment the earliest snooze expires (clamped to the
741 // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
742 const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
743 useEffect(() => {
744 if (nextSnoozeWakeAt === null) return;
745 const wakeAtMs = Date.parse(nextSnoozeWakeAt);
746 if (Number.isNaN(wakeAtMs)) return;
747 const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
748 const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);
749 return () => clearTimeout(id);
750 // snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is
751 // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
752 // range) the boundary string is identical and the chain would die.
753 }, [nextSnoozeWakeAt, snoozeWakeTick]);
754 // Queued tasks are not thread shells, so the v2 partition never sees them;
755 // they are spliced in below the active block and stay visible and deletable
756 // while their environment is offline. Same environment scope and search
757 // filter as the list itself.
758 const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
759 const v2PendingTasks = useMemo(
760 () =>
761 props.pendingTasks.filter(
762 (pendingTask) =>
763 (props.selectedEnvironmentId === null ||
764 pendingTask.environmentId === props.selectedEnvironmentId) &&
765 (v2ScopedProjectKeys === null ||
766 v2ScopedProjectKeys.has(
767 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
768 )) &&
769 (v2SearchQuery.length === 0 ||
770 pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
771 ),
772 [props.pendingTasks, props.selectedEnvironmentId, v2ScopedProjectKeys, v2SearchQuery],
773 );
774 const threadListV2Items = useMemo(
775 () =>
776 buildThreadListV2ListItems({
777 items: threadListV2Layout.items,
778 pendingTasks: v2PendingTasks,
779 snoozedCount: threadListV2Layout.snoozedCount,
780 snoozedShelfExpanded,
781 snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
782 settledCount: threadListV2Layout.settledCount,
783 settledShelfExpanded,
784 settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
785 snoozeLabelNow: `${nowMinute}:00.000Z`,
786 }),
787 [settledShelfExpanded, snoozedShelfExpanded, threadListV2Layout, v2PendingTasks],
788 );
789
790 useThreadJumpShortcuts(
791 threadListV2Enabled ? threadListV2Items : listLayout.items,
792 props.onSelectThread,
793 );
794
795 const renderV2Item = useCallback(
796 ({ item, index }: { readonly item: ThreadListV2ListItem; readonly index: number }) => {
797 const nextItem = threadListV2Items[index + 1];
798 const showTrailingDivider =
799 nextItem?.type === "v2-thread" ||
800 (nextItem?.type === "v2-pending" && !nextItem.showPendingDivider);
801 if (item.type === "v2-pending") {
802 const pendingScopeKey = scopedProjectKey(
803 item.pendingTask.environmentId,
804 item.pendingTask.projectId,
805 );
806 return (
807 <ThreadListV2PendingRow
808 pendingTask={item.pendingTask}
809 project={projectByKey.get(pendingScopeKey) ?? null}
810 projectTitle={v2ProjectTitleByProjectKey.get(pendingScopeKey)}
811 environmentLabel={
812 Object.keys(props.savedConnectionsById).length > 1
813 ? (props.savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ??
814 null)
815 : null
816 }
817 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
818 showPendingDivider={item.showPendingDivider}
819 showTrailingDivider={showTrailingDivider}
820 onSelectPendingTask={props.onSelectPendingTask}
821 onDeletePendingTask={props.onDeletePendingTask}
822 />
823 );
824 }
825 if (item.type === "v2-snoozed-shelf") {
826 return (
827 <ThreadListV2SnoozedShelfHeader
828 count={item.count}
829 disabled={!shelfPreferencesLoaded}
830 expanded={item.expanded}
831 onToggle={toggleSnoozedShelf}
832 />
833 );
834 }
835 if (item.type === "v2-settled-shelf") {
836 return (
837 <ThreadListV2SettledShelfHeader
838 count={item.count}
839 disabled={!shelfPreferencesLoaded}
840 expanded={item.expanded}
841 onToggle={toggleSettledShelf}
842 />
843 );
844 }
845 const thread = item.item.thread;
846 const movePlanner = item.item.pinned ? threadMovePlanners.pinned : threadMovePlanners.active;
847 const movedId = `${thread.environmentId}:${thread.id}`;
848 return (
849 <ThreadListV2Row
850 onNewThreadOnBranch={props.onNewThreadOnBranch}
851 thread={thread}
852 variant={item.item.variant}
853 hasQueuedMessages={queuedThreadKeys.has(movedId)}
854 snoozed={item.item.snoozed}
855 pinned={item.item.pinned}
856 snoozePresetMinute={nowMinute}
857 snoozeWakeLabelText={item.snoozeWakeLabelText}
858 showTrailingDivider={showTrailingDivider}
859 project={
860 projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId)) ?? null
861 }
862 projectTitle={v2ProjectTitleByProjectKey.get(
863 scopedProjectKey(thread.environmentId, thread.projectId),
864 )}
865 providerInstance={resolveThreadProviderInstance(serverConfigs, thread)}
866 environmentLabel={
867 Object.keys(props.savedConnectionsById).length > 1
868 ? (props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
869 : null
870 }
871 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
872 searchMatch={threadSearchMatchByKey.get(
873 threadSearchMatchKey({
874 environmentId: thread.environmentId,
875 threadId: thread.id,
876 }),
877 )}
878 searchQuery={props.searchQuery}
879 onSelectThread={props.onSelectThread}
880 onDeleteThread={handleDeleteThread}
881 onArchiveThread={props.onArchiveThread}
882 onRenameThread={handleRenameThread}
883 onRegenerateThreadTitle={handleRegenerateThreadTitle}
884 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
885 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
886 onSettleThread={handleSettleThread}
887 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
888 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
889 reorderSupported={
890 item.item.pinned
891 ? pinReorderEnvironmentIds.has(thread.environmentId)
892 : activeReorderEnvironmentIds.has(thread.environmentId)
893 }
894 canMoveUp={pendingOrder === null && movePlanner(movedId, "up") !== null}
895 canMoveDown={pendingOrder === null && movePlanner(movedId, "down") !== null}
896 onSnoozeThread={handleSnoozeThread}
897 onUnsnoozeThread={handleUnsnoozeThread}
898 onUnsettleThread={handleUnsettleThread}
899 onPinThread={handlePinThread}
900 onUnpinThread={handleUnpinThread}
901 onMoveThread={handleMoveThread}
902 onSwipeableClose={handleSwipeableClose}
903 onSwipeableWillOpen={handleSwipeableWillOpen}
904 />
905 );
906 },
907 [
908 handleDeleteThread,
909 activeReorderEnvironmentIds,
910 threadMovePlanners,
911 pendingOrder,
912 queuedThreadKeys,
913 handleMoveThread,
914 handlePinThread,
915 handleRegenerateThreadTitle,
916 handleRenameThread,
917 handleSettleThread,
918 handleSnoozeThread,
919 handleUnpinThread,
920 handleUnsnoozeThread,
921 handleSwipeableClose,
922 handleSwipeableWillOpen,
923 handleUnsettleThread,
924 pinningEnvironmentIds,
925 machineByEnvironmentId,
926 pinReorderEnvironmentIds,
927 projectByKey,
928 props.onArchiveThread,
929 props.onDeletePendingTask,
930 props.onSelectPendingTask,
931 props.onSelectThread,
932 props.onNewThreadOnBranch,
933 props.savedConnectionsById,
934 serverConfigs,
935 shelfPreferencesLoaded,
936 settlementEnvironmentIds,
937 snoozeEnvironmentIds,
938 threadListV2Items,
939 threadSearchMatchByKey,
940 titleRegenerationEnvironmentIds,
941 toggleSettledShelf,
942 toggleSnoozedShelf,
943 v2ProjectTitleByProjectKey,
944 props.searchQuery,
945 nowMinute,
946 ],
947 );
948 const v2KeyExtractor = useCallback((item: ThreadListV2ListItem) => item.key, []);
949
950 // FlatList treats a changed extraData identity as "re-render every visible
951 // row", so an inline object literal would invalidate all rows on every
952 // HomeScreen render.
953 const v2ExtraData = useMemo(
954 () => ({
955 projectByKey,
956 projectTitleByProjectKey: v2ProjectTitleByProjectKey,
957 serverConfigs,
958 savedConnectionsById: props.savedConnectionsById,
959 searchQuery: props.searchQuery,
960 snoozePresetMinute: nowMinute,
961 threadSearchMatchByKey,
962 }),
963 [
964 projectByKey,
965 props.searchQuery,
966 props.savedConnectionsById,
967 serverConfigs,
968 nowMinute,
969 threadSearchMatchByKey,
970 v2ProjectTitleByProjectKey,
971 ],
972 );
973
974 const extraData = useMemo(
975 () => ({
976 savedConnectionsById: props.savedConnectionsById,
977 searchQuery: props.searchQuery,
978 threadSearchMatchByKey,
979 }),
980 [props.savedConnectionsById, props.searchQuery, threadSearchMatchByKey],
981 );
982
983 const renderItem = useCallback(
984 ({ item }: LegendListRenderItemProps<HomeListItem>) => {
985 switch (item.type) {
986 case "header":
987 return (
988 <ThreadListGroupHeader
989 variant="compact"
990 collapsed={item.collapsed}
991 isFirst={item.isFirst}
992 groupKey={item.group.key}
993 onGroupAction={updateGroupDisplay}
994 // Aggregated groups (same repo across machines) have no single
995 // target project, and `pending-project:` groups hold a placeholder
996 // built from queued-task metadata rather than a real project shell,
997 // so the quick new-thread button is single-real-project only.
998 newThreadTarget={item.group.newThreadTarget}
999 onNewThread={props.onNewThreadInProject}
1000 project={item.group.representative}
1001 threadCount={item.group.threads.length + item.group.pendingTasks.length}
1002 title={item.group.title}
1003 />
1004 );
1005 case "pending-task":
1006 return (
1007 <PendingTaskListRow
1008 variant="compact"
1009 pendingTask={item.pendingTask}
1010 environmentLabel={
1011 props.savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null
1012 }
1013 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
1014 isLast={item.isLast}
1015 onSelectPendingTask={props.onSelectPendingTask}
1016 onDeletePendingTask={props.onDeletePendingTask}
1017 />
1018 );
1019 case "thread": {
1020 const thread = item.thread;
1021 return (
1022 <ThreadListRow
1023 onNewThreadOnBranch={props.onNewThreadOnBranch}
1024 variant="compact"
1025 thread={thread}
1026 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
1027 environmentLabel={
1028 props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
1029 }
1030 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
1031 isLast={item.isLast}
1032 searchMatch={threadSearchMatchByKey.get(
1033 threadSearchMatchKey({
1034 environmentId: thread.environmentId,
1035 threadId: thread.id,
1036 }),
1037 )}
1038 searchQuery={props.searchQuery}
1039 onArchiveThread={props.onArchiveThread}
1040 onDeleteThread={props.onDeleteThread}
1041 onRenameThread={handleRenameThread}
1042 onRegenerateThreadTitle={handleRegenerateThreadTitle}
1043 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
1044 onSelectThread={props.onSelectThread}
1045 onSwipeableClose={handleSwipeableClose}
1046 onSwipeableWillOpen={handleSwipeableWillOpen}
1047 />
1048 );
1049 }
1050 case "show-more":
1051 return (
1052 <ThreadListShowMoreRow
1053 variant="compact"
1054 hiddenCount={item.hiddenCount}
1055 canShowLess={item.canShowLess}
1056 groupKey={item.groupKey}
1057 onGroupAction={updateGroupDisplay}
1058 />
1059 );
1060 }
1061 },
1062 [
1063 handleSwipeableClose,
1064 handleSwipeableWillOpen,
1065 handleRegenerateThreadTitle,
1066 handleRenameThread,
1067 machineByEnvironmentId,
1068 queuedThreadKeys,
1069 props.onArchiveThread,
1070 props.onDeletePendingTask,
1071 props.onDeleteThread,
1072 props.onNewThreadInProject,
1073 props.onSelectPendingTask,
1074 props.onSelectThread,
1075 props.onNewThreadOnBranch,
1076 props.searchQuery,
1077 props.savedConnectionsById,
1078 threadSearchMatchByKey,
1079 titleRegenerationEnvironmentIds,
1080 updateGroupDisplay,
1081 ],
1082 );
1083
1084 const keyExtractor = useCallback((item: HomeListItem) => item.key, []);
1085
1086 /* Empty states */
1087 // The signal must ignore the search/environment filters: an active query
1088 // that matches nothing needs the in-list "No results" state, not the
1089 // full-page "No threads yet". Settled threads are unarchived live shells,
1090 // so the v1 check already covers v2.
1091 const hasAnyThreads =
1092 props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;
1093 const hasResults = threadListV2Enabled ? threadListV2Items.length > 0 : projectGroups.length > 0;
1094 const selectedEnvironmentLabel =
1095 props.selectedEnvironmentId === null
1096 ? null
1097 : (props.savedConnectionsById[props.selectedEnvironmentId]?.environmentLabel ??
1098 "this environment");
1099 // Connection state surfaces in the header title slot
1100 // (WorkspaceConnectionTitle) — nothing renders inside the list, so
1101 // reconnects never shift the rows.
1102 const emptyState = deriveEmptyState({
1103 catalogState: props.catalogState,
1104 projectCount: props.projects.length,
1105 });
1106
1107 if (!hasAnyThreads) {
1108 return (
1109 <View className={Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 bg-screen"}>
1110 <View
1111 className={cn(
1112 "flex-1 items-center justify-center bg-screen px-8",
1113 Platform.OS === "android" && "overflow-hidden rounded-t-[28px]",
1114 )}
1115 style={{
1116 paddingBottom: Math.max(insets.bottom, 24) + iosBottomToolbarClearance,
1117 paddingTop: NATIVE_LIQUID_GLASS_SUPPORTED ? insets.top + 72 : 0,
1118 }}
1119 >
1120 <View className="w-full max-w-[430px]">
1121 <EmptyState
1122 title={emptyState.title}
1123 detail={emptyState.detail}
1124 actionLabel={!props.catalogState.hasReadyEnvironment ? "Add environment" : undefined}
1125 onAction={!props.catalogState.hasReadyEnvironment ? props.onAddConnection : undefined}
1126 action={
1127 Platform.OS === "android" && !props.catalogState.hasReadyEnvironment ? (
1128 <MaterialFloatingActionButton
1129 label="Add environment"
1130 icon="plus"
1131 variant="extended"
1132 tone="primary"
1133 onPress={props.onAddConnection}
1134 />
1135 ) : undefined
1136 }
1137 variant="plain"
1138 />
1139 {emptyState.loading ? (
1140 <View className="mt-4 items-center">
1141 <ActivityIndicator colorClassName="accent-icon-muted" />
1142 </View>
1143 ) : null}
1144 </View>
1145 </View>
1146 </View>
1147 );
1148 }
1149
1150 const listHeader = Platform.OS === "ios" ? null : <HomeTopContentSpacer />;
1151
1152 // Project scoping lives in the header filter menu (no inline chip row on
1153 // mobile — the menu is the one filter surface).
1154 const v2ListHeader = listHeader;
1155
1156 const listEmpty = !hasResults ? (
1157 hasSearchQuery && threadSearch.isPending ? null : hasSearchQuery ? (
1158 <EmptyState
1159 title="No results"
1160 detail={`No threads matching "${props.searchQuery}".`}
1161 variant={Platform.OS === "android" ? "plain" : undefined}
1162 />
1163 ) : selectedProjectScope !== null ? (
1164 <EmptyState
1165 title={`No threads in ${selectedProjectScope.title}`}
1166 detail="Choose another project or create a new task."
1167 variant={Platform.OS === "android" ? "plain" : undefined}
1168 />
1169 ) : selectedEnvironmentLabel ? (
1170 <EmptyState
1171 title={`No threads in ${selectedEnvironmentLabel}`}
1172 detail="Choose another environment or create a new task."
1173 variant={Platform.OS === "android" ? "plain" : undefined}
1174 />
1175 ) : (
1176 <EmptyState
1177 title="No threads yet"
1178 detail="Create a task to start a new coding session."
1179 variant={Platform.OS === "android" ? "plain" : undefined}
1180 />
1181 )
1182 ) : null;
1183 // Use the v2 project scope for its empty state. Snoozed threads need no
1184 // special empty state: their shelf header is a list row even while collapsed.
1185 const v2ListEmpty =
1186 hasSearchQuery && threadSearch.isPending ? null : hasSearchQuery ? (
1187 <EmptyState
1188 title="No results"
1189 detail={`No threads matching "${props.searchQuery}".`}
1190 variant={Platform.OS === "android" ? "plain" : undefined}
1191 />
1192 ) : v2ScopedProjectGroup !== null ? (
1193 <EmptyState
1194 title={`No threads in ${v2ScopedProjectGroup.title}`}
1195 detail="Choose another project or create a new task."
1196 variant={Platform.OS === "android" ? "plain" : undefined}
1197 />
1198 ) : (
1199 listEmpty
1200 );
1201
1202 if (
1203 Platform.OS === "android" &&
1204 (threadListV2Enabled ? threadListV2Items.length === 0 : listLayout.items.length === 0)
1205 ) {
1206 return (
1207 <View className="flex-1 bg-header">
1208 <View
1209 className="flex-1 items-center justify-center overflow-hidden rounded-t-[28px] bg-screen px-4"
1210 style={{ paddingBottom: insets.bottom }}
1211 >
1212 {threadListV2Enabled ? v2ListEmpty : listEmpty}
1213 </View>
1214 </View>
1215 );
1216 }
1217
1218 if (threadListV2Enabled) {
1219 return (
1220 <View className={Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 bg-screen"}>
1221 <View
1222 className={
1223 Platform.OS === "android"
1224 ? "flex-1 overflow-hidden rounded-t-[28px] bg-screen"
1225 : "flex-1 bg-screen"
1226 }
1227 >
1228 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1229 <FlatList
1230 data={threadListV2Items}
1231 renderItem={renderV2Item}
1232 keyExtractor={v2KeyExtractor}
1233 extraData={v2ExtraData}
1234 ListHeaderComponent={v2ListHeader}
1235 ListFooterComponent={
1236 settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0 ? (
1237 <ThreadListV2ShowMoreRow
1238 hiddenCount={threadListV2Layout.hiddenSettledCount}
1239 onPress={showMoreSettled}
1240 />
1241 ) : null
1242 }
1243 ListEmptyComponent={v2ListEmpty}
1244 style={{ flex: 1 }}
1245 automaticallyAdjustsScrollIndicatorInsets={Platform.OS === "ios"}
1246 contentInsetAdjustmentBehavior={Platform.OS === "ios" ? "automatic" : "never"}
1247 showsVerticalScrollIndicator={false}
1248 keyboardDismissMode="on-drag"
1249 keyboardShouldPersistTaps="handled"
1250 {...scrollGateHandlers}
1251 scrollEventThrottle={16}
1252 contentContainerStyle={{
1253 paddingBottom:
1254 Platform.OS === "ios"
1255 ? Math.max(insets.bottom, 24) + 96 + iosBottomToolbarClearance
1256 : Math.max(insets.bottom, 16) + (Platform.OS === "android" ? 148 : 88),
1257 }}
1258 />
1259 </SwipeableScrollGateProvider>
1260 </View>
1261 </View>
1262 );
1263 }
1264
1265 return (
1266 <View className={Platform.OS === "android" ? "flex-1 bg-header" : "flex-1 bg-screen"}>
1267 <View
1268 className={
1269 Platform.OS === "android"
1270 ? "flex-1 overflow-hidden rounded-t-[28px] bg-screen"
1271 : "flex-1 bg-screen"
1272 }
1273 >
1274 {/* Sticky headers are deliberately not wired up: LegendList's JS sticky
1275 implementation mispositions pinned headers at mount under iOS
1276 automatic content insets (headers render one nav-inset too low until
1277 the first scroll event) and blanks non-pinned headers after
1278 collapse/expand data changes. The flattened layout still exposes
1279 `stickyHeaderIndices` if this gets revisited. */}
1280 <SwipeableScrollGateProvider enabled={swipeEnabled}>
1281 <LegendList
1282 ref={listRef}
1283 data={listLayout.items}
1284 renderItem={renderItem}
1285 keyExtractor={keyExtractor}
1286 itemsAreEqual={homeListItemsAreEqual}
1287 drawDistance={500}
1288 estimatedItemSize={ESTIMATED_THREAD_ROW_HEIGHT}
1289 extraData={extraData}
1290 ListHeaderComponent={listHeader}
1291 ListEmptyComponent={listEmpty}
1292 style={{ flex: 1 }}
1293 automaticallyAdjustsScrollIndicatorInsets={NATIVE_LIQUID_GLASS_SUPPORTED}
1294 contentInsetAdjustmentBehavior={NATIVE_LIQUID_GLASS_SUPPORTED ? "automatic" : "never"}
1295 showsVerticalScrollIndicator={false}
1296 keyboardDismissMode="on-drag"
1297 keyboardShouldPersistTaps="handled"
1298 {...scrollGateHandlers}
1299 recycleItems
1300 scrollEventThrottle={16}
1301 contentContainerStyle={{
1302 // Android reserves room for the floating new-task FAB
1303 // (56 button + 16 gap + bottom inset). Pre-glass iOS shows a
1304 // standard 44pt bottom toolbar that overlays the list and is not
1305 // reflected in insets while contentInsetAdjustmentBehavior is
1306 // "never".
1307 paddingBottom:
1308 Platform.OS === "ios"
1309 ? Math.max(insets.bottom, 24) + 24 + iosBottomToolbarClearance
1310 : Math.max(insets.bottom, 16) + (Platform.OS === "android" ? 148 : 88),
1311 }}
1312 scrollIndicatorInsets={
1313 Platform.OS === "ios"
1314 ? {
1315 bottom: Math.max(insets.bottom, 16) + 24 + iosBottomToolbarClearance,
1316 top: 0,
1317 }
1318 : undefined
1319 }
1320 />
1321 </SwipeableScrollGateProvider>
1322 </View>
1323 </View>
1324 );
1325}