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

HomeScreen.tsx

1,269 lines47.5 KB

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