The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { AppActivityIndicator } from "./AppActivityIndicator"; |
| 2 | import { Column, Text as NativeText, RNHostView } from "@expo/ui/jetpack-compose"; |
| 3 | import { useGT } from "gt-react-native"; |
| 4 | import { use, useState, type ReactNode } from "react"; |
| 5 | import { View } from "react-native"; |
| 6 | |
| 7 | import type { AppSymbolName } from "./AppSymbol"; |
| 8 | import { NativeAppBar } from "./NativeAppBar.android"; |
| 9 | import { IconButton } from "./IconButton"; |
| 10 | import { AndroidAnchoredMenu } from "./AndroidAnchoredMenu.android"; |
| 11 | import { splitAndroidHeaderActions } from "./headerMenu.android"; |
| 12 | import { useScaledTextRole } from "../../features/settings/appearance/useScaledTextRole"; |
| 13 | import { useToolbarLayout } from "./useToolbarLayout"; |
| 14 | import { useControlTheme } from "./useControlTheme"; |
| 15 | import { RoutedFormSheetContext } from "./RoutedFormSheetContext"; |
| 16 | |
| 17 | export interface AndroidHeaderAction { |
| 18 | readonly accessibilityLabel: string; |
| 19 | readonly icon: AppSymbolName; |
| 20 | readonly onPress: () => void; |
| 21 | readonly disabled?: boolean; |
| 22 | readonly loading?: boolean; |
| 23 | readonly selected?: boolean; |
| 24 | readonly subtitle?: string; |
| 25 | readonly destructive?: boolean; |
| 26 | readonly overflowOnly?: boolean; |
| 27 | } |
| 28 | |
| 29 | export function AndroidHeaderIconButton(props: { |
| 30 | readonly accessibilityLabel: string; |
| 31 | readonly icon: AppSymbolName; |
| 32 | readonly onPress?: () => void; |
| 33 | readonly disabled?: boolean; |
| 34 | readonly selected?: boolean; |
| 35 | }) { |
| 36 | return <IconButton {...props} tintColorClassName="accent-header-foreground" />; |
| 37 | } |
| 38 | |
| 39 | export function AndroidScreenHeader(props: { |
| 40 | readonly title: string; |
| 41 | readonly titleContent?: ReactNode; |
| 42 | readonly subtitle?: string | null; |
| 43 | readonly actions?: ReadonlyArray<AndroidHeaderAction>; |
| 44 | readonly leading?: ReactNode; |
| 45 | readonly trailing?: ReactNode; |
| 46 | readonly onBack?: () => void; |
| 47 | readonly embedded?: boolean; |
| 48 | readonly hideBottomBorder?: boolean; |
| 49 | }) { |
| 50 | const gt = useGT(); |
| 51 | const { colors } = useControlTheme(); |
| 52 | const titleTypography = useScaledTextRole("title"); |
| 53 | const subtitleTypography = useScaledTextRole("label"); |
| 54 | const inFormSheet = use(RoutedFormSheetContext); |
| 55 | const { paddingTop, paddingBottom } = useToolbarLayout(props.embedded || inFormSheet); |
| 56 | const [headerWidth, setHeaderWidth] = useState(0); |
| 57 | const { visibleActions, overflowActions } = splitAndroidHeaderActions( |
| 58 | props.actions ?? [], |
| 59 | headerWidth >= 600, |
| 60 | ); |
| 61 | |
| 62 | return ( |
| 63 | <View |
| 64 | onLayout={(event) => setHeaderWidth(event.nativeEvent.layout.width)} |
| 65 | className="border-b border-header-border bg-header" |
| 66 | style={{ |
| 67 | paddingTop, |
| 68 | paddingBottom, |
| 69 | borderBottomWidth: props.hideBottomBorder ? 0 : undefined, |
| 70 | }} |
| 71 | > |
| 72 | {inFormSheet ? ( |
| 73 | <View |
| 74 | pointerEvents="none" |
| 75 | className="absolute top-1 h-1 w-8 self-center rounded-full bg-header-foreground/40" |
| 76 | /> |
| 77 | ) : null} |
| 78 | <NativeAppBar |
| 79 | navigationIcon={ |
| 80 | props.onBack || props.leading ? ( |
| 81 | <View collapsable={false} className="flex-row items-center"> |
| 82 | {props.onBack ? ( |
| 83 | <IconButton |
| 84 | accessibilityLabel={gt("Navigate up")} |
| 85 | icon="arrow.left" |
| 86 | tintColorClassName="accent-header-foreground" |
| 87 | onPress={props.onBack} |
| 88 | /> |
| 89 | ) : null} |
| 90 | |
| 91 | {props.leading} |
| 92 | </View> |
| 93 | ) : undefined |
| 94 | } |
| 95 | title={ |
| 96 | props.titleContent ? ( |
| 97 | <RNHostView matchContents={{ vertical: true }}> |
| 98 | <View collapsable={false}>{props.titleContent}</View> |
| 99 | </RNHostView> |
| 100 | ) : !props.subtitle ? ( |
| 101 | <NativeText |
| 102 | color={colors["--color-header-foreground"]} |
| 103 | maxLines={1} |
| 104 | overflow="ellipsis" |
| 105 | style={titleTypography} |
| 106 | > |
| 107 | {props.title} |
| 108 | </NativeText> |
| 109 | ) : ( |
| 110 | <Column> |
| 111 | <NativeText |
| 112 | color={colors["--color-header-foreground"]} |
| 113 | maxLines={1} |
| 114 | overflow="ellipsis" |
| 115 | style={titleTypography} |
| 116 | > |
| 117 | {props.title} |
| 118 | </NativeText> |
| 119 | {props.subtitle ? ( |
| 120 | <NativeText |
| 121 | color={colors["--color-foreground-muted"]} |
| 122 | maxLines={1} |
| 123 | overflow="ellipsis" |
| 124 | style={subtitleTypography} |
| 125 | > |
| 126 | {props.subtitle} |
| 127 | </NativeText> |
| 128 | ) : null} |
| 129 | </Column> |
| 130 | ) |
| 131 | } |
| 132 | actions={ |
| 133 | visibleActions.length > 0 || overflowActions.length > 0 || props.trailing ? ( |
| 134 | <View collapsable={false} className="flex-row items-center"> |
| 135 | {visibleActions.map((action) => |
| 136 | action.loading ? ( |
| 137 | <View |
| 138 | key={action.accessibilityLabel} |
| 139 | accessibilityLabel={action.accessibilityLabel} |
| 140 | className="size-12 items-center justify-center" |
| 141 | > |
| 142 | <AppActivityIndicator colorClassName="accent-header-foreground" /> |
| 143 | </View> |
| 144 | ) : ( |
| 145 | <AndroidHeaderIconButton |
| 146 | key={action.accessibilityLabel} |
| 147 | accessibilityLabel={action.accessibilityLabel} |
| 148 | disabled={action.disabled} |
| 149 | selected={action.selected} |
| 150 | icon={action.icon} |
| 151 | onPress={action.onPress} |
| 152 | /> |
| 153 | ), |
| 154 | )} |
| 155 | {overflowActions.length > 0 ? ( |
| 156 | <AndroidAnchoredMenu |
| 157 | actions={overflowActions.map((action, index) => ({ |
| 158 | id: String(index), |
| 159 | title: action.accessibilityLabel, |
| 160 | subtitle: action.subtitle, |
| 161 | state: action.selected ? "on" : undefined, |
| 162 | attributes: { |
| 163 | disabled: Boolean(action.disabled), |
| 164 | destructive: action.destructive, |
| 165 | }, |
| 166 | }))} |
| 167 | onPressAction={({ nativeEvent }) => |
| 168 | overflowActions[Number(nativeEvent.event)]?.onPress() |
| 169 | } |
| 170 | > |
| 171 | {(open) => ( |
| 172 | <IconButton |
| 173 | accessibilityLabel={gt("More actions")} |
| 174 | icon="ellipsis" |
| 175 | tintColorClassName="accent-header-foreground" |
| 176 | onPress={open} |
| 177 | /> |
| 178 | )} |
| 179 | </AndroidAnchoredMenu> |
| 180 | ) : null} |
| 181 | {props.trailing} |
| 182 | </View> |
| 183 | ) : undefined |
| 184 | } |
| 185 | /> |
| 186 | </View> |
| 187 | ); |
| 188 | } |