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

HomeScreen.tsx

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