@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

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