feat(mobile): enhance Tabbar and Tab Layout with custom tab buttons
- Add support for custom tab buttons in Tabbar component - Modify tab layout to use custom tab button rendering - Wrap tab items with optional custom tab button component Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import type { BottomTabBarProps } from "@react-navigation/bottom-tabs"
|
||||
import { getLabel } from "@react-navigation/elements"
|
||||
import { CommonActions, NavigationContext, NavigationRouteContext } from "@react-navigation/native"
|
||||
import type { FC } from "react"
|
||||
import { memo, useContext, useEffect } from "react"
|
||||
import { Fragment, memo, useContext, useEffect } from "react"
|
||||
import type { StyleProp, TextStyle } from "react-native"
|
||||
import { Platform, Pressable, StyleSheet, View } from "react-native"
|
||||
import Animated, {
|
||||
@@ -75,6 +75,7 @@ export const Tabbar: FC<BottomTabBarProps> = (props) => {
|
||||
})
|
||||
}
|
||||
}
|
||||
const tabButton = options?.tabBarButton
|
||||
const label =
|
||||
typeof options?.tabBarLabel === "function"
|
||||
? options?.tabBarLabel
|
||||
@@ -130,17 +131,19 @@ export const Tabbar: FC<BottomTabBarProps> = (props) => {
|
||||
)
|
||||
}
|
||||
|
||||
const TabButton = tabButton ?? Fragment
|
||||
return (
|
||||
<TabItem
|
||||
key={route.key}
|
||||
route={route}
|
||||
focused={focused}
|
||||
descriptors={descriptors}
|
||||
onPress={onPress}
|
||||
originalRenderIcon={renderIcon}
|
||||
originalRenderLabel={renderLabel}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
<TabButton key={route.key}>
|
||||
<TabItem
|
||||
route={route}
|
||||
focused={focused}
|
||||
descriptors={descriptors}
|
||||
onPress={onPress}
|
||||
originalRenderIcon={renderIcon}
|
||||
originalRenderLabel={renderLabel}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
</TabButton>
|
||||
)
|
||||
})}
|
||||
</Grid>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { router, Stack, Tabs } from "expo-router"
|
||||
import { Easing, Pressable, View } from "react-native"
|
||||
import { Easing } from "react-native"
|
||||
import { Gesture, GestureDetector } from "react-native-gesture-handler"
|
||||
import { runOnJS } from "react-native-reanimated"
|
||||
|
||||
@@ -51,9 +51,6 @@ export default function TabLayout() {
|
||||
const Icon = !focused ? Home5CuteReIcon : Home5CuteFiIcon
|
||||
return <Icon color={color} width={24} height={24} />
|
||||
},
|
||||
tabBarButton(props) {
|
||||
return <Pressable {...props} />
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
@@ -66,10 +63,6 @@ export default function TabLayout() {
|
||||
return <Icon color={color} width={24} height={24} />
|
||||
},
|
||||
tabBarLabel: "Subscriptions",
|
||||
|
||||
tabBarButton(props) {
|
||||
return <Pressable {...props} />
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<Tabs.Screen
|
||||
@@ -81,9 +74,6 @@ export default function TabLayout() {
|
||||
const Icon = !focused ? Search3CuteReIcon : Search3CuteFiIcon
|
||||
return <Icon color={color} width={24} height={24} />
|
||||
},
|
||||
tabBarButton(props) {
|
||||
return <Pressable {...props} />
|
||||
},
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -93,13 +83,7 @@ export default function TabLayout() {
|
||||
title: "Settings",
|
||||
headerShown: false,
|
||||
tabBarButton(props) {
|
||||
return (
|
||||
<GestureDetector gesture={fifthTap}>
|
||||
<View className="flex-1">
|
||||
<Pressable {...props} />
|
||||
</View>
|
||||
</GestureDetector>
|
||||
)
|
||||
return <GestureDetector gesture={fifthTap}>{props.children}</GestureDetector>
|
||||
},
|
||||
tabBarIcon: ({ color, focused }) => {
|
||||
const Icon = !focused ? Settings1CuteReIcon : Settings1CuteFiIcon
|
||||
|
||||
Reference in New Issue
Block a user