Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CompactBrandTitle.tsx

124 lines3.4 KB

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;
30​
31/**
32 * Compact brand lockup sized for native navigation bars.
33 */
34export function CompactBrandTitle(
35 props: {
36 readonly nativeLeadingItem?: boolean;
37 } = {},
38) {
39 const iconColor = useThemeColor("--color-icon");
40 const mutedColor = useThemeColor("--color-foreground-muted");
41 const subtleColor = useThemeColor("--color-subtle");
42 const stageLabel = resolveMobileStageLabel(Constants.expoConfig?.extra?.appVariant);
43 const titleOffset = brandTitleOffset(props.nativeLeadingItem === true);
44​
45 return (
46 <View
47 aria-level={1}
48 accessibilityLabel="T3 Code, Threads"
49 accessible
50 role="heading"
51 style={{
52 alignItems: "center",
53 flexDirection: "row",
54 gap: 6,
55 marginLeft: titleOffset,
56 }}
57 >
58 <T3Wordmark color={iconColor} height={15} />
59 <Text
60 style={{
61 color: mutedColor,
62 fontFamily: "DMSans-Medium",
63 fontSize: 21,
64 letterSpacing: -0.5,
65 }}
66 >
67 Code
68 </Text>
69 <View
70 style={{
71 backgroundColor: subtleColor,
72 borderRadius: 999,
73 paddingHorizontal: 6,
74 paddingVertical: 2,
75 }}
76 >
77 <Text
78 style={{
79 color: mutedColor,
80 fontFamily: "DMSans-Bold",
81 fontSize: 9,
82 letterSpacing: 0.9,
83 textTransform: "uppercase",
84 }}
85 >
86 {stageLabel}
87 </Text>
88 </View>
89 </View>
90 );
92​
93export function renderCompactBrandTitle() {
94 return <CompactBrandTitle />;
96​
97export function renderCompactBrandHeaderItems(): NativeStackHeaderItem[] {
98 return [
99 {
100 element: <CompactBrandTitle nativeLeadingItem />,
101 hidesSharedBackground: true,
102 type: "custom",
103 },
104 ];
106​
107export function getCompactBrandHeaderOptions(
108 fallbackTitleStyle?: NativeStackNavigationOptions["headerTitleStyle"],
109): NativeStackNavigationOptions {
110 if (Platform.OS === "ios" && NATIVE_LIQUID_GLASS_SUPPORTED) {
111 return {
112 headerTitle: "Threads",
113 headerTitleStyle: { color: "transparent", fontSize: 18, fontWeight: "800" },
114 title: "Threads",
115 unstable_headerLeftItems: renderCompactBrandHeaderItems,
116 };
117 }
118​
119 return {
120 headerTitle: renderCompactBrandTitle,
121 headerTitleStyle: fallbackTitleStyle,
122 title: "Threads",
123 };