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 22, 15:45 UTC
fix(mobile): keep segmented controls readable on cards and screens (#25729)
Alex committed
Oct 26, 2026 at 22:16 UTC
e689dad42c842d03f311ee0a7c29db25896abd6a
10 files changed
+183
-100
apps/mobile/src/components/ui/SegmentedControl.ios.tsx
+12
-20
@@ -1,11 +1,8 @@
1
import { requireNativeView } from "expo";
2
import { View, type NativeSyntheticEvent, type ViewProps } from "react-native";
3
4
-import {
5
- flattenThemeColor,
6
- themeColorWithAlpha,
7
- themeColorWithContrast,
8
-} from "../../lib/mobileTheme";
4
+import { SegmentedControl as FlatSegmentedControl } from "./SegmentedControl.shared";
5
+import { segmentedControlColors } from "./segmentedControlColors";
6
import { useControlTheme } from "./useControlTheme";
7
import type { SegmentedControlProps } from "./SegmentedControl.types";
8
@@ -27,17 +24,16 @@ const NativeSegmentedControl = requireNativeView<
24
export function SegmentedControl<Value extends string | number>(
25
props: SegmentedControlProps<Value>,
26
) {
30
- const { colors, colorScheme } = useControlTheme();
31
- const trackColor = flattenThemeColor(
32
- themeColorWithAlpha(colors["--color-prominent-action"], colorScheme === "dark" ? 0.18 : 0.07),
33
- colors["--color-screen"],
27
+ const { colors, colorScheme, themeId } = useControlTheme();
28
+ // UIKit adds a gray fill over the sunken card track.
29
+ if (props.variant === "card") return <FlatSegmentedControl {...props} />;
30
+ const { trackColor, selectedColor, selectedTextColor, mutedColor } = segmentedControlColors(
31
+ colors,
32
+ colorScheme,
33
+ props.variant,
34
+ "ios",
35
+ themeId,
36
);
35
- const selectedColor =
36
- colorScheme === "dark" ? colors["--color-prominent-action"] : colors["--color-secondary"];
37
- const selectedTextColor =
38
- colorScheme === "dark"
39
- ? colors["--color-prominent-action-foreground"]
40
- : colors["--color-secondary-foreground"];
37
return (
38
<View className={props.className}>
39
<NativeSegmentedControl
@@ -46,11 +42,7 @@ export function SegmentedControl<Value extends string | number>(
42
trackColor={trackColor}
43
selectedColor={selectedColor}
44
textColor={selectedTextColor}
49
- mutedColor={themeColorWithContrast(
50
- colors["--color-foreground-muted"],
51
- trackColor,
52
- colorScheme === "dark" ? 7 : 4.5,
53
- )}
45
+ mutedColor={mutedColor}
46
appearance={colorScheme}
47
onSelectionChange={({ nativeEvent }) => {
48
const option = props.options[nativeEvent.index];
apps/mobile/src/components/ui/SegmentedControl.shared.tsx
new
+84
@@ -0,0 +1,84 @@
1
+import { useState } from "react";
2
+import { I18nManager, Platform, Pressable, View } from "react-native";
3
+import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated";
4
+
5
+import { segmentedControlColors } from "./segmentedControlColors";
6
+import { AppText } from "./AppText";
7
+import { useControlTheme } from "./useControlTheme";
8
+import type { SegmentedControlProps } from "./SegmentedControl.types";
9
+
10
+export type { SegmentedControlProps } from "./SegmentedControl.types";
11
+
12
+export function SegmentedControl<Value extends string | number>(
13
+ props: SegmentedControlProps<Value>,
14
+) {
15
+ const { colorScheme, colors, themeId } = useControlTheme();
16
+ const [layout, setLayout] = useState({ width: 0, height: 0 });
17
+ const { width } = layout;
18
+ const reduceMotion = useReducedMotion();
19
+ const selectedIndex = props.options.findIndex((option) => option.value === props.selected);
20
+ const segmentWidth = props.options.length ? Math.max(0, width - 6) / props.options.length : 0;
21
+ const selectionOffset = selectedIndex * segmentWidth * (I18nManager.isRTL ? -1 : 1);
22
+ const selectionStyle = useAnimatedStyle(() => ({
23
+ width: segmentWidth,
24
+ transform: [{ translateX: withTiming(selectionOffset, { duration: reduceMotion ? 0 : 160 }) }],
25
+ }));
26
+ const { trackColor, selectedColor, selectedTextColor, mutedColor } = segmentedControlColors(
27
+ colors,
28
+ colorScheme,
29
+ props.variant,
30
+ Platform.OS,
31
+ themeId,
32
+ );
33
+ const minHeight = props.size === "compact" ? 32 : Platform.OS === "android" ? 40 : 36;
34
+
35
+ return (
36
+ <View collapsable={false} className={props.className}>
37
+ <View
38
+ onLayout={(event) => setLayout(event.nativeEvent.layout)}
39
+ className="flex-row rounded-full p-[3px]"
40
+ style={{
41
+ minHeight,
42
+ backgroundColor: trackColor,
43
+ }}
44
+ >
45
+ {selectedIndex >= 0 && width > 0 ? (
46
+ <Animated.View
47
+ pointerEvents="none"
48
+ className="absolute bottom-[3px] start-[3px] top-[3px] rounded-full"
49
+ style={[
50
+ {
51
+ backgroundColor: selectedColor,
52
+ },
53
+ selectionStyle,
54
+ ]}
55
+ />
56
+ ) : null}
57
+ {props.options.map((option) => {
58
+ const selected = option.value === props.selected;
59
+ return (
60
+ <Pressable
61
+ key={`${typeof option.value}:${option.value}`}
62
+ accessibilityRole={props.role ?? "button"}
63
+ accessibilityLabel={option.accessibilityLabel ?? option.label}
64
+ accessibilityState={{ selected }}
65
+ onPress={() => props.onSelect(option.value)}
66
+ className="flex-1 items-center justify-center rounded-full px-2 py-1 active:opacity-70"
67
+ style={{ minHeight: minHeight - 6 }}
68
+ >
69
+ <AppText
70
+ textRole="footnote"
71
+ className={selected ? "font-t3-bold" : "font-t3-medium"}
72
+ style={{
73
+ color: selected ? selectedTextColor : mutedColor,
74
+ }}
75
+ >
76
+ {option.label}
77
+ </AppText>
78
+ </Pressable>
79
+ );
80
+ })}
81
+ </View>
82
+ </View>
83
+ );
84
+}
apps/mobile/src/components/ui/SegmentedControl.tsx
+1
-78
@@ -1,78 +1 @@
1
-import { useState } from "react";
2
-import { I18nManager, Platform, Pressable, View } from "react-native";
3
-import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated";
4
-
5
-import { AppText } from "./AppText";
6
-import { useControlTheme } from "./useControlTheme";
7
-import type { SegmentedControlProps } from "./SegmentedControl.types";
8
-
9
-export type { SegmentedControlProps } from "./SegmentedControl.types";
10
-
11
-export function SegmentedControl<Value extends string | number>(
12
- props: SegmentedControlProps<Value>,
13
-) {
14
- const { colorScheme, colors } = useControlTheme();
15
- const [layout, setLayout] = useState({ width: 0, height: 0 });
16
- const { width } = layout;
17
- const reduceMotion = useReducedMotion();
18
- const selectedIndex = props.options.findIndex((option) => option.value === props.selected);
19
- const segmentWidth = props.options.length ? Math.max(0, width - 6) / props.options.length : 0;
20
- const selectionOffset = selectedIndex * segmentWidth * (I18nManager.isRTL ? -1 : 1);
21
- const selectionStyle = useAnimatedStyle(() => ({
22
- width: segmentWidth,
23
- transform: [{ translateX: withTiming(selectionOffset, { duration: reduceMotion ? 0 : 160 }) }],
24
- }));
25
- const dark = colorScheme === "dark";
26
- const minHeight = props.size === "compact" ? 32 : Platform.OS === "android" ? 40 : 36;
27
-
28
- return (
29
- <View collapsable={false} className={props.className}>
30
- <View
31
- onLayout={(event) => setLayout(event.nativeEvent.layout)}
32
- className="flex-row rounded-full p-[3px]"
33
- style={{
34
- minHeight,
35
- backgroundColor: colors[dark ? "--color-screen" : "--color-grouped-card"],
36
- }}
37
- >
38
- {selectedIndex >= 0 && width > 0 ? (
39
- <Animated.View
40
- pointerEvents="none"
41
- className="absolute bottom-[3px] start-[3px] top-[3px] rounded-full"
42
- style={[
43
- {
44
- backgroundColor: colors[dark ? "--color-secondary" : "--color-screen"],
45
- },
46
- selectionStyle,
47
- ]}
48
- />
49
- ) : null}
50
- {props.options.map((option) => {
51
- const selected = option.value === props.selected;
52
- return (
53
- <Pressable
54
- key={`${typeof option.value}:${option.value}`}
55
- accessibilityRole={props.role ?? "button"}
56
- accessibilityLabel={option.accessibilityLabel ?? option.label}
57
- accessibilityState={{ selected }}
58
- onPress={() => props.onSelect(option.value)}
59
- className="flex-1 items-center justify-center rounded-full px-2 py-1 active:opacity-70"
60
- style={{ minHeight: minHeight - 6 }}
61
- >
62
- <AppText
63
- textRole="footnote"
64
- className={selected ? "font-t3-bold" : "font-t3-medium"}
65
- style={{
66
- color:
67
- colors[selected ? "--color-secondary-foreground" : "--color-foreground-muted"],
68
- }}
69
- >
70
- {option.label}
71
- </AppText>
72
- </Pressable>
73
- );
74
- })}
75
- </View>
76
- </View>
77
- );
78
-}
1
+export { SegmentedControl, type SegmentedControlProps } from "./SegmentedControl.shared";
apps/mobile/src/components/ui/SegmentedControl.types.ts
+1
@@ -8,6 +8,7 @@ export interface SegmentedControlProps<Value extends number | string> {
8
readonly onSelect: (value: Value) => void;
9
/** Compact uses a 32-point capsule; default uses 36 points on iOS and 40 on Android. */
10
readonly size?: "default" | "compact";
11
+ readonly variant?: "standalone" | "card";
12
readonly role?: "tab" | "button";
13
readonly className?: string;
14
}
apps/mobile/src/components/ui/segmentedControlColors.ts
new
+58
@@ -0,0 +1,58 @@
1
+import {
2
+ flattenThemeColor,
3
+ themeColorContrastRatio,
4
+ themeColorWithAlpha,
5
+ themeColorWithContrast,
6
+ type MobileThemeAppearance,
7
+ type MobileThemeId,
8
+ type MobileThemeVariables,
9
+} from "../../lib/mobileTheme";
10
+import type { SegmentedControlProps } from "./SegmentedControl.types";
11
+
12
+export function segmentedControlColors(
13
+ colors: MobileThemeVariables,
14
+ appearance: MobileThemeAppearance,
15
+ variant: SegmentedControlProps<string>["variant"],
16
+ platform: string,
17
+ themeId: MobileThemeId,
18
+) {
19
+ const dark = appearance === "dark";
20
+ const card = variant === "card";
21
+ const accent =
22
+ colors[themeId === "material-you" ? "--color-primary" : "--color-prominent-action"];
23
+ const trackColor = card
24
+ ? dark
25
+ ? colors["--color-screen"]
26
+ : flattenThemeColor(
27
+ themeColorWithAlpha(colors["--color-foreground"], 0.07),
28
+ colors["--color-grouped-card"],
29
+ )
30
+ : flattenThemeColor(themeColorWithAlpha(accent, dark ? 0.1 : 0.07), colors["--color-screen"]);
31
+ let selectedColor = colors["--color-secondary"];
32
+ if (card && !dark) selectedColor = colors["--color-screen"];
33
+ if (dark && (!card || themeId === "t3-code")) {
34
+ selectedColor = flattenThemeColor(themeColorWithAlpha(accent, 0.32), colors["--color-screen"]);
35
+ }
36
+ let selectedTextColor =
37
+ colors[!card && dark ? "--color-foreground" : "--color-secondary-foreground"];
38
+ if (!card && !dark && platform === "android") {
39
+ const selection = colors["--color-thread-selected"];
40
+ if (
41
+ themeColorContrastRatio(selection, trackColor) >
42
+ themeColorContrastRatio(selectedColor, trackColor)
43
+ ) {
44
+ selectedColor = selection;
45
+ selectedTextColor = colors["--color-thread-selected-foreground"];
46
+ }
47
+ }
48
+ return {
49
+ trackColor,
50
+ selectedColor,
51
+ selectedTextColor: themeColorWithContrast(selectedTextColor, selectedColor),
52
+ mutedColor: themeColorWithContrast(
53
+ colors["--color-foreground-muted"],
54
+ trackColor,
55
+ dark && !card ? 7 : 4.5,
56
+ ),
57
+ };
58
+}
apps/mobile/src/components/ui/useControlTheme.ts
+2
-1
@@ -1,9 +1,10 @@
1
import { useAppearancePreferences } from "../../features/settings/appearance/AppearancePreferencesProvider";
2
3
export function useControlTheme() {
4
- const { themeAppearance, themeVariables, systemColorsActive, appearance } =
4
+ const { themeId, themeAppearance, themeVariables, systemColorsActive, appearance } =
5
useAppearancePreferences();
6
return {
7
+ themeId,
8
colorScheme: themeAppearance,
9
colors: themeVariables,
10
systemColorsActive,
apps/mobile/src/features/development/ComponentCatalogScreen.tsx
+10
@@ -104,6 +104,16 @@ export function ComponentCatalogScreen() {
104
<View className="gap-3">
105
<AppText className="text-lg font-t3-semibold">Lists and selection</AppText>
106
<ListSection>
107
+ <View className="p-4">
108
+ <SegmentedControl
109
+ variant="card"
110
+ options={CHOICES}
111
+ selected={tab}
112
+ onSelect={setTab}
113
+ size="compact"
114
+ role="tab"
115
+ />
116
+ </View>
117
<ListRow icon="folder" label="Projects" detail="4" onPress={() => setSheet(true)} />
118
<ListToggleRow
119
icon="bell.badge"
apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx
+1
@@ -951,6 +951,7 @@ function TaskForm({
951
<SettingsSection title="Schedule">
952
<View className="px-4 py-3">
953
<SegmentedControl
954
+ variant="card"
955
options={[
956
{ value: "fixed_time", label: "At a time" },
957
{ value: "interval", label: "Interval" },
apps/mobile/src/features/threads/CustomSnoozeSheet.android.tsx
+8
-1
@@ -144,6 +144,7 @@ export function CustomSnoozeSheet(props: Props) {
144
<Text style={titleTypography}>Custom snooze</Text>
145
<RNHostView matchContents={{ vertical: true }} modifiers={[fillMaxWidth()]}>
146
<SegmentedControl
147
+ variant="card"
148
options={modes}
149
selected={mode}
150
onSelect={(value) => {
@@ -155,6 +156,7 @@ export function CustomSnoozeSheet(props: Props) {
156
{mode === "date" ? (
157
<RNHostView matchContents={{ vertical: true }} modifiers={[fillMaxWidth()]}>
158
<SegmentedControl
159
+ variant="card"
160
options={[
161
{
162
value: "date",
@@ -230,7 +232,12 @@ export function CustomSnoozeSheet(props: Props) {
232
</FilledTonalIconButton>
233
</Row>
234
<RNHostView matchContents={{ vertical: true }} modifiers={[fillMaxWidth()]}>
233
- <SegmentedControl options={units} selected={unit} onSelect={setUnit} />
235
+ <SegmentedControl
236
+ variant="card"
237
+ options={units}
238
+ selected={unit}
239
+ onSelect={setUnit}
240
+ />
241
</RNHostView>
242
</Column>
243
)}
apps/mobile/src/lib/mobileTheme.ts
+6
@@ -209,6 +209,12 @@ function contrastRatio(
209
);
210
}
211
212
+export function themeColorContrastRatio(first: string, second: string): number {
213
+ const firstChannels = rgbChannels(first);
214
+ const secondChannels = rgbChannels(second);
215
+ return firstChannels && secondChannels ? contrastRatio(firstChannels, secondChannels) : 1;
216
+}
217
+
218
export function themeColorWithContrast(
219
accent: string,
220
surface: string | ReadonlyArray<string>,