Skip to content

Commit b3cc561

Browse files
authored
Merge pull request #105 from nativeui-org/fix/tabs-content-scroll-view
fix(tabs): update flex style to allow scroll view
2 parents ac8f9b3 + a03b10e commit b3cc561

File tree

1 file changed

+99
-99
lines changed

1 file changed

+99
-99
lines changed

registry/tabs/tabs.tsx

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,134 @@
1-
import * as React from "react";
2-
import { View, Text, Pressable, Platform } from "react-native";
31
import { cn } from "@/lib/utils";
2+
import * as React from "react";
3+
import { Platform, Pressable, Text, View } from "react-native";
44

55
interface TabsProps {
6-
defaultValue?: string;
7-
value?: string;
8-
onValueChange?: (value: string) => void;
9-
children: React.ReactNode;
10-
className?: string;
6+
defaultValue?: string;
7+
value?: string;
8+
onValueChange?: (value: string) => void;
9+
children: React.ReactNode;
10+
className?: string;
1111
}
1212

1313
interface TabsListProps {
14-
children: React.ReactNode;
15-
className?: string;
14+
children: React.ReactNode;
15+
className?: string;
1616
}
1717

1818
interface TabsTriggerProps {
19-
value: string;
20-
children: React.ReactNode;
21-
className?: string;
19+
value: string;
20+
children: React.ReactNode;
21+
className?: string;
2222
}
2323

2424
interface TabsContentProps {
25-
value: string;
26-
children: React.ReactNode;
27-
className?: string;
25+
value: string;
26+
children: React.ReactNode;
27+
className?: string;
2828
}
2929

3030
const TabsContext = React.createContext<{
31-
value: string;
32-
onValueChange: (value: string) => void;
31+
value: string;
32+
onValueChange: (value: string) => void;
3333
}>({
34-
value: "",
35-
onValueChange: () => { },
34+
value: "",
35+
onValueChange: () => {},
3636
});
3737

3838
const Tabs = React.forwardRef<View, TabsProps>(
39-
({ defaultValue, value, onValueChange, children, className }, ref) => {
40-
const [selectedValue, setSelectedValue] = React.useState(
41-
value || defaultValue || ""
42-
);
43-
44-
const handleValueChange = React.useCallback(
45-
(newValue: string) => {
46-
setSelectedValue(newValue);
47-
onValueChange?.(newValue);
48-
},
49-
[onValueChange]
50-
);
51-
52-
return (
53-
<TabsContext.Provider
54-
value={{
55-
value: selectedValue,
56-
onValueChange: handleValueChange,
57-
}}
58-
>
59-
<View ref={ref} className={cn("w-full", className)}>
60-
{children}
61-
</View>
62-
</TabsContext.Provider>
63-
);
64-
}
39+
({ defaultValue, value, onValueChange, children, className }, ref) => {
40+
const [selectedValue, setSelectedValue] = React.useState(
41+
value || defaultValue || "",
42+
);
43+
44+
const handleValueChange = React.useCallback(
45+
(newValue: string) => {
46+
setSelectedValue(newValue);
47+
onValueChange?.(newValue);
48+
},
49+
[onValueChange],
50+
);
51+
52+
return (
53+
<TabsContext.Provider
54+
value={{
55+
value: selectedValue,
56+
onValueChange: handleValueChange,
57+
}}
58+
>
59+
<View ref={ref} className={cn("flex-1 w-full", className)}>
60+
{children}
61+
</View>
62+
</TabsContext.Provider>
63+
);
64+
},
6565
);
6666

6767
const TabsList = React.forwardRef<View, TabsListProps>(
68-
({ children, className }, ref) => {
69-
return (
70-
<View
71-
ref={ref}
72-
className={cn(
73-
"flex-row items-center justify-center rounded-xl bg-muted p-1",
74-
Platform.OS === "ios" ? "h-12" : "h-14",
75-
className
76-
)}
77-
>
78-
{children}
79-
</View>
80-
);
81-
}
68+
({ children, className }, ref) => {
69+
return (
70+
<View
71+
ref={ref}
72+
className={cn(
73+
"flex-row items-center justify-center rounded-xl bg-muted p-1",
74+
Platform.OS === "ios" ? "h-12" : "h-14",
75+
className,
76+
)}
77+
>
78+
{children}
79+
</View>
80+
);
81+
},
8282
);
8383

8484
const TabsTrigger = React.forwardRef<View, TabsTriggerProps>(
85-
({ value, children, className }, ref) => {
86-
const { value: selectedValue, onValueChange } =
87-
React.useContext(TabsContext);
88-
const isSelected = selectedValue === value;
89-
90-
return (
91-
<Pressable
92-
ref={ref}
93-
onPress={() => onValueChange(value)}
94-
className={cn(
95-
"flex-1 items-center justify-center rounded-lg px-4 py-2",
96-
Platform.OS === "ios" ? "h-10" : "h-12",
97-
isSelected ? "bg-background" : "bg-transparent",
98-
className
99-
)}
100-
>
101-
<Text
102-
className={cn(
103-
"text-base font-medium",
104-
isSelected ? "text-foreground" : "text-muted-foreground"
105-
)}
106-
>
107-
{children}
108-
</Text>
109-
</Pressable>
110-
);
111-
}
85+
({ value, children, className }, ref) => {
86+
const { value: selectedValue, onValueChange } =
87+
React.useContext(TabsContext);
88+
const isSelected = selectedValue === value;
89+
90+
return (
91+
<Pressable
92+
ref={ref}
93+
onPress={() => onValueChange(value)}
94+
className={cn(
95+
"flex-1 items-center justify-center rounded-lg px-4 py-2",
96+
Platform.OS === "ios" ? "h-10" : "h-12",
97+
isSelected ? "bg-background" : "bg-transparent",
98+
className,
99+
)}
100+
>
101+
<Text
102+
className={cn(
103+
"text-base font-medium",
104+
isSelected ? "text-foreground" : "text-muted-foreground",
105+
)}
106+
>
107+
{children}
108+
</Text>
109+
</Pressable>
110+
);
111+
},
112112
);
113113

114114
const TabsContent = React.forwardRef<View, TabsContentProps>(
115-
({ value, children, className }, ref) => {
116-
const { value: selectedValue } = React.useContext(TabsContext);
117-
const isSelected = selectedValue === value;
118-
119-
if (!isSelected) return null;
120-
121-
return (
122-
<View ref={ref} className={cn("mt-4", className)}>
123-
{children}
124-
</View>
125-
);
126-
}
115+
({ value, children, className }, ref) => {
116+
const { value: selectedValue } = React.useContext(TabsContext);
117+
const isSelected = selectedValue === value;
118+
119+
if (!isSelected) return null;
120+
121+
return (
122+
<View ref={ref} className={cn("flex-1 mt-4", className)}>
123+
{children}
124+
</View>
125+
);
126+
},
127127
);
128128

129129
Tabs.displayName = "Tabs";
130130
TabsList.displayName = "TabsList";
131131
TabsTrigger.displayName = "TabsTrigger";
132132
TabsContent.displayName = "TabsContent";
133133

134-
export { Tabs, TabsList, TabsTrigger, TabsContent };
134+
export { Tabs, TabsContent, TabsList, TabsTrigger };

0 commit comments

Comments
 (0)