react-native - 在反应本机选项卡导航中将指示器边框应用于选定选项卡
问题描述
我正在尝试将顶部边框应用于反应(本机)选项卡导航中的选定选项卡,但无法弄清楚。
我在其他解决方案中看到有一个“indicatorStyle”,但我无法添加它,看起来它已被弃用或其他东西。
请看下面的图片和代码:
我的标签导航器:
所需的选项卡导航器示例:
这是我的标签导航器:
import * as React from 'react';
import { Text, View, Dimensions } from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import {mainColor, seperatorColor, textColor} from '../../styles'
//Components stacks
import HomeStackScreens from './HomeStack'
import JoinStackScreens from './JoinStack'
import ProfileStackScreens from './ProfileStack'
import CreateRideStackScreens from './CreateRideStack'
import {homeIcon, profileIcon, messagesIcon, addRideIcon, JoinIcon} from '../../components/global/Icons'
import {navigationConsts, stackNavigationsConsts} from '../../constants/NavigationConsts'
import { color } from 'react-native-reanimated';
function DetailsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Details!12</Text>
</View>
);
}
const AnotherStack = createStackNavigator();
function AnotherStackScreen() {
return (
<AnotherStack.Navigator>
<AnotherStack.Screen name="Details" component={DetailsScreen} />
</AnotherStack.Navigator>
);
}
const Tab = createBottomTabNavigator();
export default function MainTabNavigator() {
return (
<Tab.Navigator
initialRouteName={stackNavigationsConsts.HOME_STACK}
tabBarOptions={{
tabStyle:{
borderTopColor:mainColor.MainBackgroundColor,
// borderTopWidth:1.2,
// paddingVertical: 2,
},
activeTintColor: mainColor.MainBackgroundColor,
inactiveTintColor: textColor.tabIcon,
activeBackgroundColor: mainColor.backgroundColorWhite,
inactiveBackgroundColor: mainColor.backgroundColorWhite,
keyboardHidesTabBar: true,
showLabel: false,
borderTopWidth:24,
borderTopColor:'red'
}}
>
<Tab.Screen name={stackNavigationsConsts.HOME_STACK} component={HomeStackScreens}
options={{
tabBarLabel: navigationConsts.HOME,
tabBarIcon: ({ color, size }) => (
homeIcon(color)
),
}}
tabStyle={{
borderTopWidth:24,
borderTopColor:'red'
}}
/>
<Tab.Screen name={stackNavigationsConsts.PROFILE_STACK} component={ProfileStackScreens} options={{
tabBarLabel: navigationConsts.PROFILE ,
tabBarIcon: ({ color, size }) => (
profileIcon(color)
),
}}/>
<Tab.Screen name={stackNavigationsConsts.JOIN_STACK} component={JoinStackScreens}
options={{
tabBarLabel: navigationConsts.JOIN ,
tabBarIcon: ({ color, size }) => (
JoinIcon(color)
),
}}/>
<Tab.Screen name={stackNavigationsConsts.NOTIFICATIONS_STACK} component={AnotherStackScreen} options={{
tabBarLabel: navigationConsts.NOTIFICATIONS ,
tabBarIcon: ({ color, size }) => (
messagesIcon(color)
),
tabBarBadge: 12
}}/>
<Tab.Screen name={stackNavigationsConsts.ADD_RIDE_STACK} component={CreateRideStackScreens} options={{
tabBarLabel: navigationConsts.ADD_RIDE ,
tabBarIcon: ({ color, size, focused }) => (
addRideIcon(color)
),
}}/>
</Tab.Navigator>
);
}
解决方案
解决方案是创建一个自定义的 TabBar 组件,并在创建选项卡屏幕时将其作为选项卡中的 tabBarButton 传递。
您可以在此线程中查看答案 -如何在当前选项卡在反应导航 5 中处于活动状态时在底部选项卡顶部添加一行
推荐阅读
- c# - WPF 获取发件人的窗口
- php - nusoap 客户端无法运行
- php - Laravel Annotation 扫描路线不起作用
- sql - 如何在客户下订单且每个订单包含多个食物的餐厅场景中设计星型模式
- stimulsoft - 根据条件在 stimulsoft 报告中隐藏乐队
- android - 无法在自定义 ListView 中将 onItemClickListener 设置为 CheckBox
- sql - 获取用户的名字、城市和当月乘坐的次数
- ruby-on-rails - Rails:回形针上传时 AWS S3 访问被拒绝错误
- python - Python 如果它的相同输出不发送消息
- ajax - 通过laravel中的ajax在表中显示来自sql查询的数据