diff --git a/apps/mobile/src/components/ui/Tabs.tsx b/apps/mobile/src/components/ui/Tabs.tsx new file mode 100644 index 0000000000000..510c4bcaa4b26 --- /dev/null +++ b/apps/mobile/src/components/ui/Tabs.tsx @@ -0,0 +1,99 @@ +import { GlassView } from "expo-glass-effect"; +import { useEffect, useRef, useState, type ComponentRef } from "react"; +import { Pressable, ScrollView, 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 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 scrollView = useRef>(null); + const [frames, setFrames] = useState>>({}); + const frame = frames[props.selected]; + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- keeps the selected tab visible in the native scroll viewport + useEffect(() => { + if (frame) scrollView.current?.scrollTo({ x: frame.x, animated: false }); + }, [frame]); + 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-11 shrink-0 flex-row items-center gap-1.5 rounded-full px-3.5 active:opacity-70" + > + + {option.label} + + + ); + })} + + + ); +} diff --git a/apps/mobile/src/components/ui/segmentedControlColors.ts b/apps/mobile/src/components/ui/segmentedControlColors.ts index 6b58675726e4f..b612e9b1f006d 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 = dark && card ? colors["--color-secondary"] : 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 35cee094a0137..36c20d30d0afc 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,7 +90,7 @@ 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 01710fb095b0f..4cfa8d1af9592 100644 --- a/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx +++ b/apps/mobile/src/features/pull-requests/PullRequestRouteScreen.tsx @@ -77,7 +77,7 @@ import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSi import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout"; import { useAndroidWorkspaceBack } from "../layout/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 { ScreenContent } from "../../components/ui/ScreenContent"; import { RelativeTime } from "../../components/RelativeTime"; @@ -925,10 +925,8 @@ export function PullRequestRouteScreen({ route }: StaticScreenProps - {/* UIKit draws the tapped control's glass lens outside the hidden - tab's opacity, so only the visible tab mounts the control. */} {Platform.OS !== "ios" || section === tab ? ( - ) : ( - + )} ) : null} diff --git a/apps/mobile/src/features/usage/UsageRouteScreen.tsx b/apps/mobile/src/features/usage/UsageRouteScreen.tsx index 48215804ee2dc..aa4bd6796ef2d 100644 --- a/apps/mobile/src/features/usage/UsageRouteScreen.tsx +++ b/apps/mobile/src/features/usage/UsageRouteScreen.tsx @@ -32,6 +32,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 { useWorkspaceSettledContentWidth } from "../layout/workspace-content-width"; @@ -269,9 +270,13 @@ function UsageScreen(props: { {wide ? ( - {showingLimits ? ( - - ) : ( + + {showingLimits ? null : ( )} - ) : ( - + )}