reactnative 底部tab页面@react-navigation/bottom-tabs

使用react-navigation/native做的页面导航和tab'

官网:https://reactnavigation.org/docs/getting-started

效果图

安装

javascript 复制代码
npm install @react-navigation/native

npm install @react-navigation/bottom-tabs

封装tabbar.js

javascript 复制代码
import { View, StyleSheet, Image } from "react-native";
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import React from 'react';
const Tab = createBottomTabNavigator();

import Home from "../views/home"
import Record from "../views/record";
import Sys from "../views/sys";
import {useState} from "react";
const dataSource = [
  {
    icon: require("../assets/images/tabbar/home-un.png"),  // 未选中图标
    selectedIcon: require("../assets/images/tabbar/home.png"), // 选择图标
    tabPage: 'Home',											// 名称
    tabName: '首页',											// 文字
    badge: 0,
    component:Home												// 页面
  },
  {
    icon: require("../assets/images/tabbar/record-un.png"),
    selectedIcon: require("../assets/images/tabbar/record.png"),
    tabPage: 'Record',
    tabName: '记录',
    badge: 0,
    component: Record
  },
  {
    icon: require("../assets/images/tabbar/sys-un.png"),
    selectedIcon: require("../assets/images/tabbar/sys.png"),
    tabPage: 'Sys',
    tabName: '系统',
    badge: 0,
    component: Sys
  }

];

let Index=()=>{
  const [selectedTab,setSelect]=useState('Home');
  return (
      <View style={{ flex: 1, backgroundColor: '#F5FCFF' }}>
        <Tab.Navigator >
          {dataSource.map((v, i) => {
            return (
                <Tab.Screen name={v.tabPage} component={v.component} key={i}  options={{ tabBarLabel: v.tabName,headerShown: false,tabBarIcon: ({ focused }) => (
                      <Image
                          source={focused ? v.selectedIcon : v.icon}
                          style={{ width: 30, height: 30 }}
                      />
                  ),tabBarActiveTintColor: '#59E0A7',
                  tabBarInactiveTintColor: '#5E5E5E'}}/>
            )
          })}
        </Tab.Navigator>
      </View>
  )
}

const stylesheet = StyleSheet.create({
  tab: {
    justifyContent: "center"
  },
  tabIcon: {
    color: "#999",
    width: 23,
    height: 23
  }
})
export default Index;

引入

在route,js中引入tabbar.js.设置默认展示Tarbar

javascript 复制代码
        <NavigationContainer>
            <Stack.Navigator
                screenOptions={{headerShown:false}}
                options={{ title: 'My home' }} initialRouteName="Tarbar" >
                {/*登录*/}
                <Stack.Screen name="Login" component={Login} />
                <Stack.Screen name="Tarbar" component={Tarbar} />
            </Stack.Navigator>
        </NavigationContainer>
相关推荐
爱lv行3 天前
生态:React Native
javascript·react native·react.js
少恭写代码5 天前
duxapp 2024-12-18更新 新增 Svg 组件 Tab 支持幻灯片切换功能
react native·小程序·taro
凌鲨6 天前
React Native学习路线图
学习·react native·react.js
一个处女座的程序猿O(∩_∩)O6 天前
四大跨平台开发框架深度解析——uniapp、uniapp-X、React Native与Flutter
flutter·react native·uni-app
苍岚丨晨苏6 天前
使用Taro开发iOS App触发额外权限请求的问题
react native·taro
Domain-zhuo8 天前
如何理解React State不可变性的原则
前端·javascript·react native·react.js·前端框架·ecmascript
wuwuFQ10 天前
React Native状态管理器Redux、MobX、Context API、useState
javascript·react native·react.js
爱lv行11 天前
创建 React Native 项目
javascript·react native·react.js
某柚啊11 天前
Hermes engine on React Native 0.72.5,function无法toString转成字符串
javascript·react native·react.js
Domain-zhuo12 天前
React的功能是什么?
前端·javascript·react native·react.js·前端框架·ecmascript