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