diff --git a/apps/mobile/src/components/ui/Tabs.tsx b/apps/mobile/src/components/ui/Tabs.tsx new file mode 100644 index 0000000000000..06c8d4ab00fa2 --- /dev/null +++ b/apps/mobile/src/components/ui/Tabs.tsx @@ -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 { + 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(props: TabsProps) { + const { themeAppearance } = useAppearancePreferences(); + const reduceMotion = useReducedMotion(); + const [frames, setFrames] = useState>>({}); + 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 ( + + {frame ? ( + + {NATIVE_LIQUID_GLASS_SUPPORTED ? ( + + ) : ( + + )} + + ) : null} + {props.options.map((option) => { + const selected = option.value === props.selected; + return ( + 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" + > + + {option.label} + + {option.count ? ( + + {option.count} + + ) : null} + + ); + })} + + ); +} diff --git a/apps/mobile/src/components/ui/segmentedControlColors.ts b/apps/mobile/src/components/ui/segmentedControlColors.ts index 6b58675726e4f..f90d5bc3d41ee 100644 --- a/apps/mobile/src/components/ui/segmentedControlColors.ts +++ b/apps/mobile/src/components/ui/segmentedControlColors.ts @@ -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"]; diff --git a/apps/mobile/src/features/development/ComponentCatalogScreen.tsx b/apps/mobile/src/features/development/ComponentCatalogScreen.tsx index d692e3e129b0a..34eb720d92313 100644 --- a/apps/mobile/src/features/development/ComponentCatalogScreen.tsx +++ b/apps/mobile/src/features/development/ComponentCatalogScreen.tsx @@ -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"; @@ -89,15 +90,14 @@ export function ComponentCatalogScreen() { size="compact" /> - {page === "controls" ? ( <> diff --git a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx index e0ad9c76e9bb4..954e107900e82 100644 --- a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx +++ b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx @@ -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"; @@ -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, @@ -838,18 +839,21 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps - ) : null} diff --git a/apps/mobile/src/features/usage/UsageRouteScreen.tsx b/apps/mobile/src/features/usage/UsageRouteScreen.tsx index 1cba6c00547fe..a825fe9476384 100644 --- a/apps/mobile/src/features/usage/UsageRouteScreen.tsx +++ b/apps/mobile/src/features/usage/UsageRouteScreen.tsx @@ -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"; @@ -309,9 +310,8 @@ function UsageScreen(props: { {wide ? ( - {showingLimits ? ( - - ) : ( + + {showingLimits ? null : ( )} - ) : ( - + )}