当前位置: 首页 > 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.xdnf.cn/news/1136899.html

相关文章:

  • 【开源软件推荐】 SmartSub,一个可以快速识别视频/音频字幕的工具
  • JavaScript进阶篇——第八章 原型链、深浅拷贝与原型继承全解析
  • 性能优化实践:Modbus 在高并发场景下的吞吐量提升(二)
  • 【Linux】第一个小程序—进度条
  • 自动化技术在造纸行业的应用:EtherCAT转PROFIBUS DP解决方案
  • 【中等】题解力扣22:括号生成
  • MyUI1.0全新现代化 Vue.js 组件库框架上线
  • HCIE - 云计算拿下后的职业选择如何规划?
  • 摩尔投票法:高效寻找数组中的多数元素
  • 基于在线地图的路径规划测评对比-综合对比城区、农村及城乡结合处的导航
  • 阿里云-通义灵码:隐私保护机制—为数据安全筑起铜墙铁壁
  • DolphinScheduler 如何高效调度 AnalyticDB on Spark 作业?
  • Flutter在Android studio运行出现Error: Entrypoint is not a Dart file
  • SpringBoot 使用MyBatisPlus
  • web APIs(更新中)
  • 【机器学习实战【七】】机器学习特征选定与评估
  • 聚类算法原理与应用(一):K-means聚类算法原理
  • 基础算法题
  • 如何轻松玩转多线程高并发?
  • Install Docker Engine on UbuntuMySQL
  • cdh6.3.2的hive使用apache paimon格式只能创建不能写报错的问题
  • Python包测试全攻略:从单元测试到持续集成
  • ZKmall开源商城架构助力增长:多端流量聚合与用户体验
  • GitHub开源轻量级语音模型 Vui:重塑边缘智能语音交互的未来
  • Python 网络爬虫 —— 提交信息到网页
  • 音视频同步技术初剖析:原理、实现与FFmpeg分析
  • CrewAI与LangGraph:下一代智能体编排平台深度测评
  • 深度学习前置知识
  • PyTorch边界感知上下文神经网络BA-Net在医学图像分割中的应用
  • ubuntu基础搭建