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

CompactBrandTitle.tsx

101 lines3.1 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 { NATIVE_LIQUID_GLASS_SUPPORTED } from "../native/native-glass";
13​
14// Native leading items inherit different UIKit margins than title views.
15const IOS_NATIVE_LEADING_TITLE_OFFSET = -6;
16const IPAD_NATIVE_LEADING_TITLE_OFFSET = 7;
17​
18/**
19 * Horizontal correction applied to content rendered in the brand title slot,
20 * shared with the connection-status swap so both align identically.
21 */
22export function brandTitleOffset(nativeLeadingItem: boolean): number {
23 if (Platform.OS !== "ios") return 0;
24 if (nativeLeadingItem) {
25 return Platform.isPad ? IPAD_NATIVE_LEADING_TITLE_OFFSET : IOS_NATIVE_LEADING_TITLE_OFFSET;
26 }
27 return Platform.isPad ? IPAD_HOME_TITLE_OFFSET : 0;
29​
30/**
31 * Compact brand lockup sized for native navigation bars.
32 */
33export function CompactBrandTitle(
34 props: {
35 readonly allowFontScaling?: boolean;
36 readonly nativeLeadingItem?: boolean;
37 } = {},
38) {
39 const stageLabel = resolveMobileStageLabel(Constants.expoConfig?.extra?.appVariant);
40 const titleOffset = brandTitleOffset(props.nativeLeadingItem === true);
41​
42 return (
43 <View
44 aria-level={1}
45 accessibilityLabel="T3 Code, Threads"
46 accessible
47 role="heading"
48 className="flex-row items-center gap-1.5"
49 style={{ marginLeft: titleOffset }}
50 >
51 <T3Wordmark colorClassName="accent-icon" height={15} />
52 <Text
53 allowFontScaling={props.allowFontScaling}
54 className="font-t3-medium text-[21px] tracking-[-0.5px] text-foreground-muted"
55 >
56 Code
57 </Text>
58 <View className="rounded-full bg-subtle px-1.5 py-0.5">
59 <Text
60 allowFontScaling={props.allowFontScaling}
61 className="font-t3-bold text-[9px] tracking-[0.9px] text-foreground-muted uppercase"
62 >
63 {stageLabel}
64 </Text>
65 </View>
66 </View>
67 );
69​
70export function renderCompactBrandTitle() {
71 return <CompactBrandTitle allowFontScaling={Platform.OS === "ios"} />;
73​
74export function renderCompactBrandHeaderItems(): NativeStackHeaderItem[] {
75 return [
76 {
77 element: <CompactBrandTitle nativeLeadingItem />,
78 hidesSharedBackground: true,
79 type: "custom",
80 },
81 ];
83​
84export function getCompactBrandHeaderOptions(
85 fallbackTitleStyle?: NativeStackNavigationOptions["headerTitleStyle"],
86): NativeStackNavigationOptions {
87 if (Platform.OS === "ios" && NATIVE_LIQUID_GLASS_SUPPORTED) {
88 return {
89 headerTitle: "Threads",
90 headerTitleStyle: { color: "transparent", fontSize: 18, fontWeight: "800" },
91 title: "Threads",
92 unstable_headerLeftItems: renderCompactBrandHeaderItems,
93 };
94 }
95​
96 return {
97 headerTitle: renderCompactBrandTitle,
98 headerTitleStyle: fallbackTitleStyle,
99 title: "Threads",
100 };