Skip to content

Commit f16b8ab

Browse files
committed
feat(mobile): simplify section tabs with a sliding glass pill
1 parent 886d8f6 commit f16b8ab

5 files changed

Lines changed: 112 additions & 27 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { GlassView } from "expo-glass-effect";
2+
import { useState } from "react";
3+
import { Pressable, View } from "react-native";
4+
import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated";
5+
import { withUniwind } from "uniwind";
6+
7+
import { cn } from "../../lib/cn";
8+
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
9+
import { useAppearancePreferences } from "../../features/settings/appearance/AppearancePreferencesProvider";
10+
import { AppText } from "./AppText";
11+
12+
const TabGlass = withUniwind(GlassView, { style: { fromClassName: "className" } });
13+
14+
export interface TabsProps<Value extends string> {
15+
readonly options: readonly {
16+
readonly value: Value;
17+
readonly label: string;
18+
readonly count?: number;
19+
}[];
20+
readonly selected: Value;
21+
readonly onSelect: (value: Value) => void;
22+
readonly className?: string;
23+
}
24+
25+
/** Section navigation. Value pickers use SegmentedControl. */
26+
export function Tabs<Value extends string>(props: TabsProps<Value>) {
27+
const { themeAppearance } = useAppearancePreferences();
28+
const reduceMotion = useReducedMotion();
29+
const [frames, setFrames] = useState<Partial<Record<Value, { x: number; width: number }>>>({});
30+
const frame = frames[props.selected];
31+
const duration = reduceMotion ? 0 : 220;
32+
const indicatorStyle = useAnimatedStyle(() => ({
33+
width: withTiming(frame?.width ?? 0, { duration }),
34+
transform: [{ translateX: withTiming(frame?.x ?? 0, { duration }) }],
35+
}));
36+
37+
return (
38+
<View accessibilityRole="tablist" className={cn("flex-row", props.className)}>
39+
{frame ? (
40+
<Animated.View
41+
pointerEvents="none"
42+
className="absolute bottom-0 left-0 top-0 rounded-full border border-border-subtle"
43+
style={indicatorStyle}
44+
>
45+
{NATIVE_LIQUID_GLASS_SUPPORTED ? (
46+
<TabGlass
47+
className="flex-1 rounded-full"
48+
colorScheme={themeAppearance === "dark" ? "dark" : "light"}
49+
/>
50+
) : (
51+
<View className="flex-1 rounded-full bg-grouped-card" />
52+
)}
53+
</Animated.View>
54+
) : null}
55+
{props.options.map((option) => {
56+
const selected = option.value === props.selected;
57+
return (
58+
<Pressable
59+
key={option.value}
60+
accessibilityRole="tab"
61+
accessibilityLabel={option.count ? `${option.label}, ${option.count}` : option.label}
62+
accessibilityState={{ selected }}
63+
onPress={() => props.onSelect(option.value)}
64+
onLayout={({ nativeEvent: { layout } }) =>
65+
setFrames((current) =>
66+
current[option.value]?.x === layout.x &&
67+
current[option.value]?.width === layout.width
68+
? current
69+
: { ...current, [option.value]: { x: layout.x, width: layout.width } },
70+
)
71+
}
72+
className="min-h-9 flex-row items-center gap-1.5 rounded-full px-3.5 active:opacity-70"
73+
>
74+
<AppText
75+
textRole="footnote"
76+
className={cn(
77+
"font-t3-semibold",
78+
selected ? "text-foreground" : "text-foreground-muted",
79+
)}
80+
>
81+
{option.label}
82+
</AppText>
83+
{option.count ? (
84+
<AppText textRole="label" className="font-t3-medium text-foreground-muted">
85+
{option.count}
86+
</AppText>
87+
) : null}
88+
</Pressable>
89+
);
90+
})}
91+
</View>
92+
);
93+
}

‎apps/mobile/src/components/ui/segmentedControlColors.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ export function segmentedControlColors(
2828
colors["--color-grouped-card"],
2929
)
3030
: flattenThemeColor(themeColorWithAlpha(accent, dark ? 0.1 : 0.07), colors["--color-screen"]);
31-
let selectedColor = colors["--color-secondary"];
31+
// The thumb must lift off the track: --color-secondary nearly matches it in light themes.
32+
let selectedColor = colors["--color-card"];
3233
if (card && !dark) selectedColor = colors["--color-screen"];
3334
if (dark && (!card || themeId === "t3-code")) {
34-
selectedColor = flattenThemeColor(themeColorWithAlpha(accent, 0.32), colors["--color-screen"]);
35+
selectedColor = flattenThemeColor(themeColorWithAlpha(accent, 0.2), colors["--color-screen"]);
3536
}
3637
let selectedTextColor =
3738
colors[!card && dark ? "--color-foreground" : "--color-secondary-foreground"];

‎apps/mobile/src/features/development/ComponentCatalogScreen.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { NumberField } from "../../components/ui/NumberField";
2424
import { AppBar } from "../../components/ui/AppBar";
2525
import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
2626
import { SegmentedControl } from "../../components/ui/SegmentedControl";
27+
import { Tabs } from "../../components/ui/Tabs";
2728
import { SliderRow } from "../../components/ui/SliderRow";
2829
import * as Dialog from "../../components/ui/Dialog";
2930
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
@@ -89,15 +90,14 @@ export function ComponentCatalogScreen() {
8990
size="compact"
9091
/>
9192
</View>
92-
<SegmentedControl
93+
<Tabs
9394
options={[
9495
{ value: "controls", label: "Controls" },
9596
{ value: "forms", label: "Forms" },
96-
{ value: "feedback", label: "Feedback" },
97+
{ value: "feedback", label: "Feedback", count: 3 },
9798
]}
9899
selected={page}
99100
onSelect={setPage}
100-
size="compact"
101101
/>
102102
{page === "controls" ? (
103103
<>

‎apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { AndroidWorkspaceSidebarButton } from "../layout/workspace-sidebar-toolb
7272
import { useWorkspaceSidebarHeaderItem } from "../layout/useWorkspaceSidebarHeaderItem";
7373
import { useAndroidWorkspaceBack } from "../workspace/useAndroidWorkspaceNavigation";
7474
import { EmptyState } from "../../components/ui/EmptyState";
75-
import { SegmentedControl } from "../../components/ui/SegmentedControl";
75+
import { Tabs } from "../../components/ui/Tabs";
7676
import { SymbolView } from "../../components/ui/AppSymbol";
7777
import { relativeTime } from "../../lib/time";
7878
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -171,6 +171,7 @@ function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityF
171171
})();
172172
return {
173173
rows,
174+
count: result.data ? result.data.commentCount + result.data.reviewThreads.length : undefined,
174175
hiddenCount: filtered?.hiddenCount ?? 0,
175176
pending: result.isPending && !result.data,
176177
error: result.error,
@@ -838,18 +839,21 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
838839
}}
839840
>
840841
<PullRequestIdentity pr={identity} params={params} />
841-
<SegmentedControl
842+
<Tabs
842843
options={[
843844
{ value: "overview", label: "Overview" },
844845
...(guidesEnabled
845846
? [{ value: "guide" as const, label: "Guide" }]
846847
: []),
847-
{ value: "activity", label: "Activity" },
848+
{
849+
value: "activity",
850+
label: "Activity",
851+
count: activityContent.count,
852+
},
848853
]}
849854
selected={section}
850855
onSelect={selectSection}
851-
role="tab"
852-
size="compact"
856+
className="-mx-3.5"
853857
/>
854858
</View>
855859
) : null}

‎apps/mobile/src/features/usage/UsageRouteScreen.tsx‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Animated, { FadeIn, ReduceMotion } from "react-native-reanimated";
3434
import { useSafeAreaInsets } from "react-native-safe-area-context";
3535

3636
import { SegmentedControl } from "../../components/ui/SegmentedControl";
37+
import { Tabs } from "../../components/ui/Tabs";
3738
import { useReduceMotionEnabled } from "../../lib/appState";
3839
import { AppText as Text } from "../../components/ui/AppText";
3940
import { ProviderIcon } from "../../components/ProviderIcon";
@@ -309,9 +310,8 @@ function UsageScreen(props: {
309310
<View className="w-full gap-6 self-center" style={{ maxWidth: MAX_CONTENT_WIDTH }}>
310311
{wide ? (
311312
<View className="flex-row items-center gap-3">
312-
{showingLimits ? (
313-
<View className="flex-1" />
314-
) : (
313+
<Tabs options={VIEW_OPTIONS} selected={view} onSelect={setView} className="-ms-3.5" />
314+
{showingLimits ? null : (
315315
<SegmentedControl
316316
options={WINDOW_OPTIONS}
317317
selected={windowDays}
@@ -320,22 +320,9 @@ function UsageScreen(props: {
320320
className="flex-1"
321321
/>
322322
)}
323-
<SegmentedControl
324-
options={VIEW_OPTIONS}
325-
selected={view}
326-
onSelect={setView}
327-
size="compact"
328-
role="tab"
329-
className="w-60"
330-
/>
331323
</View>
332324
) : (
333-
<SegmentedControl
334-
options={VIEW_OPTIONS}
335-
selected={view}
336-
onSelect={setView}
337-
role="tab"
338-
/>
325+
<Tabs options={VIEW_OPTIONS} selected={view} onSelect={setView} className="-mx-3.5" />
339326
)}
340327
<Animated.View
341328
key={showingLimits ? "limits" : "usage"}

0 commit comments

Comments
 (0)