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