|
1 | 1 | import { GlassView } from "expo-glass-effect"; |
2 | 2 | import { useState } from "react"; |
3 | | -import { Pressable, View } from "react-native"; |
| 3 | +import { Pressable, ScrollView, View } from "react-native"; |
4 | 4 | import Animated, { useAnimatedStyle, useReducedMotion, withTiming } from "react-native-reanimated"; |
5 | 5 | import { withUniwind } from "uniwind"; |
6 | 6 |
|
@@ -34,54 +34,60 @@ export function Tabs<Value extends string>(props: TabsProps<Value>) { |
34 | 34 | })); |
35 | 35 |
|
36 | 36 | return ( |
37 | | - <View accessibilityRole="tablist" className={cn("flex-row", props.className)}> |
38 | | - {frame ? ( |
39 | | - <Animated.View |
40 | | - pointerEvents="none" |
41 | | - className="absolute bottom-0 left-0 top-0 rounded-full border border-border-subtle" |
42 | | - style={indicatorStyle} |
43 | | - > |
44 | | - {NATIVE_LIQUID_GLASS_SUPPORTED ? ( |
45 | | - <TabGlass |
46 | | - className="flex-1 rounded-full" |
47 | | - colorScheme={themeAppearance === "dark" ? "dark" : "light"} |
48 | | - /> |
49 | | - ) : ( |
50 | | - <View className="flex-1 rounded-full bg-grouped-card" /> |
51 | | - )} |
52 | | - </Animated.View> |
53 | | - ) : null} |
54 | | - {props.options.map((option) => { |
55 | | - const selected = option.value === props.selected; |
56 | | - return ( |
57 | | - <Pressable |
58 | | - key={option.value} |
59 | | - accessibilityRole="tab" |
60 | | - accessibilityLabel={option.label} |
61 | | - accessibilityState={{ selected }} |
62 | | - onPress={() => props.onSelect(option.value)} |
63 | | - onLayout={({ nativeEvent: { layout } }) => |
64 | | - setFrames((current) => |
65 | | - current[option.value]?.x === layout.x && |
66 | | - current[option.value]?.width === layout.width |
67 | | - ? current |
68 | | - : { ...current, [option.value]: { x: layout.x, width: layout.width } }, |
69 | | - ) |
70 | | - } |
71 | | - className="min-h-8 flex-row items-center gap-1.5 rounded-full px-3.5 active:opacity-70" |
| 37 | + <ScrollView |
| 38 | + horizontal |
| 39 | + showsHorizontalScrollIndicator={false} |
| 40 | + className={cn("grow-0", props.className)} |
| 41 | + > |
| 42 | + <View accessibilityRole="tablist" className="flex-row"> |
| 43 | + {frame ? ( |
| 44 | + <Animated.View |
| 45 | + pointerEvents="none" |
| 46 | + className="absolute bottom-0 left-0 top-0 rounded-full border border-border-subtle" |
| 47 | + style={indicatorStyle} |
72 | 48 | > |
73 | | - <AppText |
74 | | - textRole="footnote" |
75 | | - className={cn( |
76 | | - "font-t3-semibold", |
77 | | - selected ? "text-foreground" : "text-foreground-muted", |
78 | | - )} |
| 49 | + {NATIVE_LIQUID_GLASS_SUPPORTED ? ( |
| 50 | + <TabGlass |
| 51 | + className="flex-1 rounded-full" |
| 52 | + colorScheme={themeAppearance === "dark" ? "dark" : "light"} |
| 53 | + /> |
| 54 | + ) : ( |
| 55 | + <View className="flex-1 rounded-full bg-grouped-card" /> |
| 56 | + )} |
| 57 | + </Animated.View> |
| 58 | + ) : null} |
| 59 | + {props.options.map((option) => { |
| 60 | + const selected = option.value === props.selected; |
| 61 | + return ( |
| 62 | + <Pressable |
| 63 | + key={option.value} |
| 64 | + accessibilityRole="tab" |
| 65 | + accessibilityLabel={option.label} |
| 66 | + accessibilityState={{ selected }} |
| 67 | + onPress={() => props.onSelect(option.value)} |
| 68 | + onLayout={({ nativeEvent: { layout } }) => |
| 69 | + setFrames((current) => |
| 70 | + current[option.value]?.x === layout.x && |
| 71 | + current[option.value]?.width === layout.width |
| 72 | + ? current |
| 73 | + : { ...current, [option.value]: { x: layout.x, width: layout.width } }, |
| 74 | + ) |
| 75 | + } |
| 76 | + className="min-h-11 shrink-0 flex-row items-center gap-1.5 rounded-full px-3.5 active:opacity-70" |
79 | 77 | > |
80 | | - {option.label} |
81 | | - </AppText> |
82 | | - </Pressable> |
83 | | - ); |
84 | | - })} |
85 | | - </View> |
| 78 | + <AppText |
| 79 | + textRole="footnote" |
| 80 | + className={cn( |
| 81 | + "font-t3-semibold", |
| 82 | + selected ? "text-foreground" : "text-foreground-muted", |
| 83 | + )} |
| 84 | + > |
| 85 | + {option.label} |
| 86 | + </AppText> |
| 87 | + </Pressable> |
| 88 | + ); |
| 89 | + })} |
| 90 | + </View> |
| 91 | + </ScrollView> |
86 | 92 | ); |
87 | 93 | } |
0 commit comments