Open History to see the last commit
1import { useActiveNewTask } from "../../state/active-new-task";
2import { ThreadUndoNotice } from "../home/ThreadUndoNotice";
3import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
4import {
5 pickableProjectGroups,
6 resolveScratchProjectScopeKey,
7} from "@t3tools/client-runtime/state/project-grouping";
8import {
9 useAppearancePreferences,
10 useAndroidFloatingTabs,
11} from "../settings/appearance/AppearancePreferencesProvider";
12import type {
13 EnvironmentProject,
14 EnvironmentThreadShell,
15} from "@t3tools/client-runtime/state/shell";
16import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
17import { AnimatedLegendList } from "@legendapp/list/reanimated";
18import { THREAD_SIDEBAR_ROW_LAYOUT } from "./threadListAnimations";
19import { useAtomValue } from "@effect/atom-react";
20import { useMemo, useRef, useState } from "react";
21import { Platform, StyleSheet, View } from "react-native";
22import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
23import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
24import { FLOATING_TABS } from "../layout/workspace/floating-workspace-tabs";
25import { useSafeAreaInsets } from "react-native-safe-area-context";
26
27import { AppText as Text } from "../../components/ui/AppText";
28import { Button } from "../../components/ui/Button";
29import { scopedProjectKey, scopedThreadKey } from "../../lib/scopedEntities";
30import { useProjects } from "../../state/entities";
31import { steadyNavigationThreadShellsAtom } from "../../state/threads";
32import { useThreadSearch } from "../../state/queries";
33import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences";
34import { useThreadListNow } from "./use-thread-list-now";
35import { usePendingThreadOrder } from "../../state/thread-order";
36import { threadListEnvironmentsAtom } from "../../state/presentation";
37import {
38 useLaunchingThreads,
39 usePendingNewTasks,
40 type PendingNewTask,
41} from "../../state/use-pending-new-tasks";
42import { useQueuedThreadKeys } from "../../state/use-thread-outbox";
43import { useWorkspaceState } from "../../state/workspace";
44import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
45import { useThreadListV2 } from "./useThreadListV2";
46import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts";
47import { requestThreadMessageJump } from "./threadMessageJump";
48import { useThreadListSearchMatches } from "./useThreadListSearchMatches";
49import { useHomeListOptions } from "../home/home-list-options";
50import { buildHomeListFilterMenuItems } from "../home/home-list-filter-menu";
51import { buildHomeProjectScopes } from "../home/homeThreadList";
52import { SwipeableScrollGateProvider, useSwipeableScrollGate } from "../home/thread-swipe-actions";
53import { usePendingTaskListActions } from "../home/usePendingTaskListActions";
54import { useThreadListActions } from "../home/useThreadListActions";
55import { useFabScroll } from "../home/FabScrollContext";
56import { WorkspaceListHeader } from "../layout/workspace/WorkspaceListHeader";
57import { WorkspaceSidebarColumn } from "../layout/workspace/WorkspaceSidebarColumn";
58import {
59 ThreadListV2PendingRow,
60 ThreadListV2Row,
61 ThreadListV2SettledShelfHeader,
62 ThreadListV2ShowMoreRow,
63 ThreadListV2SnoozedShelfHeader,
64 ThreadListV2WorkingShelfHeader,
65} from "./thread-list-v2-items";
66import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
67import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
68import { ThreadPrDemandProvider } from "../../state/thread-pr-demand";
69import {
70 isThreadListV2ListItem,
71 threadListV2ListItemsAreEqual,
72 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
73 THREAD_LIST_V2_SETTLED_PAGE_COUNT,
74 type ThreadListV2ListItem,
75} from "./threadListV2";
76import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";
77import { NativeScrollView } from "../../native/NativeScrollViewMarker";
78
79type SidebarListItem =
80 | ThreadListV2ListItem
81 | {
82 readonly type: "v2-show-more";
83 readonly key: string;
84 readonly hiddenCount: number;
85 readonly state?: "loading" | "failed";
86 };
87
88interface ThreadNavigationSidebarProps {
89 readonly width: number;
90 readonly visible: boolean;
91 readonly selectedThreadKey: string | null;
92 readonly onOpenSettings: () => void;
93 readonly onOpenEnvironmentSettings: () => void;
94 readonly onNewThreadOnBranch: (thread: EnvironmentThreadShell) => void;
95 readonly onNewThreadInProject: (project: EnvironmentProject) => void;
96 readonly onOpenPendingTask: (pendingTask: PendingNewTask) => void;
97 readonly onSearchQueryChange: (query: string) => void;
98 readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
99 readonly onOpenThreadPullRequests: (
100 thread: EnvironmentThreadShell,
101 pr: ThreadPrPresentation,
102 ) => void;
103 readonly onRequestVisibility: () => void;
104 readonly searchQuery: string;
105}
106
107export function ThreadNavigationSidebar(props: ThreadNavigationSidebarProps) {
108 return (
109 <ThreadPrDemandProvider visible={props.visible}>
110 <WorkspaceSidebarColumn width={props.width}>
111 <ThreadNavigationSidebarPane {...props} />
112 </WorkspaceSidebarColumn>
113 </ThreadPrDemandProvider>
114 );
115}
116
117function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
118 const floatingTabsEnabled = useAndroidFloatingTabs();
119 const { themeVariables: materialTheme } = useAppearancePreferences();
120 const drawerColor = materialTheme["--color-drawer"];
121
122 const insets = useSafeAreaInsets();
123 const { fabClearance, fabSize } = useAndroidControlSizing();
124 const projects = useProjects();
125 const threads = useAtomValue(steadyNavigationThreadShellsAtom);
126 const { environments: workspaceEnvironments, state: catalogState } = useWorkspaceState();
127 const { savedConnectionsById } = useSavedRemoteConnections();
128 const openSwipeableRef = useRef<SwipeableMethods | null>(null);
129 const sidebarScrollGesture = useNativeGesture();
130 const {
131 archiveThread,
132 confirmDeleteThread,
133 settleThread,
134 snoozeThread,
135 unsnoozeThread,
136 unsettleThread,
137 pinThread,
138 unpinThread,
139 setThreadAutoSettle,
140 moveThread,
141 renameThread,
142 regenerateThreadTitle,
143 } = useThreadListActions();
144 const pendingTasks = usePendingNewTasks();
145 const launchingThreads = useLaunchingThreads(threads);
146 const activeNewTask = useActiveNewTask();
147 const queuedThreadKeys = useQueuedThreadKeys();
148 const selectDetail = useSelectWorkspaceDetail();
149 const { confirmDeletePendingTask } = usePendingTaskListActions((params) =>
150 selectDetail({ name: "Thread", params }),
151 );
152 const environments = Object.values(savedConnectionsById)
153 .map((connection) => ({
154 environmentId: connection.environmentId,
155 label: connection.environmentLabel,
156 }))
157 .sort((left, right) => left.label.localeCompare(right.label));
158 const availableEnvironmentIds = new Set(
159 environments.map((environment) => environment.environmentId),
160 );
161 const { options, setSelectedEnvironmentId, setSelectedProjectKey } =
162 useHomeListOptions(availableEnvironmentIds);
163 const searchEnvironmentIds =
164 options.selectedEnvironmentId === null
165 ? workspaceEnvironments
166 .filter((environment) => environment.connectionState === "connected")
167 .map((environment) => environment.environmentId)
168 : workspaceEnvironments.some(
169 (environment) =>
170 environment.environmentId === options.selectedEnvironmentId &&
171 environment.connectionState === "connected",
172 )
173 ? [options.selectedEnvironmentId]
174 : [];
175 // A legacy per-environment scratch key resolves here on every render; the stored
176 // value is only rewritten when the user picks a filter.
177 const resolvedProjectKey = resolveScratchProjectScopeKey(options.selectedProjectKey, projects, {
178 sidebarProjectGroupingMode: options.projectGroupingMode,
179 sidebarProjectGroupingOverrides: {},
180 });
181 const projectScopes = useMemo(
182 () =>
183 buildHomeProjectScopes({
184 projects,
185 environmentId: options.selectedEnvironmentId,
186 projectGroupingMode: options.projectGroupingMode,
187 }),
188 [projects, options.selectedEnvironmentId, options.projectGroupingMode],
189 );
190 const projectFilterOptions = pickableProjectGroups(projectScopes).map((scope) => ({
191 key: scope.key,
192 label: scope.title,
193 }));
194 const projectTitleByProjectKey = useMemo(
195 () =>
196 new Map(
197 projectScopes.flatMap((scope) =>
198 scope.projectRefs.map(
199 (projectRef) =>
200 [
201 scopedProjectKey(projectRef.environmentId, projectRef.projectId),
202 scope.title,
203 ] as const,
204 ),
205 ),
206 ),
207 [projectScopes],
208 );
209 // An archived project's filter reads as all projects, matching the filter menu.
210 const selectedProjectScope =
211 pickableProjectGroups(projectScopes).find((scope) => scope.key === resolvedProjectKey) ?? null;
212 const threadSearch = useThreadSearch(
213 searchEnvironmentIds,
214 props.searchQuery,
215 selectedProjectScope === null
216 ? {}
217 : { projectIds: selectedProjectScope.projectRefs.map((ref) => ref.projectId) },
218 );
219 // This map reaches LegendList's extraData, which re-renders every row whenever it changes
220 // identity; the hook keeps it stable.
221 const threadSearchMatchByKey = useThreadListSearchMatches(threads, threadSearch);
222 const selectedProjectKey = selectedProjectScope?.key ?? null;
223 const projectByKey = useMemo(() => {
224 const map = new Map<string, EnvironmentProject>();
225 for (const project of projects) {
226 map.set(scopedProjectKey(project.environmentId, project.id), project);
227 }
228 return map;
229 }, [projects]);
230
231 const [settledVisibleCount, setSettledVisibleCount] = useState(
232 THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
233 );
234 const settledResetKey = `${options.selectedEnvironmentId ?? "all"}:${selectedProjectKey ?? "all"}:${props.searchQuery.trim()}`;
235 const [lastSettledResetKey, setLastSettledResetKey] = useState(settledResetKey);
236 if (lastSettledResetKey !== settledResetKey) {
237 setLastSettledResetKey(settledResetKey);
238 setSettledVisibleCount(THREAD_LIST_V2_SETTLED_INITIAL_COUNT);
239 }
240 const showMoreSettled = () =>
241 setSettledVisibleCount((count) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT);
242 const {
243 loaded: shelfPreferencesLoaded,
244 settledShelfExpanded,
245 snoozedShelfExpanded,
246 workingShelfEnabled,
247 workingShelfExpanded,
248 toggleSettledShelf,
249 toggleSnoozedShelf,
250 toggleWorkingShelf,
251 } = useThreadListV2ShelfPreferences();
252 const now = useThreadListNow(threads);
253 const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
254 const {
255 providersByEnvironmentId,
256 machineByEnvironmentId,
257 settlementEnvironmentIds,
258 snoozeEnvironmentIds,
259 snoozePresetsByEnvironmentId,
260 pinningEnvironmentIds,
261 autoSettleOptOutEnvironmentIds,
262 pinReorderEnvironmentIds,
263 activeReorderEnvironmentIds,
264 titleRegenerationEnvironmentIds,
265 } = listEnvironments;
266 const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
267 const pendingOrder = usePendingThreadOrder();
268 const {
269 layout: threadListV2Layout,
270 items: threadListV2Items,
271 contentOnlyThreadKeys,
272 olderSettledShelf,
273 } = useThreadListV2({
274 threads: launchingThreads,
275 pendingTasks,
276 environmentId: options.selectedEnvironmentId,
277 projectRefs: selectedProjectScope === null ? null : selectedProjectScope.projectRefs,
278 searchQuery: props.searchQuery,
279 searchMatches: threadSearchMatchByKey,
280 settlementEnvironmentIds,
281 snoozeEnvironmentIds,
282 pinReorderEnvironmentIds,
283 activeReorderEnvironmentIds,
284 queuedThreadKeys,
285 settledLimit: settledVisibleCount,
286 now,
287 pendingOrder,
288 shelfPreferencesLoaded,
289 workingShelfEnabled,
290 workingShelfExpanded,
291 snoozedShelfExpanded,
292 settledShelfExpanded,
293 selectedThreadKey: props.selectedThreadKey ?? null,
294 });
295 const listItems: readonly SidebarListItem[] =
296 settledShelfExpanded && threadListV2Layout.hiddenSettledCount > 0
297 ? [
298 ...threadListV2Items,
299 {
300 type: "v2-show-more",
301 key: "v2-show-more",
302 hiddenCount: threadListV2Layout.hiddenSettledCount,
303 ...(olderSettledShelf.loading
304 ? { state: "loading" as const }
305 : olderSettledShelf.failed
306 ? { state: "failed" as const }
307 : {}),
308 },
309 ]
310 : threadListV2Items;
311
312 const handleSwipeableWillOpen = (methods: SwipeableMethods) => {
313 if (openSwipeableRef.current !== methods) {
314 openSwipeableRef.current?.close();
315 openSwipeableRef.current = methods;
316 }
317 };
318 const handleSwipeableClose = (methods: SwipeableMethods) => {
319 if (openSwipeableRef.current === methods) {
320 openSwipeableRef.current = null;
321 }
322 };
323 // Destructure callback props; capturing all props would invalidate these row-closing handlers on unrelated changes.
324 const { onSelectThread, onOpenThreadPullRequests } = props;
325 // A row listed for a message match opens the thread at that message, by
326 // tap or by shortcut.
327 const handleSelectThread = (thread: EnvironmentThreadShell) => {
328 const key = threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id });
329 const messageId = contentOnlyThreadKeys.has(key)
330 ? threadSearchMatchByKey.get(key)?.messageId
331 : undefined;
332 if (messageId) {
333 requestThreadMessageJump(scopedThreadKey(thread.environmentId, thread.id), messageId);
334 }
335 onSelectThread(thread);
336 openSwipeableRef.current?.close();
337 };
338 const handleOpenThreadPullRequests = (
339 thread: EnvironmentThreadShell,
340 pr: ThreadPrPresentation,
341 ) => {
342 onOpenThreadPullRequests(thread, pr);
343 openSwipeableRef.current?.close();
344 };
345 const handleScrollBeginDrag = () => {
346 openSwipeableRef.current?.close();
347 };
348 const onFabScroll = useFabScroll();
349 const { swipeEnabled, scrollGateHandlers } = useSwipeableScrollGate({
350 onScroll: onFabScroll,
351 onScrollBeginDrag: handleScrollBeginDrag,
352 });
353 // Recycle equality needs project/search data for titles and favicons; keep the minute clock on items to limit updates.
354 const listExtraData = {
355 activeNewTask,
356 selectedThreadKey: props.selectedThreadKey ?? "",
357 projectByKey,
358 projectTitleByProjectKey,
359 savedConnectionsById,
360 listEnvironments,
361 threadSearchMatchByKey,
362 workingShelfEnabled,
363 };
364 useThreadJumpShortcuts(listItems, handleSelectThread);
365 const sidebarItemsAreEqual = (previous: SidebarListItem, item: SidebarListItem): boolean => {
366 if (isThreadListV2ListItem(previous) && isThreadListV2ListItem(item)) {
367 return threadListV2ListItemsAreEqual(previous, item);
368 }
369 if (previous.type === "v2-show-more" && item.type === "v2-show-more") {
370 return previous.hiddenCount === item.hiddenCount && previous.state === item.state;
371 }
372 return false;
373 };
374 const renderListItem = ({ item }: { readonly item: SidebarListItem }) => {
375 switch (item.type) {
376 case "v2-pending": {
377 const pendingScopeKey = scopedProjectKey(
378 item.pendingTask.environmentId,
379 item.pendingTask.projectId,
380 );
381 return (
382 <ThreadListV2PendingRow
383 pendingTask={item.pendingTask}
384 selected={
385 activeNewTask?.pendingKey === item.pendingTask.key ||
386 (item.pendingTask.kind === "pending" &&
387 scopedThreadKey(
388 item.pendingTask.environmentId,
389 item.pendingTask.message.threadId,
390 ) === props.selectedThreadKey)
391 }
392 project={projectByKey.get(pendingScopeKey) ?? null}
393 projectTitle={projectTitleByProjectKey.get(pendingScopeKey)}
394 environmentLabel={
395 Object.keys(savedConnectionsById).length > 1
396 ? (savedConnectionsById[item.pendingTask.environmentId]?.environmentLabel ?? null)
397 : null
398 }
399 environmentMachine={machineByEnvironmentId.get(item.pendingTask.environmentId)}
400 pane="sidebar"
401 showPendingDivider={item.showPendingDivider}
402 onSelectPendingTask={props.onOpenPendingTask}
403 onDeletePendingTask={confirmDeletePendingTask}
404 fullSwipeWidth={props.width - 20}
405 onSwipeableClose={handleSwipeableClose}
406 onSwipeableWillOpen={handleSwipeableWillOpen}
407 simultaneousSwipeGesture={sidebarScrollGesture}
408 />
409 );
410 }
411 case "v2-thread": {
412 const thread = item.item.thread;
413 const scopeKey = scopedProjectKey(thread.environmentId, thread.projectId);
414 return (
415 <ThreadListV2Row
416 onNewThreadOnBranch={props.onNewThreadOnBranch}
417 thread={thread}
418 variant={item.item.variant}
419 hasQueuedMessages={item.hasQueuedMessages}
420 snoozed={item.item.snoozed}
421 pinned={item.item.pinned}
422 wokeAt={item.item.wokeAt}
423 snoozePresetMinute={item.snoozePresetMinute ?? ""}
424 snoozeWakeLabelText={item.snoozeWakeLabelText}
425 timeLabel={item.timeLabel}
426 project={projectByKey.get(scopeKey) ?? null}
427 providerInstance={resolveProviderInstance(thread)}
428 providers={providersByEnvironmentId.get(thread.environmentId)}
429 environmentLabel={
430 Object.keys(savedConnectionsById).length > 1
431 ? (savedConnectionsById[thread.environmentId]?.environmentLabel ?? null)
432 : null
433 }
434 environmentMachine={machineByEnvironmentId.get(thread.environmentId)}
435 searchMatch={
436 // Only rows listed for their messages show one and open at it.
437 contentOnlyThreadKeys.has(
438 threadSearchMatchKey({ environmentId: thread.environmentId, threadId: thread.id }),
439 )
440 ? threadSearchMatchByKey.get(
441 threadSearchMatchKey({
442 environmentId: thread.environmentId,
443 threadId: thread.id,
444 }),
445 )
446 : undefined
447 }
448 searchQuery={threadSearch.query}
449 pane="sidebar"
450 selected={
451 !activeNewTask &&
452 scopedThreadKey(thread.environmentId, thread.id) === props.selectedThreadKey
453 }
454 fullSwipeWidth={props.width - 20}
455 onSelectThread={handleSelectThread}
456 onOpenThreadPullRequests={handleOpenThreadPullRequests}
457 onDeleteThread={confirmDeleteThread}
458 onArchiveThread={archiveThread}
459 onRenameThread={renameThread}
460 onRegenerateThreadTitle={regenerateThreadTitle}
461 titleRegenerationSupported={titleRegenerationEnvironmentIds.has(thread.environmentId)}
462 settlementSupported={settlementEnvironmentIds.has(thread.environmentId)}
463 onSettleThread={settleThread}
464 snoozeSupported={snoozeEnvironmentIds.has(thread.environmentId)}
465 snoozePresets={snoozePresetsByEnvironmentId.get(thread.environmentId)}
466 pinningSupported={pinningEnvironmentIds.has(thread.environmentId)}
467 autoSettleOptOutSupported={autoSettleOptOutEnvironmentIds.has(thread.environmentId)}
468 reorderSupported={
469 item.item.pinned
470 ? pinReorderEnvironmentIds.has(thread.environmentId)
471 : !workingShelfEnabled && activeReorderEnvironmentIds.has(thread.environmentId)
472 }
473 canMoveUp={item.canMoveUp}
474 canMoveDown={item.canMoveDown}
475 onSnoozeThread={snoozeThread}
476 onUnsnoozeThread={unsnoozeThread}
477 onUnsettleThread={unsettleThread}
478 onPinThread={pinThread}
479 onUnpinThread={unpinThread}
480 onSetThreadAutoSettle={setThreadAutoSettle}
481 onMoveThread={moveThread}
482 onSwipeableClose={handleSwipeableClose}
483 onSwipeableWillOpen={handleSwipeableWillOpen}
484 simultaneousSwipeGesture={sidebarScrollGesture}
485 />
486 );
487 }
488 case "v2-working-shelf":
489 return (
490 <ThreadListV2WorkingShelfHeader
491 count={item.count}
492 disabled={item.disabled}
493 expanded={item.expanded}
494 onToggle={toggleWorkingShelf}
495 pane="sidebar"
496 />
497 );
498 case "v2-snoozed-shelf":
499 return (
500 <ThreadListV2SnoozedShelfHeader
501 count={item.count}
502 disabled={item.disabled}
503 expanded={item.expanded}
504 onToggle={toggleSnoozedShelf}
505 pane="sidebar"
506 />
507 );
508 case "v2-settled-shelf":
509 return (
510 <ThreadListV2SettledShelfHeader
511 count={item.count}
512 disabled={item.disabled}
513 expanded={item.expanded}
514 onToggle={toggleSettledShelf}
515 pane="sidebar"
516 />
517 );
518 case "v2-show-more":
519 return (
520 <ThreadListV2ShowMoreRow
521 pane="sidebar"
522 hiddenCount={item.hiddenCount}
523 {...(item.state === undefined ? {} : { state: item.state })}
524 onPress={() => {
525 olderSettledShelf.retry();
526 showMoreSettled();
527 }}
528 />
529 );
530 }
531 };
532 const header = (
533 <WorkspaceListHeader
534 accessibilityLabel="T3 Code, Threads"
535 onOpenEnvironments={props.onOpenEnvironmentSettings}
536 onOpenSettings={props.onOpenSettings}
537 search={{
538 value: props.searchQuery,
539 onChangeText: props.onSearchQueryChange,
540 placeholder: "Search",
541 accessibilityLabel: "Search threads",
542 }}
543 filter={{
544 customized: options.selectedEnvironmentId !== null || selectedProjectKey !== null,
545 items: buildHomeListFilterMenuItems({
546 environments,
547 projects: projectFilterOptions,
548 selectedEnvironmentId: options.selectedEnvironmentId,
549 selectedProjectKey,
550 onEnvironmentChange: setSelectedEnvironmentId,
551 onProjectChange: setSelectedProjectKey,
552 }),
553 }}
554 sidebar={{
555 width: props.width,
556 visible: props.visible,
557 onRequestVisibility: props.onRequestVisibility,
558 }}
559 />
560 );
561 const showAddEnvironment =
562 !catalogState.isLoadingConnections &&
563 !catalogState.hasReadyEnvironment &&
564 !catalogState.hasConnectingEnvironment;
565 const listEmpty = (
566 <View>
567 <Text
568 className={
569 Platform.OS === "android"
570 ? "px-4 py-4 text-center text-sm text-drawer-foreground-muted"
571 : "px-2 py-4 text-sm text-drawer-foreground-muted"
572 }
573 >
574 {catalogState.isLoadingConnections
575 ? "Loading threads…"
576 : showAddEnvironment
577 ? "No environments connected"
578 : props.searchQuery.trim().length > 0
579 ? threadSearch.isPending
580 ? "Searching thread messages…"
581 : "No matching threads"
582 : selectedProjectScope !== null
583 ? `No threads in ${selectedProjectScope.title}`
584 : "No threads yet"}
585 </Text>
586 {showAddEnvironment ? (
587 <View className={Platform.OS === "android" ? "self-center" : "px-2"}>
588 <Button
589 tone="primary"
590 size="compact"
591 icon="plus"
592 label="Add environment"
593 onPress={props.onOpenEnvironmentSettings}
594 />
595 </View>
596 ) : null}
597 </View>
598 );
599
600 if (Platform.OS === "ios") {
601 return (
602 <>
603 {header}
604 <View className="flex-1">
605 <SwipeableScrollGateProvider enabled={swipeEnabled}>
606 <GestureDetector gesture={sidebarScrollGesture}>
607 <AnimatedLegendList
608 renderScrollComponent={NativeScrollView}
609 itemLayoutAnimation={THREAD_SIDEBAR_ROW_LAYOUT}
610 data={listItems}
611 drawDistance={500}
612 estimatedItemSize={64}
613 extraData={listExtraData}
614 getItemType={(item) => item.type}
615 itemsAreEqual={sidebarItemsAreEqual}
616 keyExtractor={(item) => item.key}
617 renderItem={renderListItem}
618 automaticallyAdjustsScrollIndicatorInsets
619 // The column lays the list under its bar, glass or solid; UIKit insets it past both.
620 contentInsetAdjustmentBehavior="automatic"
621 contentContainerStyle={[
622 styles.threadListContent,
623 {
624 paddingBottom: Math.max(insets.bottom, 16) + 16,
625 paddingTop: 6,
626 },
627 ]}
628 keyboardDismissMode="on-drag"
629 keyboardShouldPersistTaps="handled"
630 {...scrollGateHandlers}
631 recycleItems
632 scrollEventThrottle={16}
633 showsVerticalScrollIndicator={false}
634 style={styles.threadList}
635 ListEmptyComponent={listEmpty}
636 />
637 </GestureDetector>
638 </SwipeableScrollGateProvider>
639 <ThreadUndoNotice visible={props.visible} />
640 </View>
641 </>
642 );
643 }
644
645 // Android: the bar floats below the list.
646 return (
647 <View testID="thread-navigation-sidebar" className="flex-1 bg-header">
648 <View
649 className="flex-1"
650 style={{
651 marginHorizontal: 4,
652 paddingBottom: insets.bottom,
653 backgroundColor: drawerColor,
654 borderTopLeftRadius: 28,
655 borderTopRightRadius: 28,
656 overflow: "hidden",
657 }}
658 >
659 {listItems.length === 0 ? (
660 <View className="flex-1 items-center justify-center">{listEmpty}</View>
661 ) : (
662 <SwipeableScrollGateProvider enabled={swipeEnabled}>
663 <GestureDetector gesture={sidebarScrollGesture}>
664 {/* oxlint-disable-next-line t3code/require-registered-list-scroll -- The Android sidebar has no native header to register with. */}
665 <AnimatedLegendList
666 itemLayoutAnimation={THREAD_SIDEBAR_ROW_LAYOUT}
667 data={listItems}
668 drawDistance={500}
669 estimatedItemSize={64}
670 extraData={listExtraData}
671 getItemType={(item) => item.type}
672 itemsAreEqual={sidebarItemsAreEqual}
673 keyExtractor={(item) => item.key}
674 renderItem={renderListItem}
675 contentContainerStyle={{
676 paddingBottom: floatingTabsEnabled
677 ? FLOATING_TABS.bottom + FLOATING_TABS.edge + fabSize
678 : Math.max(insets.bottom, 16) + fabClearance - insets.bottom,
679 paddingTop: 6,
680 }}
681 keyboardDismissMode="on-drag"
682 keyboardShouldPersistTaps="handled"
683 {...scrollGateHandlers}
684 recycleItems
685 scrollEventThrottle={16}
686 showsVerticalScrollIndicator={false}
687 style={styles.threadList}
688 ListEmptyComponent={listEmpty}
689 />
690 </GestureDetector>
691 </SwipeableScrollGateProvider>
692 )}
693 </View>
694 {header}
695 <ThreadUndoNotice visible={props.visible} />
696 </View>
697 );
698}
699
700const styles = StyleSheet.create({
701 threadList: {
702 flex: 1,
703 },
704 threadListContent: {
705 paddingHorizontal: 8,
706 },
707});