ReactNative TabBarIOS和NavigatorIOS

TabBarIOS.png

1、TabBarIOS的使用

import React, { Component } from 'react';
import {    
   AppRegistry,  
   StyleSheet,   
   TabBarIOS, 
   NavigatorIOS,   
   Text,  
   View } from 'react-native';  
 import MessageView from './MessageView';
 import ReleaseView from './ReleaseView';  
 import HomeView from './HomeView';
export default class MainView extends Component {      
    constructor(props) {      
        super(props);       
        this.state =  {         
             selectedTab: 'Home',         
             notifCount: 0,          
            presses: 0,      
       };    
    }
   render() {   
         var _this=this;   
         return (   
              <TabBarIOS 
                       unselectedTintColor="#000000" 
                       tintColor="#000000" 
                       barTintColor="#F5F5F5">     
                  <TabBarIOS.Item 
                       title="首页"
                       icon={require('../images/Home.png')}
                       selectedIcon={require('../images/HomeSelected.png')} 
                       renderAsOriginal  
                       selected={this.state.selectedTab === 'Home'} 
                       onPress={() => { 
                                                      this.setState({    
                                                             selectedTab: 'Home',     
                                                       });           
                    }}>              
                  <NavigatorIOS          
                          style={{flex: 1}}                
                          navigationBarHidden={true}     
                          initialRoute={{           
                                                    title: "首页",                             
                                                    component: HomeView,   
                                                    passProps: { myProp: _this },                    
                                                  }}              
                      />         
                  </TabBarIOS.Item>       
                  <TabBarIOS.Item             
                       title="发布"           
                       icon={require('../images/ReleaseGoods.png')}   
                       selectedIcon={require('../images/ReleaseGoodsSelected.png')}    
                     renderAsOriginal             
                     selected={this.state.selectedTab === 'Release'}  
                     onPress={() => {                  
                                  this.setState({        
                                                         selectedTab: 'Release',    
                                                         notifCount: this.state.notifCount + 1,                 
                                                         });        
                    }}>           
                    <NavigatorIOS             
                               style={{flex: 1}}                 
                               initialRoute={{                    
                                                         title: "发布",   
                                                        component: ReleaseView   
                                                      } }
                      />          
                   </TabBarIOS.Item>      
                   <TabBarIOS.Item              
                             title="消息"             
                             icon={require('../images/Message.png')}                
                             selectedIcon={require('../images/MessageSelected.png')}              
                             badge={this.state.notifCount > 0 ? this.state.notifCount : undefined}               
                             renderAsOriginal            
                             selected={this.state.selectedTab === 'Message'} 
                             onPress={() => {         
                                                         this.setState({    
                                                                    selectedTab: 'Message',  
                                                                    notifCount: this.state.notifCount + 1,              
                                                          });             
                                                  }}
                      >                
                    <NavigatorIOS                 
                                  style={{flex: 1}}       
                                  initialRoute={{                
                                                           title: "消息", 
                                                            component: MessageView                            
                                                         }}
                      />            
                    </TabBarIOS.Item>    
                    </TabBarIOS>   
 );
};
}

2、首页页面的搭建

import React, { Component } from 'react'; 
import {   
       StyleSheet,  
       View,  
       Navigator, 
       Text, 
       TouchableOpacity,  
       Image,   
       StatusBar,  
       AsyncStorage} from 'react-native';
import LoginView from './LoginView';import Util from './Util';
import NetUtil from './NetUtil';
export default class HomeView extends Component {   
              constructor(props) {     
                       super(props);      
                       this.state = {     
                                    member_avatar:'https://facebook.github.io/react/img/logo_og.png',                     
                                    member_nickname:'用户昵称',         
                                    store_name:'店铺名称',         
                                    store_id:'0',          
                                    sumOrder:'',      
                                    count:'',       
                                    sum:'',      
                                    amountTitle:'',      
                                    registerTitle:'',       
                                    inviteTitle:'',         
                                    amount_rank:'0',       
                                    register_rank:'0',      
                                    invite_rank:'0',    
                                  };    
}   
 componentDidMount() {       
           var _this=this;       
          AsyncStorage.getItem('member_avatar').then((value) => { 
               if (value !== null){       
                      _this.setState({                 
                             member_avatar:value,            
                           })              
              }}).done();    
          AsyncStorage.getItem('member_nickname').then((value) => {                
              if (value !== null){                 
                        _this.setState({         
                                  member_nickname:value,           
                       })          
             }}).done();     
          AsyncStorage.getItem('store_name').then((value) => {    
              if (value !== null){          
                      _this.setState({              
                             store_name:value,                 
                     })             
            }}).done();     
           AsyncStorage.getItem('store_id').then((value) => {      
                  if (value !== null){                  
                            _this.setState({           
                                     store_id:value,            
                             })            
             }}).done();  
           let data={'store_id':this.state.store_id};       
           let url='http://192.168.0.85/mobile/index.php?act=manager_store&op=datas_invite';       
           var common=NetUtil.commonParamsWithAct('manager_store','datas_invite');         
            NetUtil.post(url,data,common,function (set){    
                       if(set.code==10000){        
                              _this.setState({               
                                      sumOrder:(_this.progressLength(set.datas.sumOrder)).progress,    
                                      count:(_this.userProgressLength(set.datas.count)).progress,     
                                      sum:(_this.progressLength(set.datas.sum)).progress,    
                                      amountTitle:(_this.progressLength(set.datas.sumOrder)).title,  
                                      registerTitle:(_this.progressLength(set.datas.count)).title,    
                                      inviteTitle:(_this.progressLength(set.datas.sum)).title,    
                                      amount_rank:set.datas.amount_rank,      
                                      register_rank:set.datas.register_rank,      
                                      invite_rank:set.datas.invite_rank,        
                                  })             
                        }else{               
                            alert("网络繁忙,请稍后");           
                       }          
        });   
}   
 // 进度条计算   
progressLength(money){     
           var progress=0;  
           var title=money+"/100k";    
           if (money>0 && money<=100000) {//10万    
                     if(money>10000){        
                             progress=money/100000.0;      
                             title=money+"/100k";    
                     }else{        
                             progress=0.1;     
                    }      
            }else if(money>100000 && money<=1000000) {//100万      
                     if(money>100000){     
                             progress=money/1000000.0;   
                             title=money+"/1000k";      
                      }else{          
                             progress=0.1;      
                      }        
             }else if(money>1000000 && money<=10000000) {//1000万            
                     if(money>1000000){        
                               progress=money/10000000.0;      
                               title=money+"/10000k";         
                     }else{             
                               progress=0.1;      
                     }      
            }else if(money>10000000 && money<=100000000) {//1亿   
                    if(money>10000000){       
                               progress=money/100000000.0;     
                               title=money+"/100000k";         
                    }else{            
                              progress=0.1;   
                    }    
            }else if(money>100000000 && money<=1000000000) {//10亿           
                    if(money>100000000){        
                               progress=money/1000000000.0;      
                               title=money+"/1000000k";        
                    }else{            
                               progress=0.1;      
                    }    
           }    
           return {"progress": progress,"title":title};
    } 
 userProgressLength(count){ 
              var progress=0.0;   
              var title=count+"/10"; 
              if (count>0&&count<=10) {     
                         progress=count/10.0;    
                         title=count+"/10";   
              }else if(count>10&&count<=100) {    
                         progress=count/100.0;     
                         title=count+"/100"; 
              }else if(count>100&&count<=1000) {   
                         progress=count/1000.0;     
                         title=count+"/1K"; 
               }else if(count>1000&&count<=10000) {   
                        progress=count/10000.0;    
                        title=count+"/10k";   
              } else if(count>10000&&count<=100000) {    
                        progress=count/100000.0;      
                        title=count+"/100k";  
              }else if(count>100000&&count<=1000000) {  
                       progress=count/1000000.0;      
                       title=count+"/1000k";   
             }   
           return {"progress":progress,"title":title};
}    
//退出登录  
  exit(){      
        Util.saveItem('IsLogin','NO');    
         this.props.myProp.props.navigator.push({     
                    title: '登录',          
                    component:LoginView,  
         });  
  }  
  render() {      
          var Dimensions = require('Dimensions');    
          var {width, height} = Dimensions.get('window');     
          var _this=this;       
          return (           
                 <View style={styles.container}>        
                      <StatusBar 
                         backgroundColor="white"    
                         barStyle="light-content"/>   
                       <View style={[{width:width} ,styles.headerView]}>      
                            <Image source={{uri:_this.state.member_avatar}}
                                     style={styles.headerImage}>
                            </Image>                 
                            <Text style={styles.userNameText}> 
                                  {_this.state.member_nickname}
                            </Text>                   
                           <Text style={styles.storeNameText}>
                                 店铺名称: {_this.state.store_name}
                           </Text>            
                           <TouchableOpacity onPress={this.exit.bind(_this)}>  
                                  <Text style={styles.exitBtn}>退出</Text>      
                           </TouchableOpacity>            
                  </View>           
                  <View style={styles.showView}>    
                           <Text style={{top:10,left:10}}>身价</Text>    
                           <View  style={{top:-5,
                                                     left:50,
                                                     width:width-130,
                                                     height:14,
                                                     backgroundColor:'#D3D3D3',
                                                     borderRadius:7
                                    }}>
                            </View>                 
                            <View  style={{top:-19,
                                                      left:50, 
                                                      width:(width-130)*this.state.sumOrder,
                                                      height:14,
                                                      backgroundColor:'#FFFF00',
                                                      borderRadius:7
                                    }}>
                            </View>               
                           <Text style={[styles.titleShow,{top:-32}]}>
                                      {this.state.amountTitle}
                            </Text>             
                            <Text style={{top:-46,left:width-70}}>
                                        排名
                                      <Text style={{color:'red'}}>     
                                            {this.state.amount_rank}
                                      </Text>
                             </Text>                
                            <Text style={{top:-17,left:10}}> 
                                      魅力
                            </Text>   
                            <View  style={{top:-31,
                                                      left:50,
                                                      width:width-130,
                                                      height:14,
                                                      backgroundColor:'#D3D3D3',
                                                      borderRadius:7
                                       }}>
                             </View>                    
                             <View  style={{top:-45,
                                            left:50,
                                            width:(width-130)*this.state.count,
                                            height:14,
                                            backgroundColor:'#4169E1',
                                            borderRadius:7
                             }}>
                           </View>        
                           <Text style={[styles.titleShow,{top:-58}]}> 
                                             {this.state.registerTitle}
                           </Text>                    
                           <Text  style={{top:-72,left:width-70}}>
                                        排名
                                  <Text style={{color:'red'}}>
                                            {this.state.register_rank}
                                  </Text>
                           </Text>                   
                           <Text style={{top:-45,left:10}}>声望</Text>          
                           <View  style={{top:-59,
                                          left:50,
                                          width:width-130,
                                          height:14,
                                          backgroundColor:'#D3D3D3',
                                          borderRadius:7
                                    }}>
                          </View>                   
                          <View  style={{top:-73,
                                         left:50,width:(width-130)*this.state.sum,
                                         height:14,
                                         backgroundColor:'#2E8B57',
                                         borderRadius:7
                                 }}>
                       </View>                
                       <Text style={[styles.titleShow,{top:-86}]}>
                                      {this.state.inviteTitle}
                       </Text>               
                      <Text  style={{top:-100,left:width-70}}>
                                    排名
                                <Text style={{color:'red'}}>
                                              {this.state.invite_rank}
                                </Text>
                      </Text>            
          </View>            
         <Image source={require('../images/doImage.png')} 
                      style={styles.doImage}>
         </Image>            
   </View>       
 );  
  }
}
const styles = StyleSheet.create({    
         container: {    
                    flex: 1,      
                    backgroundColor: '#D3D3D3', 
               },   
         headerView:{   
                   backgroundColor: '#000000',       
                   height:100,    
                   marginTop:0, 
              },   
         headerImage:{     
                  height:60,      
                  width:60,      
                  marginTop:35,   
                  marginLeft:20,    
                  borderRadius: 30,    
                  borderColor:'white',     
                  borderWidth:1
           },    
         userNameText:{   
                color:'white',     
                fontSize:16,    
                marginLeft:85,   
                top:-55,   
            },  
          storeNameText:{    
              color:'white',   
              fontSize:16,    
              marginLeft:85,    
              top:-45,  
           },  
         exitBtn:{     
             color:'red',      
             fontSize:16,    
             width:50,     
             top:-95,   
             alignSelf:'flex-end', 
         },  
        showView:{     
             backgroundColor:'white',  
             height:125,      
             marginTop:0, 
        },  
        titleShow:{   
             alignSelf:'center',      
             backgroundColor:'transparent',    
             fontSize:10,  
         },   
        doImage:{    
             height:60,  
             width:60,    
             marginTop:20,     
             marginLeft:20  
         }
});
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 219,366评论 6 508
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,521评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 165,689评论 0 356
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,925评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,942评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,727评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,447评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,349评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,820评论 1 317
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,990评论 3 337
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,127评论 1 351
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,812评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,471评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,017评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,142评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,388评论 3 373
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,066评论 2 355

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,183评论 25 707
  • 世界上最美好的十件事—— 1.身边的人身体建康; 2.冬天里暖和的被窝; 3.与很在乎的那个人牵手; 4.躺在床上...
    柒贰零阅读 140评论 0 0
  • 七点半从公司出来的时候,天已经黑了。一个人走在工业区里,街灯才亮了两三盏,有些害怕,就想着给妈妈打个电话。 妈妈在...
    S夏七七Y阅读 364评论 0 1
  • 《中国好声音》之后,《中国好》系列遍地开花,什么《中国好舞蹈》、《中国好歌曲》,名头很大,节目宗旨也被吹得很高,但...
    胡言说影视阅读 140评论 0 1
  • 本文属于「Unity与iOS、Android平台的整合」系列文章之一,转载请注明出处。主要讲解如何优雅地实现Uni...
    万士辰阅读 2,157评论 0 5