Open History to see the last commit
1import Constants from "expo-constants";
2import type {
3 NativeStackHeaderItem,
4 NativeStackNavigationOptions,
5} from "@react-navigation/native-stack";
6import { Platform, View } from "react-native";
7
8import { AppText as Text } from "./AppText";
9import { T3Wordmark } from "./T3Wordmark";
10import { IPAD_HOME_TITLE_OFFSET } from "../lib/layoutMetrics";
11import { resolveMobileStageLabel } from "../lib/mobileBranding";
12import { useThemeColor } from "../lib/useThemeColor";
13import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../native/native-glass";
14
15// Native leading items inherit different UIKit margins than title views.
16const IOS_NATIVE_LEADING_TITLE_OFFSET = -6;
17const IPAD_NATIVE_LEADING_TITLE_OFFSET = 7;
18
19/**
20 * Horizontal correction applied to content rendered in the brand title slot,
21 * shared with the connection-status swap so both align identically.
22 */
23export function brandTitleOffset(nativeLeadingItem: boolean): number {
24 if (Platform.OS !== "ios") return 0;
25 if (nativeLeadingItem) {
26 return Platform.isPad ? IPAD_NATIVE_LEADING_TITLE_OFFSET : IOS_NATIVE_LEADING_TITLE_OFFSET;
27 }
28 return Platform.isPad ? IPAD_HOME_TITLE_OFFSET : 0;
29}
30
31/**
32 * Compact brand lockup sized for native navigation bars.
33 */
34export function CompactBrandTitle(
35 props: {
36 readonly allowFontScaling?: boolean;
37 readonly nativeLeadingItem?: boolean;
38 } = {},
39) {
40 const iconColor = useThemeColor("--color-icon");
41 const mutedColor = useThemeColor("--color-foreground-muted");
42 const subtleColor = useThemeColor("--color-subtle");
43 const stageLabel = resolveMobileStageLabel(Constants.expoConfig?.extra?.appVariant);
44 const titleOffset = brandTitleOffset(props.nativeLeadingItem === true);
45
46 return (
47 <View
48 aria-level={1}
49 accessibilityLabel="T3 Code, Threads"
50 accessible
51 role="heading"
52 style={{
53 alignItems: "center",
54 flexDirection: "row",
55 gap: 6,
56 marginLeft: titleOffset,
57 }}
58 >
59 <T3Wordmark color={iconColor} height={15} />
60 <Text
61 allowFontScaling={props.allowFontScaling}
62 style={{
63 color: mutedColor,
64 fontFamily: "DMSans-Medium",
65 fontSize: 21,
66 letterSpacing: -0.5,
67 }}
68 >
69 Code
70 </Text>
71 <View
72 style={{
73 backgroundColor: subtleColor,
74 borderRadius: 999,
75 paddingHorizontal: 6,
76 paddingVertical: 2,
77 }}
78 >
79 <Text
80 allowFontScaling={props.allowFontScaling}
81 style={{
82 color: mutedColor,
83 fontFamily: "DMSans-Bold",
84 fontSize: 9,
85 letterSpacing: 0.9,
86 textTransform: "uppercase",
87 }}
88 >
89 {stageLabel}
90 </Text>
91 </View>
92 </View>
93 );
94}
95
96export function renderCompactBrandTitle() {
97 return <CompactBrandTitle allowFontScaling={Platform.OS === "ios"} />;
98}
99
100export function renderCompactBrandHeaderItems(): NativeStackHeaderItem[] {
101 return [
102 {
103 element: <CompactBrandTitle nativeLeadingItem />,
104 hidesSharedBackground: true,
105 type: "custom",
106 },
107 ];
108}
109
110export function getCompactBrandHeaderOptions(
111 fallbackTitleStyle?: NativeStackNavigationOptions["headerTitleStyle"],
112): NativeStackNavigationOptions {
113 if (Platform.OS === "ios" && NATIVE_LIQUID_GLASS_SUPPORTED) {
114 return {
115 headerTitle: "Threads",
116 headerTitleStyle: { color: "transparent", fontSize: 18, fontWeight: "800" },
117 title: "Threads",
118 unstable_headerLeftItems: renderCompactBrandHeaderItems,
119 };
120 }
121
122 return {
123 headerTitle: renderCompactBrandTitle,
124 headerTitleStyle: fallbackTitleStyle,
125 title: "Threads",
126 };
127}