Repository navigation
feat(mobile): distinguish section tabs from value pickers #29381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jakeleventhal
wants to merge
5
commits into
pingdotgg:main
Choose a base branch
from
jakeleventhal:t3/redesign-mobile-tab-selectors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−28
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d96cf45
feat(mobile): simplify section tabs with a sliding glass pill
jakeleventhal 1a53f4d
fix(mobile): remove ambiguous activity tab counts
jakeleventhal 41dc39f
fix(mobile): preserve dark card selection contrast
jakeleventhal f489f69
fix(mobile): keep section tabs reachable and easier to tap
jakeleventhal b45ad99
fix(mobile): scroll selected section tabs into view
jakeleventhal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Value extends string> { | ||
| 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<Value extends string>(props: TabsProps<Value>) { | ||
| const { themeAppearance } = useAppearancePreferences(); | ||
| const reduceMotion = useReducedMotion(); | ||
| const scrollView = useRef<ComponentRef<typeof ScrollView>>(null); | ||
| const [frames, setFrames] = useState<Partial<Record<Value, { x: number; width: number }>>>({}); | ||
| 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 ( | ||
| <ScrollView | ||
| ref={scrollView} | ||
| horizontal | ||
| showsHorizontalScrollIndicator={false} | ||
| className={cn("grow-0", props.className)} | ||
| > | ||
| <View accessibilityRole="tablist" className="flex-row"> | ||
| {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.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-11 shrink-0 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> | ||
| </Pressable> | ||
| ); | ||
| })} | ||
| </View> | ||
| </ScrollView> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.