The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePreferencesProvider"; |
| 2 | import { useState } from "react"; |
| 3 | import { useKeyboardState } from "react-native-keyboard-controller"; |
| 4 | import { Platform, View } from "react-native"; |
| 5 | import { useGT } from "gt-react-native"; |
| 6 | import { useSafeAreaInsets } from "react-native-safe-area-context"; |
| 7 | import { Toast } from "../../components/ui/Toast"; |
| 8 | import { |
| 9 | useDeviceType, |
| 10 | useDuoBottomBarInset, |
| 11 | useNativeLayoutMetrics, |
| 12 | useNativeColumnLayoutMetrics, |
| 13 | } from "../../native/native-layout-metrics"; |
| 14 | import { workspaceSearchBottomClearance } from "../layout/workspace/workspace-tabs-state"; |
| 15 | import { useWorkspaceTabs } from "../layout/workspace/WorkspaceTabsContext"; |
| 16 | import { |
| 17 | dismissThreadUndoNotice, |
| 18 | readThreadUndoNotice, |
| 19 | useThreadUndoNotice, |
| 20 | } from "./thread-undo-notice"; |
| 21 | |
| 22 | export function ThreadUndoNotice(props: { readonly visible: boolean }) { |
| 23 | const gt = useGT(); |
| 24 | const floatingTabsEnabled = useAndroidFloatingTabs(); |
| 25 | const notice = useThreadUndoNotice(); |
| 26 | const insets = useSafeAreaInsets(); |
| 27 | const columnMetrics = useNativeColumnLayoutMetrics(); |
| 28 | const rootMetrics = useNativeLayoutMetrics(); |
| 29 | const workspace = useWorkspaceTabs(); |
| 30 | const deviceType = useDeviceType(); |
| 31 | const keyboardHeight = useKeyboardState((keyboard) => keyboard.height); |
| 32 | const horizontalInsets = |
| 33 | Platform.OS === "ios" |
| 34 | ? deviceType === "phone" |
| 35 | ? { left: 29, right: 23 } |
| 36 | : { left: 20, right: 20 } |
| 37 | : { left: 12, right: 12 }; |
| 38 | // The Duo's native tab pill extends above the 48-point toolbar reservation. |
| 39 | const workspacePadding = |
| 40 | useDuoBottomBarInset() === undefined |
| 41 | ? deviceType === "phone" && keyboardHeight === 0 |
| 42 | ? 32 |
| 43 | : 16 |
| 44 | : 8; |
| 45 | // Replacing a notice must also cancel the native gesture tracking the old one. |
| 46 | const [instance, setInstance] = useState({ notice, key: 0 }); |
| 47 | if (instance.notice !== notice) setInstance({ notice, key: instance.key + 1 }); |
| 48 | if (!props.visible || notice === null) return null; |
| 49 | const foldedResting = |
| 50 | rootMetrics?.hasHinge && |
| 51 | rootMetrics.horizontalSizeClass === "compact" && |
| 52 | workspace?.state.tabs.threads.searchMode === "resting"; |
| 53 | const bottom = |
| 54 | Platform.OS === "ios" |
| 55 | ? foldedResting |
| 56 | ? // Sit level with the rail's tab pill, which floats inside the bottom safe area. |
| 57 | Math.max( |
| 58 | rootMetrics.bottomBarInset ?? rootMetrics.safeArea.bottom + 8, |
| 59 | keyboardHeight + 8, |
| 60 | ) |
| 61 | : rootMetrics?.hasHinge && rootMetrics.verticalBarEdge !== "none" |
| 62 | ? // The column's safe area already includes UIKit's search toolbar in this posture. |
| 63 | workspaceSearchBottomClearance({ |
| 64 | bottomInset: rootMetrics.safeArea.bottom, |
| 65 | bottomBarInset: rootMetrics.bottomBarInset, |
| 66 | keyboardHeight, |
| 67 | }) - |
| 68 | 16 + |
| 69 | 8 |
| 70 | : Math.max( |
| 71 | insets.bottom, |
| 72 | columnMetrics?.safeArea.bottom ?? 0, |
| 73 | (workspace?.bottomClearance ?? 0) - workspacePadding, |
| 74 | ) + 8 |
| 75 | : floatingTabsEnabled && keyboardHeight === 0 |
| 76 | ? Math.max(insets.bottom + 12, workspace?.bottomClearance ?? 0) |
| 77 | : insets.bottom + 12; |
| 78 | return ( |
| 79 | <View |
| 80 | key={instance.key} |
| 81 | collapsable={false} |
| 82 | className="absolute z-[100]" |
| 83 | style={{ bottom, ...horizontalInsets }} |
| 84 | pointerEvents="box-none" |
| 85 | > |
| 86 | <Toast |
| 87 | message={ |
| 88 | notice.action === "Settled" |
| 89 | ? gt("Settled thread") |
| 90 | : notice.action === "Snoozed" |
| 91 | ? gt("Snoozed thread") |
| 92 | : gt("Unpinned thread") |
| 93 | } |
| 94 | action={{ |
| 95 | label: gt("Undo"), |
| 96 | onPress: () => { |
| 97 | void notice.undo(); |
| 98 | }, |
| 99 | }} |
| 100 | dismissMode="swipe" |
| 101 | onDismiss={() => { |
| 102 | // A newer action can replace the notice while the swipe is animating out. |
| 103 | if (readThreadUndoNotice() === notice) dismissThreadUndoNotice(); |
| 104 | }} |
| 105 | /> |
| 106 | </View> |
| 107 | ); |
| 108 | } |