当前位置: 首页 > news >正文

React Native 基础tabBar和自定义tabBar - bottom-tabs

一、基础TabBar
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'// ...
const BottomTabBar = createBottomTabNavigator()return (<View style={{width: '100%', height: '100%'}}><BottomTabBar.NavigatorscreenOptions={({route}) => {console.log('res:', route)return {tabBarIcon: ({focused, color, size}) => {let name = focused ? `${route.name}Active` : route.namereturn (<Image style={{width: size, height: size, tintColor: color}}source={IconTabMap[name]} />)}}}}  ><BottomTabBar.Screenname='Home'component={Home}options={{title: '首页',headerShown: false,tabBarActiveTintColor: '#ff2442',tabBarInactiveTintColor: '#999'}}/><BottomTabBar.Screenname='Shop'component={Shop}options={{title: '购物车',headerShown: false,tabBarActiveTintColor: '#ff2442',tabBarInactiveTintColor: '#999'}}/><BottomTabBar.Screenname='Message'component={Message}options={{title: '消息',headerShown: false,tabBarActiveTintColor: '#ff2442',tabBarInactiveTintColor: '#999'}}/><BottomTabBar.Screenname='Mine'component={Mine}options={{title: '我的',headerShown: false,tabBarActiveTintColor: '#ff2442',tabBarInactiveTintColor: '#999'}}/></BottomTabBar.Navigator></View>
)

在这里插入图片描述

二、自定义TabBar
const TabBarRender = ({state, descriptors, navigation}) => {// index:当前选中const { routes, index } = statereturn (<View style={styles.tabBar}>{routes.map((route, i) => {// route -> {key, name, params}// descriptors->{key值: {navigation, options(Screen上的options值), route, render}}console.log('descriptors', descriptors[route.key])const { options: { title } } = descriptors[route.key]const isActive = index === iif (i === 2) {return (<TouchableOpacityactiveOpacity={0.7}onPress={() => {// ....}}><Imagestyle={styles.img}source={IconAdd}/></TouchableOpacity>)}return (<TouchableOpacitystyle={styles.tabItem}key={`tab-item-${i}`}activeOpacity={0.7}onPress={() => {navigation.navigate(route.name)}}><Text style={[styles.text, isActive ? styles.textActive : {}]}>{ title }</Text></TouchableOpacity>)})}</View>)}// ...
<BottomTabBar.NavigatortabBar={props => <TabBarRender {...props} />} // 自定义
><BottomTabBar.Screenname='Home'component={Home}options={{title: '首页',headerShown: false,}}/><BottomTabBar.Screenname='Shop'component={Shop}options={{title: '购物车',headerShown: false,}}/><BottomTab.Screenname='Add'component={Shop}options={{title: '新增',headerShown: false,}}/><BottomTabBar.Screenname='Message'component={Message}options={{title: '消息',headerShown: false,}}/><BottomTabBar.Screenname='Mine'component={Mine}options={{title: '我的',headerShown: false,}}/>
</BottomTabBar.Navigator>

在这里插入图片描述

http://www.lryc.cn/news/591173.html

相关文章:

  • React hooks——useMemo
  • Android离线TTS实战——集成espeak-ng实现开箱即用的中文语音播报
  • Flutter:上传图片,选择相机或相册:wechat_assets_picker
  • 玖[9],相机/镜头/光源
  • 2021-07-21 VB窗体求范围质数(Excel复制工作簿)
  • Java使用FastExcel实现模板写入导出(多级表头)
  • 在Anaconda Prompt中安装库【保姆教程】
  • 使用flock单进程启动,仍然有多个同名进程可以同时运行
  • 苹果的机器学习框架将支持英伟达的CUDA平台
  • web后端开发(javaweb第十天)
  • 【后端】Linux系统发布.NetCore项目
  • suricata新增Mysql告警规则处理
  • Zemax坐标断点
  • GitHub开源轻量级语音模型 Vui:重塑边缘智能语音交互的未来
  • 【git 如何查看本地分支与远程分支之间的差异】
  • Oracle11.2.0.4 RAC迁移升级Oracle19.3 RAC
  • 单片机(STM32-时钟系统)
  • AI 智能质检系统在汽车制造企业的应用​
  • select_shape_proto 用起来很省事
  • 错误 0x80370102排查
  • CCLink IE转ModbusTCP网关配置无纸记录器(中篇)
  • 大语言模型系列(1): 3分钟上手,在骁龙AI PC上部署DeepSeek!
  • uniapp云托管前端网页
  • CentOS在线安装docker教程
  • 人工智能概念之八:常见的参数调优方法(交叉验证网格搜索、随机优化、贝叶斯优化、Hyperband优化)
  • npm 和 npx 区别对比
  • Django `transaction.atomic()` 完整使用指南
  • Java行为型模式---命令模式
  • Visual Studio 的常用快捷键
  • 自定义 django 中间件