博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
十二、实战底部(二)
阅读量:7128 次
发布时间:2019-06-28

本文共 4181 字,大约阅读时间需要 13 分钟。

1.顶部导航 为了适配安卓和iOS两个平台使用facebook的第三发组件,组件的导入的方式在十一讲有提到,具体可参考

组件名称:react-native-tab-navigator 导入的命令:npm I react-native-tab-navigator --save 需要导入的组件:

  • Platform, // 判断当前运行的系统
  • Navigator

e.g.:

// 每一个TabBarItem    renderTabBarItem(title, iconName, selectedIconName, selectedTab, componentName, component, badgeText){        return(            
} // 图标 renderSelectedIcon={() =>
} // 选中的图标 onPress={()=>{this.setState({selectedTab:selectedTab})}} selected={this.state.selectedTab === selectedTab} selectedTitleStyle={styles.selectedTitleStyle} badgeText = {badgeText} >
{// 过渡动画 return Navigator.SceneConfigs.PushFromRight; }} renderScene={(route,navigator)=>{ let Component = route.component; return
; }} />
) }复制代码

e.g:

/** * Created by hjq on 2017/4/3. */import React, { Component } from 'react';import {    AppRegistry,    StyleSheet,    Text,    View,    Image,    Navigator,    Platform, // 主要用来判断系统版本的    Alert} from 'react-native';// 导入外部组件import TabNavigator from 'react-native-tab-navigator';import Util from './Util';// 导入主要的组件var Home = require('../Home/JQHome');var More = require('../More/JQMore');var Mine = require('../Mine/JQMine');var Shop = require('../Shop/JQShop');var JQMain = React.createClass({    getInitialState() {        return {            selectedTab: 'home' // 默认选择第一个        }    },    render() {        return (            
{/*首页**/} {this.renderTabItem('首页', 'icon_tabbar_homepage', 'icon_tabbar_homepage_selected','home','首页', Home,'')} {/*店铺**/} {this.renderTabItem('店铺', 'icon_tabbar_merchant_normal', 'icon_tabbar_merchant_selected','shop','店铺', Shop, '20')} {/*我的**/} {this.renderTabItem('我的', 'icon_tabbar_mine', 'icon_tabbar_mine_selected','mine','我的', Mine, '88')} {/*更多**/} {this.renderTabItem('更多', 'icon_tabbar_misc', 'icon_tabbar_misc_selected','more','更多', More, '199')}
); }, // 每一个组件的item renderTabItem (title, iconName, selectedIconName, selectedTab, componentName, component, badgeText) { return (
} renderSelectedIcon={() =>
} badgeText={badgeText} selected={this.state.selectedTab === selectedTab} selectedTitleStyle={styles.selectedTitleStyle} titleStyle={styles.titleStyle} renderBadge={() => this.customBadgeView(badgeText)} onPress={() => this.setState({ selectedTab: selectedTab })}>
{// 过渡动画 return Navigator.SceneConfigs.PushFromRight; }} renderScene={(route,navigator)=>{ let Component = route.component; return
; }} />
) }, // 自定义BageView customBadgeView(badgeText) { return ( badgeText ?
{badgeText}
: null ); }});const styles = StyleSheet.create({ iconStyle: { // 如果图片不设置大小显示不了 width: (Platform.OS === 'ios') ? 30 : 25, height: (Platform.OS === 'ios') ? 30 : 25, }, titleStyle: { // tabbar默认的颜色 color: 'black' }, selectedTitleStyle: { // tabbar选中的颜色 color: 'orange' }, renderBadgeStyle: { backgroundColor: 'red' }, customBadgeViewStyle: { marginTop: 5, width:21, height:21, justifyContent:'center', alignItems: 'center', backgroundColor: 'red', borderRadius: 10.5, overflow: 'hidden' }, customBadgeTextStyle: { color: 'white', fontSize: 12 }});// 输出组件module.exports = JQMain;复制代码

转载地址:http://nxael.baihongyu.com/

你可能感兴趣的文章
DCD DSR DTR RTS CTS 的含义
查看>>
OpenTest:教你在自动化脚本中增加选择文件的支持
查看>>
关于安装ASPNetExtMVC2008.exe 后不出现MVC项目的问题
查看>>
强烈推荐ISCSI target和initiator软件
查看>>
企业服务经验总结--服务器安全细则2
查看>>
python中时间的加n和减n运算
查看>>
软件开发人员应具备的基本素质 !!!
查看>>
无线运维——J2ME和WAP运维方式的优缺点
查看>>
生产环境Shell脚本Ping监控主机是否存活(多种方法)
查看>>
关于SQLServer2000中触发器的使用——多行数据提交
查看>>
commons-fileupload 1.3.1 上传测试
查看>>
红帽集群套件RHCS四部曲(概念篇)
查看>>
TFS配置(二)
查看>>
GeoServer地图开发解决方案(五):基于Silverlight技术的地图客户端实现
查看>>
Android应用程序键盘(Keyboard)消息处理机制分析(3)
查看>>
Linux上连接Microsoft SQL Server 2005
查看>>
私有云管理-Windows Azure Pack
查看>>
Linux下文件和目录的颜色代表的含义
查看>>
Forefront Client Security服务器部署
查看>>
Crystal Reports中的字段
查看>>