Open History to see the last commit
1import { NATIVE_WORKSPACE_COLUMNS_SUPPORTED } from "../native/NativeWorkspaceColumns";
2import Constants from "expo-constants";
3import type { NativeStackNavigationOptions } from "@react-navigation/native-stack";
4import { useState } from "react";
5import { Platform, View } from "react-native";
6
7import { AppText as Text } from "./ui/AppText";
8import { T3Wordmark } from "./T3Wordmark";
9import { IPAD_HOME_TITLE_OFFSET } from "../lib/layoutMetrics";
10import { resolveMobileStageLabel } from "../lib/mobileBranding";
11import { useAndroidControlSizing } from "./ui/useAndroidControlSizing";
12
13const BRAND_MAX_FONT_SCALE = 1.4;
14
15export function brandTitleOffset(): number {
16 if (Platform.OS !== "ios") return 0;
17 return Platform.isPad && !NATIVE_WORKSPACE_COLUMNS_SUPPORTED ? IPAD_HOME_TITLE_OFFSET : 0;
18}
19
20export function CompactBrandTitle(
21 props: {
22 readonly allowFontScaling?: boolean;
23 readonly accessibilityLabel?: string;
24 /** Fills the row and hides the stage badge when the full title does not fit. */
25 readonly fit?: boolean;
26 } = {},
27) {
28 const stageLabel = resolveMobileStageLabel(Constants.expoConfig?.extra?.appVariant);
29 const titleOffset = brandTitleOffset();
30 const { scale } = useAndroidControlSizing();
31 const [availableWidth, setAvailableWidth] = useState<number | null>(null);
32 // Measured only while the badge shows, so hiding it does not make it look like it fits.
33 const [fullWidth, setFullWidth] = useState<number | null>(null);
34 const showStage =
35 !props.fit || availableWidth === null || fullWidth === null || fullWidth <= availableWidth;
36
37 const title = (
38 <View
39 onLayout={
40 props.fit && showStage ? (event) => setFullWidth(event.nativeEvent.layout.width) : undefined
41 }
42 aria-level={1}
43 accessibilityLabel={props.accessibilityLabel ?? "T3 Code, Threads"}
44 accessible
45 role="heading"
46 className="flex-row items-center gap-1.5"
47 style={[
48 { marginLeft: titleOffset },
49 Platform.OS === "android" && { gap: 5.25 * scale },
50 props.fit && { flexShrink: 0 },
51 ]}
52 >
53 <T3Wordmark colorClassName="accent-icon" height={Math.round(15 * scale)} />
54 {/* A logo beside a fixed-size wordmark: it may grow with Dynamic Type, not crowd the bar. */}
55 <Text
56 allowFontScaling={props.allowFontScaling}
57 maxFontSizeMultiplier={BRAND_MAX_FONT_SCALE}
58 className="font-t3-medium text-foreground-muted"
59 style={{ fontSize: 21 * scale, letterSpacing: -0.5 * scale }}
60 >
61 Code
62 </Text>
63 {showStage ? (
64 <View
65 className="rounded-full bg-subtle px-1.5 py-0.5"
66 style={
67 Platform.OS === "android"
68 ? { paddingHorizontal: 5.25 * scale, paddingVertical: 1.75 * scale }
69 : undefined
70 }
71 >
72 <Text
73 allowFontScaling={props.allowFontScaling}
74 maxFontSizeMultiplier={BRAND_MAX_FONT_SCALE}
75 className="font-t3-bold text-foreground-muted uppercase"
76 style={{ fontSize: 9 * scale, letterSpacing: 0.9 * scale }}
77 >
78 {stageLabel}
79 </Text>
80 </View>
81 ) : null}
82 </View>
83 );
84
85 return props.fit ? (
86 <View
87 className="min-w-0 flex-1 flex-row items-center"
88 onLayout={(event) => setAvailableWidth(event.nativeEvent.layout.width)}
89 >
90 {title}
91 </View>
92 ) : (
93 title
94 );
95}
96
97function renderCompactBrandTitle() {
98 return <CompactBrandTitle allowFontScaling={Platform.OS === "ios"} />;
99}
100
101export function getCompactBrandHeaderOptions(
102 fallbackTitleStyle?: NativeStackNavigationOptions["headerTitleStyle"],
103): NativeStackNavigationOptions {
104 return {
105 headerTitle: renderCompactBrandTitle,
106 headerTitleStyle: fallbackTitleStyle,
107 title: "Threads",
108 unstable_headerLeftItems: undefined,
109 };
110}