Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions apps/mobile/src/components/ui/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { GlassView } from "expo-glass-effect";
import { useState } from "react";
import { Pressable, View } from "react-native";
import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated";
import { withUniwind } from "uniwind";

import { cn } from "../../lib/cn";
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
import { useAppearancePreferences } from "../../features/settings/appearance/AppearancePreferencesProvider";
import { AppText } from "./AppText";

const TabGlass = withUniwind(GlassView, { style: { fromClassName: "className" } });

export interface TabsProps<Value extends string> {
readonly options: readonly {
readonly value: Value;
readonly label: string;
readonly count?: number;
}[];
readonly selected: Value;
readonly onSelect: (value: Value) => void;
readonly className?: string;
}

/** Section navigation. Value pickers use SegmentedControl. */
export function Tabs<Value extends string>(props: TabsProps<Value>) {
const { themeAppearance } = useAppearancePreferences();
const reduceMotion = useReducedMotion();
const [frames, setFrames] = useState<Partial<Record<Value, { x: number; width: number }>>>({});
const frame = frames[props.selected];
const duration = reduceMotion ? 0 : 220;
const indicatorStyle = useAnimatedStyle(() => ({
width: withTiming(frame?.width ?? 0, { duration }),
transform: [{ translateX: withTiming(frame?.x ?? 0, { duration }) }],
}));

return (
<View accessibilityRole="tablist" className={cn("flex-row", props.className)}>
{frame ? (
<Animated.View
pointerEvents="none"
className="absolute bottom-0 left-0 top-0 rounded-full border border-border-subtle"
style={indicatorStyle}
>
{NATIVE_LIQUID_GLASS_SUPPORTED ? (
<TabGlass
className="flex-1 rounded-full"
colorScheme={themeAppearance === "dark" ? "dark" : "light"}
/>
) : (
<View className="flex-1 rounded-full bg-grouped-card" />
)}
</Animated.View>
) : null}
{props.options.map((option) => {
const selected = option.value === props.selected;
return (
<Pressable
key={option.value}
accessibilityRole="tab"
accessibilityLabel={option.count ? `${option.label}, ${option.count}` : option.label}
accessibilityState={{ selected }}
onPress={() => props.onSelect(option.value)}
onLayout={({ nativeEvent: { layout } }) =>
setFrames((current) =>
current[option.value]?.x === layout.x &&
current[option.value]?.width === layout.width
? current
: { ...current, [option.value]: { x: layout.x, width: layout.width } },
)
}
className="min-h-9 flex-row items-center gap-1.5 rounded-full px-3.5 active:opacity-70"
>
<AppText
textRole="footnote"
className={cn(
"font-t3-semibold",
selected ? "text-foreground" : "text-foreground-muted",
)}
>
{option.label}
</AppText>
{option.count ? (
<AppText textRole="label" className="font-t3-medium text-foreground-muted">
{option.count}
</AppText>
) : null}
</Pressable>
);
})}
</View>
);
}
5 changes: 3 additions & 2 deletions apps/mobile/src/components/ui/segmentedControlColors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export function segmentedControlColors(
colors["--color-grouped-card"],
)
: flattenThemeColor(themeColorWithAlpha(accent, dark ? 0.1 : 0.07), colors["--color-screen"]);
let selectedColor = colors["--color-secondary"];
// The thumb must lift off the track: --color-secondary nearly matches it in light themes.
let selectedColor = colors["--color-card"];
if (card && !dark) selectedColor = colors["--color-screen"];
if (dark && (!card || themeId === "t3-code")) {
selectedColor = flattenThemeColor(themeColorWithAlpha(accent, 0.32), colors["--color-screen"]);
selectedColor = flattenThemeColor(themeColorWithAlpha(accent, 0.2), colors["--color-screen"]);
}
let selectedTextColor =
colors[!card && dark ? "--color-foreground" : "--color-secondary-foreground"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { NumberField } from "../../components/ui/NumberField";
import { AppBar } from "../../components/ui/AppBar";
import { ScreenScrollView } from "../../components/ui/ScreenScrollView";
import { SegmentedControl } from "../../components/ui/SegmentedControl";
import { Tabs } from "../../components/ui/Tabs";
import { SliderRow } from "../../components/ui/SliderRow";
import * as Dialog from "../../components/ui/Dialog";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
Expand Down Expand Up @@ -89,15 +90,14 @@ export function ComponentCatalogScreen() {
size="compact"
/>
</View>
<SegmentedControl
<Tabs
options={[
{ value: "controls", label: "Controls" },
{ value: "forms", label: "Forms" },
{ value: "feedback", label: "Feedback" },
{ value: "feedback", label: "Feedback", count: 3 },
]}
selected={page}
onSelect={setPage}
size="compact"
/>
{page === "controls" ? (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import { AndroidWorkspaceSidebarButton } from "../layout/workspace-sidebar-toolb
import { useWorkspaceSidebarHeaderItem } from "../layout/useWorkspaceSidebarHeaderItem";
import { useAndroidWorkspaceBack } from "../workspace/useAndroidWorkspaceNavigation";
import { EmptyState } from "../../components/ui/EmptyState";
import { SegmentedControl } from "../../components/ui/SegmentedControl";
import { Tabs } from "../../components/ui/Tabs";
import { SymbolView } from "../../components/ui/AppSymbol";
import { relativeTime } from "../../lib/time";
import { NativeStackScreenOptions } from "../../native/StackHeader";
Expand Down Expand Up @@ -171,6 +171,7 @@ function usePullRequestActivityRows(params: PullRequestParams, filter: ActivityF
})();
return {
rows,
count: result.data ? result.data.commentCount + result.data.reviewThreads.length : undefined,
hiddenCount: filtered?.hiddenCount ?? 0,
pending: result.isPending && !result.data,
error: result.error,
Expand Down Expand Up @@ -838,18 +839,21 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps<PullRequestP
}}
>
<PullRequestIdentity pr={identity} params={params} />
<SegmentedControl
<Tabs
options={[
{ value: "overview", label: "Overview" },
...(guidesEnabled
? [{ value: "guide" as const, label: "Guide" }]
: []),
{ value: "activity", label: "Activity" },
{
value: "activity",
label: "Activity",
count: activityContent.count,
},
]}
selected={section}
onSelect={selectSection}
role="tab"
size="compact"
className="-mx-3.5"
/>
</View>
) : null}
Expand Down
21 changes: 4 additions & 17 deletions apps/mobile/src/features/usage/UsageRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Animated, { FadeIn, ReduceMotion } from "react-native-reanimated";
import { useSafeAreaInsets } from "react-native-safe-area-context";

import { SegmentedControl } from "../../components/ui/SegmentedControl";
import { Tabs } from "../../components/ui/Tabs";
import { useReduceMotionEnabled } from "../../lib/appState";
import { AppText as Text } from "../../components/ui/AppText";
import { ProviderIcon } from "../../components/ProviderIcon";
Expand Down Expand Up @@ -309,9 +310,8 @@ function UsageScreen(props: {
<View className="w-full gap-6 self-center" style={{ maxWidth: MAX_CONTENT_WIDTH }}>
{wide ? (
<View className="flex-row items-center gap-3">
{showingLimits ? (
<View className="flex-1" />
) : (
<Tabs options={VIEW_OPTIONS} selected={view} onSelect={setView} className="-ms-3.5" />
{showingLimits ? null : (
<SegmentedControl
options={WINDOW_OPTIONS}
selected={windowDays}
Expand All @@ -320,22 +320,9 @@ function UsageScreen(props: {
className="flex-1"
/>
)}
<SegmentedControl
options={VIEW_OPTIONS}
selected={view}
onSelect={setView}
size="compact"
role="tab"
className="w-60"
/>
</View>
) : (
<SegmentedControl
options={VIEW_OPTIONS}
selected={view}
onSelect={setView}
role="tab"
/>
<Tabs options={VIEW_OPTIONS} selected={view} onSelect={setView} className="-mx-3.5" />
)}
<Animated.View
key={showingLimits ? "limits" : "usage"}
Expand Down
Loading