Skip to content

Commit 7b5dee1

Browse files
authored
Add iconPosition prop to tab view (#899)
1 parent 5968753 commit 7b5dee1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/core/src/components/TabView/TabView.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type TabBarProps = SceneRendererProps & {
2222
};
2323
type TabBarPosition = "top" | "bottom";
2424
type KeyboardDismissMode = "none" | "auto" | "on-drag";
25+
type IconPosition = "top" | "bottom" | "left" | "right";
2526

2627
type TabViewProps = {
2728
onIndexChanged?: (index: number) => void;
@@ -37,6 +38,7 @@ type TabViewProps = {
3738
indicatorColor?: string;
3839
tabsBackgroundColor?: string;
3940
iconSize?: number;
41+
iconPosition?: IconPosition;
4042
style?: StyleProp<ViewStyle | TextStyle>;
4143
theme: Theme;
4244
} & IconSlot;
@@ -56,6 +58,7 @@ const TabViewComponent: React.FC<React.PropsWithChildren<TabViewProps>> = ({
5658
indicatorColor,
5759
tabsBackgroundColor,
5860
iconSize = 16,
61+
iconPosition = "top",
5962
style,
6063
theme,
6164
children: childrenProp,
@@ -101,6 +104,21 @@ const TabViewComponent: React.FC<React.PropsWithChildren<TabViewProps>> = ({
101104
};
102105

103106
const renderTabBar: React.FC<TabBarProps> = (props) => {
107+
let tabFlexDirection: "row" | "column" | "row-reverse" | "column-reverse";
108+
switch (iconPosition) {
109+
case "top":
110+
tabFlexDirection = "column";
111+
break;
112+
case "bottom":
113+
tabFlexDirection = "column-reverse";
114+
break;
115+
case "left":
116+
tabFlexDirection = "row";
117+
break;
118+
case "right":
119+
tabFlexDirection = "row-reverse";
120+
break;
121+
}
104122
return (
105123
<TabBar
106124
{...props}
@@ -112,6 +130,7 @@ const TabViewComponent: React.FC<React.PropsWithChildren<TabViewProps>> = ({
112130
backgroundColor: indicatorColor || theme.colors.primary,
113131
}}
114132
labelStyle={[{ textTransform: "none" }, textStyles]}
133+
tabStyle={{ flexDirection: tabFlexDirection }}
115134
renderIcon={({ route, color }) =>
116135
route?.icon ? (
117136
<Icon name={route.icon} color={color} size={iconSize} />

0 commit comments

Comments
 (0)