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

CompactBrandTitle.tsx

83 lines2.7 KB

1import { NATIVE_WORKSPACE_COLUMNS_SUPPORTED } from "../native/NativeWorkspaceColumns";
2import Constants from "expo-constants";
3import type { NativeStackNavigationOptions } from "@react-navigation/native-stack";
4import { Platform, View } from "react-native";
5​
6import { AppText as Text } from "./AppText";
7import { T3Wordmark } from "./T3Wordmark";
8import { IPAD_HOME_TITLE_OFFSET } from "../lib/layoutMetrics";
9import { resolveMobileStageLabel } from "../lib/mobileBranding";
10import { useAndroidControlSizing } from "./useAndroidControlSizing";
11​
12/**
13 * Horizontal correction applied to content rendered in the brand title slot,
14 * shared with the connection-status swap so both align identically.
15 */
16export function brandTitleOffset(): number {
17 if (Platform.OS !== "ios") return 0;
18 return Platform.isPad && !NATIVE_WORKSPACE_COLUMNS_SUPPORTED ? IPAD_HOME_TITLE_OFFSET : 0;
20​
21/**
22 * Compact brand lockup sized for native navigation bars.
23 */
24export function CompactBrandTitle(
25 props: {
26 readonly allowFontScaling?: boolean;
27 } = {},
28) {
29 const stageLabel = resolveMobileStageLabel(Constants.expoConfig?.extra?.appVariant);
30 const titleOffset = brandTitleOffset();
31 const { scale } = useAndroidControlSizing();
32​
33 return (
34 <View
35 aria-level={1}
36 accessibilityLabel="T3 Code, Threads"
37 accessible
38 role="heading"
39 className="flex-row items-center gap-1.5"
40 style={[{ marginLeft: titleOffset }, Platform.OS === "android" && { gap: 5.25 * scale }]}
41 >
42 <T3Wordmark colorClassName="accent-icon" height={Math.round(15 * scale)} />
43 <Text
44 allowFontScaling={props.allowFontScaling}
45 className="font-t3-medium text-foreground-muted"
46 style={{ fontSize: 21 * scale, letterSpacing: -0.5 * scale }}
47 >
48 Code
49 </Text>
50 <View
51 className="rounded-full bg-subtle px-1.5 py-0.5"
52 style={
53 Platform.OS === "android"
54 ? { paddingHorizontal: 5.25 * scale, paddingVertical: 1.75 * scale }
55 : undefined
56 }
57 >
58 <Text
59 allowFontScaling={props.allowFontScaling}
60 className="font-t3-bold text-foreground-muted uppercase"
61 style={{ fontSize: 9 * scale, letterSpacing: 0.9 * scale }}
62 >
63 {stageLabel}
64 </Text>
65 </View>
66 </View>
67 );
69​
70export function renderCompactBrandTitle() {
71 return <CompactBrandTitle allowFontScaling={Platform.OS === "ios"} />;
73​
74export function getCompactBrandHeaderOptions(
75 fallbackTitleStyle?: NativeStackNavigationOptions["headerTitleStyle"],
76): NativeStackNavigationOptions {
77 return {
78 headerTitle: renderCompactBrandTitle,
79 headerTitleStyle: fallbackTitleStyle,
80 title: "Threads",
81 unstable_headerLeftItems: undefined,
82 };