Open History to see the last commit
1import type { ReactNode } from "react";
2import { Pressable, View } from "react-native";
3import { useSafeAreaInsets } from "react-native-safe-area-context";
4
5import { SymbolView, type AppSymbolName } from "./AppSymbol";
6import { AppText as Text } from "./AppText";
7import { cn } from "../lib/cn";
8
9export interface AndroidHeaderAction {
10 readonly accessibilityLabel: string;
11 readonly icon: AppSymbolName;
12 readonly onPress: () => void;
13 readonly disabled?: boolean;
14}
15
16export function AndroidHeaderIconButton(props: {
17 readonly accessibilityLabel: string;
18 readonly icon: AppSymbolName;
19 readonly onPress?: () => void;
20 readonly disabled?: boolean;
21}) {
22 return (
23 <Pressable
24 accessibilityLabel={props.accessibilityLabel}
25 accessibilityRole="button"
26 disabled={props.disabled}
27 hitSlop={8}
28 onPress={props.onPress}
29 className={cn(
30 "size-11 items-center justify-center rounded-full bg-subtle",
31 props.disabled && "opacity-55",
32 )}
33 >
34 <SymbolView
35 name={props.icon}
36 size={20}
37 tintColorClassName={props.disabled ? "accent-icon-subtle" : "accent-foreground"}
38 type="monochrome"
39 />
40 </Pressable>
41 );
42}
43
44export function AndroidScreenHeader(props: {
45 readonly title: string;
46 readonly subtitle?: string | null;
47 readonly actions?: ReadonlyArray<AndroidHeaderAction>;
48 readonly trailing?: ReactNode;
49 readonly onBack?: () => void;
50 readonly embedded?: boolean;
51}) {
52 const insets = useSafeAreaInsets();
53
54 return (
55 <View
56 className="border-b border-header-border bg-header px-3 pb-2.5"
57 style={{
58 paddingTop: props.embedded ? 8 : Math.max(insets.top, 12),
59 }}
60 >
61 <View className="min-h-12 flex-row items-center gap-2">
62 {props.onBack ? (
63 <Pressable
64 accessibilityLabel="Navigate up"
65 accessibilityRole="button"
66 hitSlop={8}
67 onPress={props.onBack}
68 className="-mr-2 size-11 items-center justify-center"
69 >
70 <SymbolView
71 name="chevron.left"
72 size={24}
73 tintColorClassName={"accent-foreground"}
74 type="monochrome"
75 />
76 </Pressable>
77 ) : null}
78
79 <View className={cn("min-w-0 flex-1", !props.onBack && "pl-1")}>
80 <Text numberOfLines={1} className="text-lg font-t3-bold text-foreground">
81 {props.title}
82 </Text>
83 {props.subtitle ? (
84 <Text
85 numberOfLines={1}
86 className="mt-px text-[13px] font-t3-medium text-foreground-muted"
87 >
88 {props.subtitle}
89 </Text>
90 ) : null}
91 </View>
92
93 {props.actions?.map((action) => (
94 <AndroidHeaderIconButton
95 key={action.accessibilityLabel}
96 accessibilityLabel={action.accessibilityLabel}
97 disabled={action.disabled}
98 icon={action.icon}
99 onPress={action.onPress}
100 />
101 ))}
102 {props.trailing}
103 </View>
104 </View>
105 );
106}
107
108export function AndroidSheetHeader(
109 props: Omit<Parameters<typeof AndroidScreenHeader>[0], "embedded">,
110) {
111 return <AndroidScreenHeader {...props} embedded />;
112}