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

HomeScreen.tsx

1,288 lines48.2 KB

1import { resolveThreadProviderInstance } from "../threads/thread-provider-instance";
2import type { ThreadMoveDestination } from "../threads/threadOrder";
3import { createThreadMovePlanner } from "../threads/threadOrder";
4import {
5 LegendList,
6 type LegendListRef,
7 type LegendListRenderItemProps,
8} from "@legendapp/list/react-native";
9import {
10 type EnvironmentProject,
11 type EnvironmentThreadShell,
12} from "@t3tools/client-runtime/state/shell";
13import {
14 threadSearchMatchKey,
15 type EnvironmentThreadSearchMatch,
16} from "@t3tools/client-runtime/state/thread-search";
17import {
18 type EnvironmentId,
19 resolveEnvironmentMachineKind,
20 type SidebarProjectGroupingMode,
21 type SidebarThreadSortOrder,
22} from "@t3tools/contracts";
23import { useAtomSet, useAtomValue } from "@effect/atom-react";
24import { AsyncResult } from "effect/unstable/reactivity";
25import { useFocusEffect } from "@react-navigation/native";
26import { useCallback, useEffect, useMemo, useRef, useState } from "react";
27import { ActivityIndicator, FlatList, Platform, Pressable, View } from "react-native";
28import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
29import { useSafeAreaInsets } from "react-native-safe-area-context";
30​
31import { cn } from "../../lib/cn";
32import { AppText as Text } from "../../components/AppText";
33import { EmptyState } from "../../components/EmptyState";
34import type { WorkspaceEnvironment, WorkspaceState } from "../../state/workspaceModel";
35import type { SavedRemoteConnection } from "../../lib/connection";
36import { scopedProjectKey } from "../../lib/scopedEntities";
37import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
38import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences";
39import { useThreadSearch } from "../../state/queries";
40import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
41import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
42import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled";
43import { usePendingThreadOrder } from "../../state/thread-order";
44import { environmentServerConfigsAtom } from "../../state/server";
45import type { PendingNewTask } from "../../state/use-pending-new-tasks";
46import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
47import {
48 PendingTaskListRow,
49 ThreadListGroupHeader,
50 ThreadListRow,
51 ThreadListShowMoreRow,
52} from "../threads/thread-list-items";
53import {
54 ThreadListV2PendingRow,
55 ThreadListV2Row,
56 ThreadListV2SettledShelfHeader,
57 ThreadListV2SnoozedShelfHeader,
58} from "../threads/thread-list-v2-items";
59import {
60 buildThreadListV2Items,
61 getThreadListV2OrderedSection,
62 buildThreadListV2ListItems,
63 resolveThreadListV2ProviderDrivers,
64 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
65 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
66 type ThreadListV2ListItem,
67} from "../threads/threadListV2";
68import { useThreadListV2ShelfPreferences } from "../threads/use-thread-list-v2-shelf-preferences";
69import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu";
70import {
71 buildHomeListLayout,
72 DEFAULT_GROUP_DISPLAY_STATE,
73 EMPTY_HOME_LIST_LAYOUT,
74 homeListItemsAreEqual,
75 nextGroupDisplayState,
76 type HomeGroupDisplayAction,
77 type HomeGroupDisplayState,
78 type HomeListItem,
79} from "./homeListItems";
80import {
81 buildHomeProjectScopes,
82 buildHomeThreadGroups,
83 sortHomeProjectScopes,
84 type HomeProjectSortOrder,
85} from "./homeThreadList";
86import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "./thread-swipe-actions";
87​
88/* ─── Types ──────────────────────────────────────────────────────────── */
89​
90interface HomeScreenProps {
91 readonly projects: ReadonlyArray<EnvironmentProject>;
92 readonly threads: ReadonlyArray<EnvironmentThreadShell>;
93 readonly pendingTasks: ReadonlyArray<PendingNewTask>;
94 readonly catalogState: WorkspaceState;
95 readonly savedConnectionsById: Readonly<Record<string, SavedRemoteConnection>>;
96 readonly environments: ReadonlyArray<
97 HomeListFilterMenuEnvironment & Pick<WorkspaceEnvironment, "connectionState">
98 >;
99 readonly searchQuery: string;
100 readonly selectedEnvironmentId: EnvironmentId | null;
101 readonly selectedProjectKey: string | null;
102 readonly projectSortOrder: HomeProjectSortOrder;
103 readonly threadSortOrder: SidebarThreadSortOrder;
104 readonly projectGroupingMode: SidebarProjectGroupingMode;
105 readonly onSearchQueryChange: (query: string) => void;
106 readonly onEnvironmentChange: (environmentId: EnvironmentId | null) => void;
107 readonly onProjectChange: (projectKey: string | null) => void;
108 readonly onProjectSortOrderChange: (sortOrder: HomeProjectSortOrder) => void;
109 readonly onThreadSortOrderChange: (sortOrder: SidebarThreadSortOrder) => void;
110 readonly onAddConnection: () => void;
111 readonly onOpenSettings: () => void;
112 readonly onStartNewTask: () => void;
113 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
114 readonly onArchiveThread: (thread: EnvironmentThreadShell) => void;
115 readonly onDeleteThread: (thread: EnvironmentThreadShell) => void;
116 /** Resolves true iff the settle was dispatched and succeeded. */
117 readonly onSettleThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
118 readonly onSnoozeThread: (
119 thread: EnvironmentThreadShell,
120 snoozedUntil: string,
121 ) => Promise<boolean>;
122 readonly onUnsnoozeThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
123 readonly onUnsettleThread: (thread: EnvironmentThreadShell) => void;
124 readonly onPinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
125 readonly onUnpinThread: (thread: EnvironmentThreadShell) => Promise<boolean>;
126 readonly onMoveThread: (
127 thread: EnvironmentThreadShell,
128 direction: ThreadMoveDestination,
129 ) => Promise<boolean>;
130 readonly 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;
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.hasLoadedShellSnapshot
174 ) {
175 return {
176 title: "Environment unavailable",
177 detail:
178 catalogState.connectionError ??
179 "The saved environment is offline. Check the URL or start the environment, then retry.",
180 loading: false,
181 };
182 }
183​
184 if (
185 catalogState.hasConnectingEnvironment &&
186 !catalogState.hasLoadedShellSnapshot &&
187 catalogState.connectionError === null
188 ) {
189 return {
190 title: "Connecting to environment",
191 detail: "Loading projects and threads from the saved environment.",
192 loading: true,
193 };
194 }
195​
196 if (props.projectCount === 0 && catalogState.hasLoadedShellSnapshot) {
197 return {
198 title: "No projects found",
199 detail: "The connected environment did not report any projects.",
200 loading: false,
201 };
202 }
203​
204 return {
205 title: "No threads yet",
206 detail: "Create a task to start a new coding runtime in one of your connected projects.",
207 loading: false,
208 };
210​
211function HomeTopContentSpacer() {
212 return <View className="h-4" />;
214​
215/* ─── Main screen ────────────────────────────────────────────────────── */
216​
217export function HomeScreen(props: HomeScreenProps) {
218 const { materialYouStyleLayoutActive } = useAppearancePreferences();
219 const [groupDisplayStates, setGroupDisplayStates] = useState<
220 ReadonlyMap<string, HomeGroupDisplayState>
221 >(() => new Map());
222 const preferencesResult = useAtomValue(mobilePreferencesAtom);
223 const threadListV2Enabled = useThreadListV2Enabled();
224 const queuedThreadKeys = useQueuedThreadKeys();
225 const savePreferences = useAtomSet(updateMobilePreferencesAtom);
226 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
227 const listRef = useRef<LegendListRef | null>(null);
228 const insets = useSafeAreaInsets();
229 const iosBottomToolbarClearance =
230 Platform.OS === "ios" && !NATIVE_LIQUID_GLASS_SUPPORTED
231 ? PRE_LIQUID_GLASS_BOTTOM_TOOLBAR_HEIGHT
232 : 0;
233 const searchEnvironmentIds = useMemo(
234 () =>
235 props.selectedEnvironmentId === null
236 ? props.environments
237 .filter((environment) => environment.connectionState === "connected")
238 .map((environment) => environment.environmentId)
239 : props.environments.some(
240 (environment) =>
241 environment.environmentId === props.selectedEnvironmentId &&
242 environment.connectionState === "connected",
243 )
244 ? [props.selectedEnvironmentId]
245 : [],
246 [props.environments, props.selectedEnvironmentId],
247 );
248 const threadSearch = useThreadSearch(searchEnvironmentIds, props.searchQuery);
249 const threadSearchMatchByKey = useMemo(() => {
250 const matches = new Map<string, EnvironmentThreadSearchMatch>();
251 for (const match of threadSearch.matches) {
252 if (match.source === "user" || match.source === "assistant") {
253 matches.set(threadSearchMatchKey(match), match);
254 }
255 }
256 return matches;
257 }, [threadSearch.matches]);
258 const matchedThreadKeys = useMemo(
259 () => new Set(threadSearch.matches.map(threadSearchMatchKey)),
260 [threadSearch.matches],
261 );
262 const effectiveGroupDisplayStates = useMemo(() => {
263 const next = new Map(groupDisplayStates);
264 if (!AsyncResult.isSuccess(preferencesResult)) {
265 return next;
266 }
267 for (const key of preferencesResult.value.collapsedProjectGroups ?? []) {
268 const existing = next.get(key);
269 next.set(key, {
270 ...(existing ?? DEFAULT_GROUP_DISPLAY_STATE),
271 collapsed: true,
272 });
273 }
274 return next;
275 }, [groupDisplayStates, preferencesResult]);
276 const effectiveGroupDisplayStatesRef = useRef(effectiveGroupDisplayStates);
277 effectiveGroupDisplayStatesRef.current = effectiveGroupDisplayStates;
278​
279 const updateGroupDisplay = useCallback(
280 (key: string, action: HomeGroupDisplayAction) => {
281 const next = new Map(effectiveGroupDisplayStatesRef.current);
282 next.set(key, nextGroupDisplayState(next.get(key) ?? DEFAULT_GROUP_DISPLAY_STATE, action));
283 effectiveGroupDisplayStatesRef.current = next;
284 setGroupDisplayStates(next);
285 if (action === "toggle-collapsed") {
286 const collapsedProjectGroups: string[] = [];
287 for (const [groupKey, state] of next) {
288 if (state.collapsed) {
289 collapsedProjectGroups.push(groupKey);
290 }
291 }
292 savePreferences({ collapsedProjectGroups });
293 }
294 },
295 [savePreferences],
296 );
297​
298 const handleSwipeableWillOpen = useCallback((methods: SwipeableMethods) => {
299 if (openSwipeableRef.current !== methods) {
300 openSwipeableRef.current?.close();
301 openSwipeableRef.current = methods;
302 }
303 }, []);
304​
305 const handleSwipeableClose = useCallback((methods: SwipeableMethods) => {
306 if (openSwipeableRef.current === methods) {
307 openSwipeableRef.current = null;
308 }
309 }, []);
310​
311 const handleScrollBeginDrag = useCallback(() => {
312 openSwipeableRef.current?.close();
313 }, []);
314 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
315 onScrollBeginDrag: handleScrollBeginDrag,
316 });
317​
318 const projectScopes = useMemo(
319 () =>
320 buildHomeProjectScopes({
321 projects: props.projects,
322 environmentId: props.selectedEnvironmentId,
323 projectGroupingMode: props.projectGroupingMode,
324 }),
325 [props.projectGroupingMode, props.projects, props.selectedEnvironmentId],
326 );
327 const selectedProjectScope = useMemo(
328 () =>
329 props.selectedProjectKey === null
330 ? null
331 : (projectScopes.find(
332 (scope) =>
333 scope.key === props.selectedProjectKey ||
334 scope.projectRefs.some(
335 (projectRef) =>
336 scopedProjectKey(projectRef.environmentId, projectRef.projectId) ===
337 props.selectedProjectKey,
338 ),
339 ) ?? null),
340 [projectScopes, props.selectedProjectKey],
341 );
342 const selectedProjectRefKeys = useMemo(
343 () =>
344 selectedProjectScope === null
345 ? null
346 : new Set(
347 selectedProjectScope.projectRefs.map((projectRef) =>
348 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
349 ),
350 ),
351 [selectedProjectScope],
352 );
353 const scopedProjects = useMemo(
354 () =>
355 threadListV2Enabled
356 ? []
357 : selectedProjectRefKeys === null
358 ? props.projects
359 : props.projects.filter((project) =>
360 selectedProjectRefKeys.has(scopedProjectKey(project.environmentId, project.id)),
361 ),
362 [threadListV2Enabled, props.projects, selectedProjectRefKeys],
363 );
364 const scopedThreads = useMemo(
365 () =>
366 threadListV2Enabled
367 ? []
368 : selectedProjectRefKeys === null
369 ? props.threads
370 : props.threads.filter((thread) =>
371 selectedProjectRefKeys.has(scopedProjectKey(thread.environmentId, thread.projectId)),
372 ),
373 [threadListV2Enabled, props.threads, selectedProjectRefKeys],
374 );
375 const scopedPendingTasks = useMemo(
376 () =>
377 threadListV2Enabled
378 ? []
379 : selectedProjectRefKeys === null
380 ? props.pendingTasks
381 : props.pendingTasks.filter((pendingTask) =>
382 selectedProjectRefKeys.has(
383 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
384 ),
385 ),
386 [threadListV2Enabled, props.pendingTasks, selectedProjectRefKeys],
387 );
388​
389 const projectGroups = useMemo(
390 () =>
391 threadListV2Enabled
392 ? []
393 : buildHomeThreadGroups({
394 projects: scopedProjects,
395 threads: scopedThreads,
396 pendingTasks: scopedPendingTasks,
397 queuedThreadKeys,
398 environmentId: props.selectedEnvironmentId,
399 searchQuery: props.searchQuery,
400 matchedThreadKeys,
401 projectSortOrder: props.projectSortOrder,
402 threadSortOrder: props.threadSortOrder,
403 projectGroupingMode: props.projectGroupingMode,
404 }),
405 [
406 threadListV2Enabled,
407 queuedThreadKeys,
408 props.projectGroupingMode,
409 props.projectSortOrder,
410 props.searchQuery,
411 props.selectedEnvironmentId,
412 props.threadSortOrder,
413 matchedThreadKeys,
414 scopedPendingTasks,
415 scopedProjects,
416 scopedThreads,
417 ],
418 );
419​
420 const hasSearchQuery = props.searchQuery.trim().length > 0;
421 const listLayout = useMemo(
422 () =>
423 threadListV2Enabled
424 ? EMPTY_HOME_LIST_LAYOUT
425 : buildHomeListLayout({
426 groups: projectGroups,
427 displayStates: effectiveGroupDisplayStates,
428 showAllThreads: hasSearchQuery,
429 }),
430 [threadListV2Enabled, projectGroups, effectiveGroupDisplayStates, hasSearchQuery],
431 );
432​
433 const projectByKey = useMemo(() => {
434 const map = new Map<string, EnvironmentProject>();
435 for (const project of props.projects) {
436 map.set(scopedProjectKey(project.environmentId, project.id), project);
437 }
438 return map;
439 }, [props.projects]);
440​
441 const v2ProjectScopeKey = props.selectedProjectKey;
442 const v2ScopeProjects = useMemo(
443 () =>
444 sortHomeProjectScopes({
445 scopes: projectScopes,
446 threads: props.threads,
447 pendingTasks: props.pendingTasks,
448 projectSortOrder: props.projectSortOrder,
449 }),
450 [
451 props.pendingTasks,
452 props.projects,
453 props.projectSortOrder,
454 props.selectedEnvironmentId,
455 props.threads,
456 projectScopes,
457 ],
458 );
459 const v2ScopedProjectGroup = useMemo(
460 () =>
461 v2ProjectScopeKey === null
462 ? null
463 : (v2ScopeProjects.find(
464 (scope) =>
465 scope.key === v2ProjectScopeKey ||
466 scope.projectRefs.some(
467 (projectRef) =>
468 scopedProjectKey(projectRef.environmentId, projectRef.projectId) ===
469 v2ProjectScopeKey,
470 ),
471 ) ?? null),
472 [v2ProjectScopeKey, v2ScopeProjects],
473 );
474 const v2ProjectTitleByProjectKey = useMemo(
475 () =>
476 new Map(
477 v2ScopeProjects.flatMap((scope) =>
478 scope.projectRefs.map(
479 (projectRef) =>
480 [
481 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
482 scope.title,
483 ] as const,
484 ),
485 ),
486 ),
487 [v2ScopeProjects],
488 );
489 const v2ScopedProjectKeys = useMemo(
490 () =>
491 v2ScopedProjectGroup === null
492 ? null
493 : new Set(
494 v2ScopedProjectGroup.projectRefs.map((projectRef) =>
495 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
496 ),
497 ),
498 [v2ScopedProjectGroup],
499 );
500 // Thread List v2 (beta): one flat list in creation order, no grouping.
501 // Settled threads collapse into a recency tail below the card block.
502 // Settled threads stay in the live shell stream (settled ≠ archived), so
503 // the partition works directly off live shells — no snapshot merging or
504 // optimistic holds.
505 const handleSettleThread = props.onSettleThread;
506 const handleSnoozeThread = useCallback(
507 (thread: EnvironmentThreadShell, snoozedUntil: string) => {
508 void props.onSnoozeThread(thread, snoozedUntil);
509 },
510 [props.onSnoozeThread],
511 );
512 const handleUnsnoozeThread = useCallback(
513 (thread: EnvironmentThreadShell) => {
514 void props.onUnsnoozeThread(thread);
515 },
516 [props.onUnsnoozeThread],
517 );
518 const handlePinThread = useCallback(
519 (thread: EnvironmentThreadShell) => {
520 void props.onPinThread(thread);
521 },
522 [props.onPinThread],
523 );
524 const handleMoveThread = useCallback(
525 (thread: EnvironmentThreadShell, direction: ThreadMoveDestination) => {
526 void props.onMoveThread(thread, direction);
527 },
528 [props.onMoveThread],
529 );
530 const handleUnpinThread = useCallback(
531 (thread: EnvironmentThreadShell) => {
532 void props.onUnpinThread(thread);
533 },
534 [props.onUnpinThread],
535 );
536 const handleRegenerateThreadTitle = useCallback(
537 (thread: EnvironmentThreadShell) => {
538 void props.onRegenerateThreadTitle(thread);
539 },
540 [props.onRegenerateThreadTitle],
541 );
542 const handleDeleteThread = props.onDeleteThread;
543 const handleUnsettleThread = props.onUnsettleThread;
544 // The settled tail renders in pages; expansion resets when the filter
545 // context changes so environment/search flips never inherit a deep page.
546 const [settledVisibleCount, setSettledVisibleCount] = useState(
547 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
548 );
549 const settledResetKey = `${props.selectedEnvironmentId ?? "all"}:${v2ProjectScopeKey ?? "all"}:${props.searchQuery.trim()}`;
550 const lastSettledResetKeyRef = useRef(settledResetKey);
551 if (lastSettledResetKeyRef.current !== settledResetKey) {
552 lastSettledResetKeyRef.current = settledResetKey;
553 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
554 }
555 const showMoreSettled = useCallback(
556 () => setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT),
557 [],
558 );
559 const {
560 loaded: shelfPreferencesLoaded,
561 settledShelfExpanded,
562 snoozedShelfExpanded,
563 toggleSettledShelf,
564 toggleSnoozedShelf,
565 } = useThreadListV2ShelfPreferences();
566 // The queued-start and snooze helpers need a clock while the list stays open.
567 const [nowMinute, setNowMinute] = useState(() => new Date().toISOString().slice(0, 16));
568 // Snooze wake times are second-precise; a counter bumped exactly at the
569 // next wake boundary re-runs the partition with a fresh clock so a woken
570 // thread reappears immediately instead of on the next minute tick.
571 const [snoozeWakeTick, bumpSnoozeWakeTick] = useState(0);
572 useFocusEffect(
573 useCallback(() => {
574 if (!threadListV2Enabled) return;
575 // Refresh immediately on enable or focus because the previous value can be hours old.
576 setNowMinute(new Date().toISOString().slice(0, 16));
577 const id = setInterval(() => setNowMinute(new Date().toISOString().slice(0, 16)), 60_000);
578 return () => clearInterval(id);
579 }, [threadListV2Enabled]),
580 );
581 // Threads on servers without the settlement capability never classify as
582 // settled (the user could neither un-settle nor pin them).
583 const serverConfigs = useAtomValue(environmentServerConfigsAtom);
584 const settlementEnvironmentIds = useMemo(() => {
585 const supported = new Set<EnvironmentId>();
586 for (const [environmentId, config] of serverConfigs) {
587 if (config.environment.capabilities.threadSettlement === true) {
588 supported.add(environmentId);
589 }
590 }
591 return supported;
592 }, [serverConfigs]);
593 const snoozeEnvironmentIds = useMemo(() => {
594 const supported = new Set<EnvironmentId>();
595 for (const [environmentId, config] of serverConfigs) {
596 if (config.environment.capabilities.threadSnooze === true) {
597 supported.add(environmentId);
598 }
599 }
600 return supported;
601 }, [serverConfigs]);
602 const pinningEnvironmentIds = useMemo(() => {
603 const supported = new Set<EnvironmentId>();
604 for (const [environmentId, config] of serverConfigs) {
605 if (config.environment.capabilities.threadPinning === true) {
606 supported.add(environmentId);
607 }
608 }
609 return supported;
610 }, [serverConfigs]);
611 const pinReorderEnvironmentIds = useMemo(() => {
612 const supported = new Set<EnvironmentId>();
613 for (const [environmentId, config] of serverConfigs) {
614 if (config.environment.capabilities.threadPinReorder === true) {
615 supported.add(environmentId);
616 }
617 }
618 return supported;
619 }, [serverConfigs]);
620 const activeReorderEnvironmentIds = useMemo(() => {
621 const supported = new Set<EnvironmentId>();
622 for (const [environmentId, config] of serverConfigs) {
623 if (config.environment.capabilities.threadActiveReorder === true) {
624 supported.add(environmentId);
625 }
626 }
627 return supported;
628 }, [serverConfigs]);
629 const titleRegenerationEnvironmentIds = useMemo(() => {
630 const supported = new Set<EnvironmentId>();
631 for (const [environmentId, config] of serverConfigs) {
632 if (config.environment.capabilities.threadTitleRegeneration === true) {
633 supported.add(environmentId);
634 }
635 }
636 return supported;
637 }, [serverConfigs]);
638 const machineByEnvironmentId = useMemo(
639 () =>
640 new Map(
641 [...serverConfigs].map(
642 ([environmentId, config]) =>
643 [environmentId, resolveEnvironmentMachineKind(config)] as const,
644 ),
645 ),
646 [serverConfigs],
647 );
648 const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
649 const threadMovePlanners = useMemo(() => {
650 const sectionPlanner = (section: "pinned" | "active") =>
651 createThreadMovePlanner({
652 allThreads: props.threads,
653 section,
654 reorderableEnvironmentIds: new Set(
655 [...serverConfigs].flatMap(([id, config]) =>
656 (section === "pinned"
657 ? config.environment.capabilities.threadPinReorder
658 : config.environment.capabilities.threadActiveReorder) === true
659 ? [id]
660 : [],
661 ),
662 ),
663 ordered: getThreadListV2OrderedSection({
664 threads: props.threads,
665 section,
666 pendingOrder,
667 now: new Date().toISOString(),
668 settlementEnvironmentIds,
669 snoozeEnvironmentIds,
670 queuedThreadKeys,
671 }),
672 });
673 return { pinned: sectionPlanner("pinned"), active: sectionPlanner("active") };
674 }, [
675 serverConfigs,
676 props.threads,
677 pendingOrder,
678 queuedThreadKeys,
679 settlementEnvironmentIds,
680 snoozeEnvironmentIds,
681 nowMinute,
682 snoozeWakeTick,
683 ]);
684 const threadListV2Layout = useMemo(() => {
685 if (!threadListV2Enabled)
686 return {
687 items: [],
688 hiddenSettledCount: 0,
689 snoozedCount: 0,
690 snoozedShelfHeaderIndex: null,
691 settledCount: 0,
692 settledShelfHeaderIndex: null,
693 nextSnoozeWakeAt: null,
694 };
695 // Settled threads are live shells; archived threads keep their original
696 // "hidden from lists" meaning.
697 return buildThreadListV2Items({
698 pendingOrder,
699 threads: props.threads.filter((thread) => thread.archivedAt === null),
700 environmentId: props.selectedEnvironmentId,
701 projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs,
702 searchQuery: props.searchQuery,
703 matchedThreadKeys,
704 settlementEnvironmentIds,
705 snoozeEnvironmentIds,
706 queuedThreadKeys,
707 settledLimit: settledVisibleCount,
708 now: new Date().toISOString(),
709 snoozedShelfExpanded,
710 settledShelfExpanded,
711 selectedThreadKey: null,
712 });
713 }, [
714 pendingOrder,
715 queuedThreadKeys,
716 nowMinute,
717 snoozeWakeTick,
718 snoozedShelfExpanded,
719 settledShelfExpanded,
720 settledVisibleCount,
721 settlementEnvironmentIds,
722 snoozeEnvironmentIds,
723 props.searchQuery,
724 props.selectedEnvironmentId,
725 props.threads,
726 matchedThreadKeys,
727 threadListV2Enabled,
728 v2ScopedProjectGroup,
729 ]);
730 // Re-partition the moment the earliest snooze expires (clamped to the
731 // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
732 const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;
733 useEffect(() => {
734 if (nextSnoozeWakeAt === null) return;
735 const wakeAtMs = Date.parse(nextSnoozeWakeAt);
736 if (Number.isNaN(wakeAtMs)) return;
737 const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);
738 const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);
739 return () => clearTimeout(id);
740 // snoozeWakeTick must re-arm the timer even when nextSnoozeWakeAt is
741 // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
742 // range) the boundary string is identical and the chain would die.
743 }, [nextSnoozeWakeAt, snoozeWakeTick]);
744 // Queued tasks are not thread shells, so the v2 partition never sees them;
745 // they are spliced in below the active block and stay visible and deletable
746 // while their environment is offline. Same environment scope and search
747 // filter as the list itself.
748 const v2SearchQuery = props.searchQuery.trim().toLocaleLowerCase();
749 const v2PendingTasks = useMemo(
750 () =>
751 props.pendingTasks.filter(
752 (pendingTask) =>
753 (props.selectedEnvironmentId === null ||
754 pendingTask.environmentId === props.selectedEnvironmentId) &&
755 (v2ScopedProjectKeys === null ||
756 v2ScopedProjectKeys.has(
757 scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
758 )) &&
759 (v2SearchQuery.length === 0 ||
760 pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
761 ),
762 [props.pendingTasks, props.selectedEnvironmentId, v2ScopedProjectKeys, v2SearchQuery],
763 );
764 const threadListV2Items = useMemo(
765 () =>
766 buildThreadListV2ListItems({
767 items: threadListV2Layout.items,
768 pendingTasks: v2PendingTasks,
769 snoozedCount: threadListV2Layout.snoozedCount,
770 snoozedShelfExpanded,
771 snoozedShelfHeaderIndex: threadListV2Layout.snoozedShelfHeaderIndex,
772 settledCount: threadListV2Layout.settledCount,
773 settledShelfExpanded,
774 settledShelfHeaderIndex: threadListV2Layout.settledShelfHeaderIndex,
775 snoozeLabelNow: `${nowMinute}:00.000Z`,
776 }),
777 [settledShelfExpanded, snoozedShelfExpanded, threadListV2Layout, v2PendingTasks],
778 );
779​
780 useThreadJumpShortcuts(
781 threadListV2Enabled ? threadListV2Items : listLayout.items,
782 props.onSelectThread,
783 );
784​
785 const renderV2Item = useCallback(
786 ({ item, index }: { readonly item: ThreadListV2ListItem; readonly index: number }) => {
787 const nextItem = threadListV2Items[index + 1];
788 const showTrailingDivider =
789 nextItem?.type === "v2-thread" ||
790 (nextItem?.type === "v2-pending" && !nextItem.showPendingDivider);
791 if (item.type === "v2-pending") {
792 const pendingScopeKey = scopedProjectKey(
793 item.pendingTask.environmentId,
794 item.pendingTask.projectId,
795 );
796 return (
797 <ThreadListV2PendingRow
798 pendingTask={item.pendingTask}
799 project={projectByKey.get(pendingScopeKey) ?? null}
800 projectTitle={v2ProjectTitleByProjectKey.get(pendingScopeKey)}
801 environmentLabel={
802 Object.keys(props.savedConnectionsById).length > 1
803 ? (props.savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ??
804 null)
805 : null
806 }
807 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
808 showPendingDivider={item.showPendingDivider}
809 showTrailingDivider={showTrailingDivider}
810 onSelectPendingTask={props.onSelectPendingTask}
811 onDeletePendingTask={props.onDeletePendingTask}
812 />
813 );
814 }
815 if (item.type === "v2-snoozed-shelf") {
816 return (
817 <ThreadListV2SnoozedShelfHeader
818 count={item.count}
819 disabled={!shelfPreferencesLoaded}
820 expanded={item.expanded}
821 onToggle={toggleSnoozedShelf}
822 />
823 );
824 }
825 if (item.type === "v2-settled-shelf") {
826 return (
827 <ThreadListV2SettledShelfHeader
828 count={item.count}
829 disabled={!shelfPreferencesLoaded}
830 expanded={item.expanded}
831 onToggle={toggleSettledShelf}
832 />
833 );
834 }
835 const thread = item.item.thread;
836 const movePlanner = item.item.pinned ? threadMovePlanners.pinned : threadMovePlanners.active;
837 const movedId = `${thread.environmentId}:${thread.id}`;
838 const provider = serverConfigs
839 .get(thread.environmentId)
840 ?.providers.find(
841 (candidate) =>
842 candidate.instanceId ===
843 (thread.runtime?.providerInstanceId ?? thread.modelSelection.instanceId),
844 );
845 return (
846 <ThreadListV2Row
847 onNewThreadOnBranch={props.onNewThreadOnBranch}
848 thread={thread}
849 variant={item.item.variant}
850 hasQueuedMessages={queuedThreadKeys.has(movedId)}
851 snoozed={item.item.snoozed}
852 pinned={item.item.pinned}
853 snoozePresetMinute={nowMinute}
854 snoozeWakeLabelText={item.snoozeWakeLabelText}
855 showTrailingDivider={showTrailingDivider}
856 project={
857 projectByKey.get(scopedProjectKey(thread.environmentId, thread.projectId)) ?? null
858 }
859 projectTitle={v2ProjectTitleByProjectKey.get(
860 scopedProjectKey(thread.environmentId, thread.projectId),
861 )}
862 providerDrivers={resolveThreadListV2ProviderDrivers(
863 thread,
864 serverConfigs.get(thread.environmentId)?.providers,
865 )}
866 providerInstance={resolveThreadProviderInstance(serverConfigs, thread)}
867 providerIconUrl={provider?.iconUrl}
868 environmentLabel={
869 Object.keys(props.savedConnectionsById).length > 1
870 ? (props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
871 : null
872 }
873 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
874 searchMatch={threadSearchMatchByKey.get(
875 threadSearchMatchKey({
876 environmentId: thread.environmentId,
877 threadId: thread.id,
878 }),
879 )}
880 searchQuery={props.searchQuery}
881 onSelectThread={props.onSelectThread}
882 onDeleteThread={handleDeleteThread}
883 onArchiveThread={props.onArchiveThread}
884 onRegenerateThreadTitle={handleRegenerateThreadTitle}
885 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
886 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
887 onSettleThread={handleSettleThread}
888 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
889 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
890 reorderSupported={
891 item.item.pinned
892 ? pinReorderEnvironmentIds.has(thread.environmentId)
893 : activeReorderEnvironmentIds.has(thread.environmentId)
894 }
895 canMoveUp={pendingOrder === null && movePlanner(movedId, "up") !== null}
896 canMoveDown={pendingOrder === null && movePlanner(movedId, "down") !== null}
897 onSnoozeThread={handleSnoozeThread}
898 onUnsnoozeThread={handleUnsnoozeThread}
899 onUnsettleThread={handleUnsettleThread}
900 onPinThread={handlePinThread}
901 onUnpinThread={handleUnpinThread}
902 onMoveThread={handleMoveThread}
903 onSwipeableClose={handleSwipeableClose}
904 onSwipeableWillOpen={handleSwipeableWillOpen}
905 />
906 );
907 },
908 [
909 handleDeleteThread,
910 activeReorderEnvironmentIds,
911 threadMovePlanners,
912 pendingOrder,
913 queuedThreadKeys,
914 handleMoveThread,
915 handlePinThread,
916 handleRegenerateThreadTitle,
917 handleSettleThread,
918 handleSnoozeThread,
919 handleUnpinThread,
920 handleUnsnoozeThread,
921 handleSwipeableClose,
922 handleSwipeableWillOpen,
923 handleUnsettleThread,
924 pinningEnvironmentIds,
925 machineByEnvironmentId,
926 pinReorderEnvironmentIds,
927 projectByKey,
928 props.onArchiveThread,
929 props.onDeletePendingTask,
930 props.onSelectPendingTask,
931 props.onSelectThread,
932 props.onNewThreadOnBranch,
933 props.savedConnectionsById,
934 serverConfigs,
935 shelfPreferencesLoaded,
936 settlementEnvironmentIds,
937 snoozeEnvironmentIds,
938 threadListV2Items,
939 threadSearchMatchByKey,
940 titleRegenerationEnvironmentIds,
941 toggleSettledShelf,
942 toggleSnoozedShelf,
943 v2ProjectTitleByProjectKey,
944 props.searchQuery,
945 nowMinute,
946 ],
947 );
948 const v2KeyExtractor = useCallback((item: ThreadListV2ListItem) => item.key, []);
949​
950 // FlatList treats a changed extraData identity as "re-render every visible
951 // row", so an inline object literal would invalidate all rows on every
952 // HomeScreen render.
953 const v2ExtraData = useMemo(
954 () => ({
955 projectByKey,
956 projectTitleByProjectKey: v2ProjectTitleByProjectKey,
957 serverConfigs,
958 savedConnectionsById: props.savedConnectionsById,
959 searchQuery: props.searchQuery,
960 snoozePresetMinute: nowMinute,
961 threadSearchMatchByKey,
962 }),
963 [
964 projectByKey,
965 props.searchQuery,
966 props.savedConnectionsById,
967 serverConfigs,
968 nowMinute,
969 threadSearchMatchByKey,
970 v2ProjectTitleByProjectKey,
971 ],
972 );
973​
974 const extraData = useMemo(
975 () => ({
976 savedConnectionsById: props.savedConnectionsById,
977 searchQuery: props.searchQuery,
978 threadSearchMatchByKey,
979 }),
980 [props.savedConnectionsById, props.searchQuery, threadSearchMatchByKey],
981 );
982​
983 const renderItem = useCallback(
984 ({ item }: LegendListRenderItemProps<HomeListItem>) => {
985 switch (item.type) {
986 case "header":
987 return (
988 <ThreadListGroupHeader
989 variant="compact"
990 collapsed={item.collapsed}
991 isFirst={item.isFirst}
992 groupKey={item.group.key}
993 onGroupAction={updateGroupDisplay}
994 // Aggregated groups (same repo across machines) have no single
995 // target project, and `pending-project:` groups hold a placeholder
996 // built from queued-task metadata rather than a real project shell,
997 // so the quick new-thread button is single-real-project only.
998 newThreadTarget={item.group.newThreadTarget}
999 onNewThread={props.onNewThreadInProject}
1000 project={item.group.representative}
1001 threadCount={item.group.threads.length + item.group.pendingTasks.length}
1002 title={item.group.title}
1003 />
1004 );
1005 case "pending-task":
1006 return (
1007 <PendingTaskListRow
1008 variant="compact"
1009 pendingTask={item.pendingTask}
1010 environmentLabel={
1011 props.savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null
1013 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
1014 isLast={item.isLast}
1015 onSelectPendingTask={props.onSelectPendingTask}
1016 onDeletePendingTask={props.onDeletePendingTask}
1017 />
1018 );
1019 case "thread": {
1020 const thread = item.thread;
1021 return (
1022 <ThreadListRow
1023 onNewThreadOnBranch={props.onNewThreadOnBranch}
1024 variant="compact"
1025 thread={thread}
1026 hasQueuedMessages={queuedThreadKeys.has(`${thread.environmentId}:${thread.id}`)}
1027 environmentLabel={
1028 props.savedConnectionsById[thread.environmentId]?.environmentLabel ?? null
1030 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
1031 isLast={item.isLast}
1032 searchMatch={threadSearchMatchByKey.get(
1033 threadSearchMatchKey({
1034 environmentId: thread.environmentId,
1035 threadId: thread.id,
1036 }),
1037 )}
1038 searchQuery={props.searchQuery}
1039 onArchiveThread={props.onArchiveThread}
1040 onDeleteThread={props.onDeleteThread}
1041 onRegenerateThreadTitle={handleRegenerateThreadTitle}
1042 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
1043 onSelectThread={props.onSelectThread}
1044 onSwipeableClose={handleSwipeableClose}
1045 onSwipeableWillOpen={handleSwipeableWillOpen}
1046 />
1047 );
1049 case "show-more":
1050 return (
1051 <ThreadListShowMoreRow
1052 variant="compact"
1053 hiddenCount={item.hiddenCount}
1054 canShowLess={item.canShowLess}
1055 groupKey={item.groupKey}
1056 onGroupAction={updateGroupDisplay}
1057 />
1058 );
1060 },
1062 handleSwipeableClose,
1063 handleSwipeableWillOpen,
1064 handleRegenerateThreadTitle,
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 }}
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 );
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 runtime." />
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"
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 })}
1200 <Text className="text-xs font-t3-medium text-foreground-muted">
1201 Show more ({threadListV2Layout.hiddenSettledCount} settled hidden)
1202 </Text>
1203 </Pressable>
1204 ) : null
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 );
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"
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,
1281 : undefined
1283 />
1284 </SwipeableScrollGateProvider>
1285 </View>
1286 </View>
1287 );