React-native Navigation之TabNavigator

React-native Navigation之TabNavigator

在0.44之后开始推荐使用React Navigation下的主键开发
这篇博客主要讲解React-Navigation之TabNavigator
开始工作第一步:导入新包,我使用的yarn add react-navigation,也有看到其他有使用npm添加的,但在我这里我没有成功,还是装了一个yarn
第二步:引入模块

import {TabNavigator,StackNavigator} from 'react-navigation';

第三步:配置tab

const MyApp = TabNavigator({
    Home: {
        screen: Home,
        navigationOptions: {//配置TabNavigator的一些属性
            tabBarLabel: '首页',//标签栏的title,这里设置的与标题一样,如不一样时可进行设置
            //设置标签栏的图标
            tabBarIcon: ({tintColor}) => (
                <Image
                    source={require('./res/images/home.png')}
                    style={[{tintColor: tintColor}, styles.icon]}
                />),
        }
    },
    Businessmen: {
        screen: Businessmen,
        navigationOptions: {
            tabBarLabel: '商家',
            tabBarIcon: ({ tintColor }) => (
                <Image
                    source={require('./res/images/businessmen.png')}
                    style={[styles.icon, {tintColor: tintColor}]}
                />
            ),
        }
    },
    Mine: {
        screen: Mine,
        navigationOptions: {
            tabBarLabel: '我的',
            tabBarIcon: ({ tintColor }) => (
                <Image
                    source={require('./res/images/mine.png')}
                    style={[styles.icon, {tintColor: tintColor}]}
                />
            ),
        }
    },
    More: {
        screen: More,
        navigationOptions: {
            tabBarLabel: '更多',
            tabBarIcon: ({ tintColor }) => (
                <Image
                    source={require('./res/images/more.png')}
                    style={[styles.icon, {tintColor: tintColor}]}
                />
            ),
        }
    },
},{
    animationEnabled: false, // 切换页面时不显示动画
    tabBarPosition: 'bottom', // 显示在底端,android 默认是显示在页面顶端的
    swipeEnabled: false, // 禁止左右滑动
    backBehavior: 'none', // 按 back 键是否跳转到第一个 Tab, none 为不跳转
    tabBarOptions: {//配置标签栏的一些属性
        activeTintColor: '#e91e63',// 文字和图片选中颜色
        inactiveTintColor: '#666', // 文字和图片默认颜色
        showIcon: true, // android 默认不显示 icon, 需要设置为 true 才会显示
        indicatorStyle: {height: 0}, // android 中TabBar下面会显示一条线,高度设为 0 后就不显示线了 暂时解决这个问题
        style: {    // 整个table的样式
            backgroundColor: '#F5FCFF', // TabBar 背景色
            height: 50,
        },
        tabStyle:{    // 单个table的样式
            // backgroundColor:'#ddd',
            padding: 0,//取消默认高度
            margin: 0,
        },
        //标签页图片显示区域样式
        iconStyle:{
            // backgroundColor:'blue',
            margin: 0,
        },
        labelStyle: {
            fontSize: 10, // 文字大小
            margin: 0,
        },

    },
});

我在使用的时候发现太牛币了,居然还能改变图标的颜色,难道是我少见多怪吗,哈哈,完成:)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值