From 1c5ffd3bf968ce49ab768b989bfd513cfca7f1cb Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 27 Feb 2025 17:24:05 +0800 Subject: [PATCH] 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 --- .../src/components/layouts/tabbar/Tabbar.tsx | 25 +++++++++++-------- .../src/screens/(stack)/(tabs)/_layout.tsx | 20 ++------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx b/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx index 5e1f1f38c..c8341d29b 100644 --- a/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx +++ b/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx @@ -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 = (props) => { }) } } + const tabButton = options?.tabBarButton const label = typeof options?.tabBarLabel === "function" ? options?.tabBarLabel @@ -130,17 +131,19 @@ export const Tabbar: FC = (props) => { ) } + const TabButton = tabButton ?? Fragment return ( - + + + ) })} diff --git a/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx b/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx index fb3a0d0b6..3862b01cf 100644 --- a/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx +++ b/apps/mobile/src/screens/(stack)/(tabs)/_layout.tsx @@ -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 }, - tabBarButton(props) { - return - }, }} /> }, tabBarLabel: "Subscriptions", - - tabBarButton(props) { - return - }, }} /> }, - tabBarButton(props) { - return - }, }} /> @@ -93,13 +83,7 @@ export default function TabLayout() { title: "Settings", headerShown: false, tabBarButton(props) { - return ( - - - - - - ) + return {props.children} }, tabBarIcon: ({ color, focused }) => { const Icon = !focused ? Settings1CuteReIcon : Settings1CuteFiIcon