首页 > 其他 > 详细

react-native底部导航栏实现

时间:2019-11-03 15:05:14      阅读:169      评论:0      收藏:0      [点我收藏+]
  1. react-native-tab-navigator实现:

    bottom.js代码如下:

    

import React, {Component} from ‘react‘;
import {StyleSheet, View,Text,Image} from ‘react-native‘;
import TabNavigator from ‘react-native-tab-navigator‘
 
export default class Bottom extends Component {
  /*初始化state*/
  constructor(props){
      super();
      this.state={
        selectedTab:‘tb_msg‘,
      }
  }
    /**
     * 公共组件方法
     * @param selectedTab 选中的tab
     * @param title
     * @param icon
     * @param selectedIcon
     * @param imageStyle  选中时渲染图标的颜色
     * @param mark  角标
     * @param viewContent  页面内容
     * @returns {*}
     */
  tabNavigatorItems(selectedTab,title,icon,selectedIcon,imageStyle,mark,viewContent){
      return (
          <TabNavigator.Item
              selected={this.state.selectedTab === selectedTab }
              title={title}
              renderIcon={()=> <Image style={styles.myImage} source={icon}/> }
              renderSelectedIcon={()=> <Image style={[styles.myImage,{tintColor:imageStyle}]} source={selectedIcon}/> }
              badgeText={mark}
              onPress={()=> this.setState({selectedTab:selectedTab}) }>
              <View style={{flex:1}}><Text>{viewContent}</Text></View>
          </TabNavigator.Item>
      )
  }
 
  render() {
    return (
      <View style={styles.container}>
         <TabNavigator>
            {this.tabNavigatorItems(‘tb_msg‘,"消息",require(‘../../assets/img/zhuye.png‘),require("../../assets/img/zhuyesl.png"),‘#622193‘,"","消息页面内容")}
            {this.tabNavigatorItems(‘tb_contacts‘,"联系人",require(‘../../assets/img/zhuye.png‘),require("../../assets/img/zhuye.png"),‘#65bb74‘,"","联系人页面内容")}
            {this.tabNavigatorItems(‘tb_watch‘,"看点",require(‘../../assets/img/zhuye.png‘),require("../../assets/img/zhuye.png"),‘#6ebef3‘,"","看点页面内容")}
            {this.tabNavigatorItems(‘tb_dynamic‘,"动态",require(‘../../assets/img/zhuye.png‘),require("../../assets/img/zhuye.png"),‘#622193‘,"","动态页面内容")}
         </TabNavigator>
      </View>
    );
  }
}
 
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: ‘#F5FCFF‘,
    },
    myImage:{
        width:22,
        height:22,
    }

});

        运行:react-native run-android

     技术分享图片

 

 

  运行结果:

  技术分享图片

 

 

   

react-native底部导航栏实现

原文:https://www.cnblogs.com/focusHots/p/11785843.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!