React Native之TabBar的簡單搭建

先上效果動態(tài)圖

Untitled.gif

代碼附上:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  TabBarIOS
} from 'react-native';

var test5 = React.createClass({
  
  //設置初始值
  getInitialState(){
    return{
      //默認選擇的item
    selectTabBarItem:'home',
    }
  },
  
  
  render() {
    return (
            <View style={styles.container}>
            <View style={styles.headStyle}>
            <Text style={{color:'white'}}>Tab選項卡</Text>
            </View>
            
            
            <TabBarIOS
            barTintColor='black'
            //tintColor='purple'
            >
            
            {/*第一*/}
            <TabBarIOS.Item
            systemIcon="contacts"
            badge="3"
            title="張三"
            selected={this.state.selectTabBarItem == 'home'}
            onPress = {()=>{this.setState({selectTabBarItem:'home'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'red'}] }>
            <Text style={{color:'white'}}>首頁</Text>
            </View>
            
            </TabBarIOS.Item>
            
            
            
            {/*第2*/}
            <TabBarIOS.Item
            systemIcon="bookmarks"
            selected={this.state.selectTabBarItem == 'second'}
            onPress = {()=>{this.setState({selectTabBarItem:'second'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'blue'}]}>
            <Text style={{color:'white'}}>2頁</Text>
            </View>
            </TabBarIOS.Item>
            
            
            {/*第3*/}
            <TabBarIOS.Item
            systemIcon="downloads"
            selected={this.state.selectTabBarItem == 'three'}
            onPress = {()=>{this.setState({selectTabBarItem:'three'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'yellow'}]}>
            <Text style={{color:'white'}}>3頁</Text>
            </View>
            </TabBarIOS.Item>
            
            
            {/*第4*/}
            <TabBarIOS.Item
            systemIcon="search"
            selected={this.state.selectTabBarItem == 'four'}
            onPress = {()=>{this.setState({selectTabBarItem:'four'})}}
            >
            <View style={[styles.commonViewStyle,{backgroundColor:'purple'}]}>
            <Text style={{color:'white'}}>4頁</Text>
            </View>
            </TabBarIOS.Item>
            
            
            </TabBarIOS>
            
            </View>
            );
  }
})

const styles = StyleSheet.create({
container: {
  
flex:1,
  
backgroundColor: '#F5FCFF',
},
headStyle:{
height:64,
backgroundColor:'black',
justifyContent:'center',
alignItems:'center'
},
commonViewStyle:{
flex:1,
justifyContent:'center',
alignItems:'center'
  
}
  
});

AppRegistry.registerComponent('test5', () => test5);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容