ReactNative實(shí)現(xiàn)GitHub客戶端流程

一、初始化項(xiàng)目

??1箱残、在終端執(zhí)行react-native init MyApp 創(chuàng)建的ReactNative項(xiàng)目版本號與你終端安裝的ReactNative版本號相同
??2、在終端執(zhí)行react-native init MyApp --version 0.44.0可指定ReactNative版本創(chuàng)建項(xiàng)目

二剩胁、TabNavigator使用

??1截粗、在終端執(zhí)行命令npm install react-native-tab-navigator --save進(jìn)行安裝(加上--save才會添加到package.json文件中)
??2、在index.ios.js文件中導(dǎo)入import TabNavigator from 'react-native-tab-navigator';
??3蟋定、在render()中加入代碼
        <TabNavigator>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_popular'}
                selectedTitleStyle={{color:'red'}}
                title='最熱'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_polular.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                badgeText="1"
                onPress={() => this.setState({selectedTab: 'tb_popular'})}>
                <View style={styles.page1}></View>
            </TabNavigator.Item>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_trending'}
                selectedTitleStyle={{color:'red'}}
                title='趨勢'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_polular.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                badgeText="1"
                onPress={() => this.setState({selectedTab: 'tb_trending'})}>
                <View style={styles.page1}></View>
            </TabNavigator.Item>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_favorite'}
                selectedTitleStyle={{color:'red'}}
                title='收藏'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_polular.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                badgeText="1"
                onPress={() => this.setState({selectedTab: 'tb_favorite'})}>
                <View style={styles.page1}></View>
            </TabNavigator.Item>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_my'}
                selectedTitleStyle={{color:'red'}}
                title='我的'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_trending.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_trending.png')} />}
                onPress={() => this.setState({selectedTab: 'tb_my'})}>
                <View style={styles.page2}></View>
            </TabNavigator.Item>
          </TabNavigator>
??index.ios.js的完整代碼為:
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image
} from 'react-native';
import TabNavigator from 'react-native-tab-navigator';

export default class imoocc extends Component {
  constructor(props){
    super(props);
    this.state={
      selectedTab:'tb_popular',
    }
  }
  render() {
    return (
      <View style={styles.container}>
          <TabNavigator>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_popular'}
                selectedTitleStyle={{color:'red'}}
                title='最熱'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_polular.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                badgeText="1"
                onPress={() => this.setState({selectedTab: 'tb_popular'})}>
                <View style={styles.page1}></View>
            </TabNavigator.Item>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_trending'}
                selectedTitleStyle={{color:'red'}}
                title='趨勢'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_polular.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                badgeText="1"
                onPress={() => this.setState({selectedTab: 'tb_trending'})}>
                <View style={styles.page1}></View>
            </TabNavigator.Item>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_favorite'}
                selectedTitleStyle={{color:'red'}}
                title='收藏'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_polular.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_polular.png')} />}
                badgeText="1"
                onPress={() => this.setState({selectedTab: 'tb_favorite'})}>
                <View style={styles.page1}></View>
            </TabNavigator.Item>
            <TabNavigator.Item
                selected={this.state.selectedTab === 'tb_my'}
                selectedTitleStyle={{color:'red'}}
                title='我的'
                renderIcon={() => <Image style={styles.image} source={require('./res/images/ic_trending.png')}/>}
                renderSelectedIcon={() => <Image style={[styles.image,{tintColor:'red'}]} source={require('./res/images/ic_trending.png')} />}
                onPress={() => this.setState({selectedTab: 'tb_my'})}>
                <View style={styles.page2}></View>
            </TabNavigator.Item>
          </TabNavigator>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
  },
  page1:{
    flex:1,
    backgroundColor:'red',
  },
  page2:{
    flex:1,
    backgroundColor:'yellow',
  },
  image:{
    height:22,
    width:22
  },

});

AppRegistry.registerComponent('imoocc', () => imoocc);

Navigator的基本使用

??1、使用流程
屏幕快照 2018-09-18 上午11.13.14.png
??2草添、使用import {Navigator} from 'react-native-deprecated-custom-components';進(jìn)行導(dǎo)入驶兜。頁面在渲染的時候會調(diào)用renderScene方法
??3、示例
render() {
    return (
      <Navigator
            /*初始化路由远寸,Navigator首先顯示的是哪一個界面抄淑。默認(rèn)頁面,
            name: 默認(rèn)頁面組件名, component: 默認(rèn)頁面渲染組件*/
           initialRoute={{ name: 'Boy', component: Boy }}
           // 頁面切換動畫
           configureScene={(route) => {
               return Navigator.SceneConfigs.VerticalDownSwipeJump;
           }}
           /* 頁面在渲染的時候會調(diào)用  將頁面參數(shù)和navigator注入渲染組件中 */
           renderScene={(route, navigator) => {
               let Component = route.component;
               return <Component {...route.params} navigator={navigator} />
           }}
     />
    )
  }
??4、Navigator方法
getCurrentRoutes() - 獲取當(dāng)前棧里的路由驰后,也就是push進(jìn)來肆资,沒有pop掉的那些。
jumpBack() - 跳回之前的路由灶芝,當(dāng)然前提是保留現(xiàn)在的郑原,還可以再跳回來,會給你保留原樣夜涕。
jumpForward() - 上一個方法不是調(diào)到之前的路由了么犯犁,用這個跳回來就好了。
jumpTo(route) - 跳轉(zhuǎn)到已有的場景并且不卸載女器。
push(route) - 跳轉(zhuǎn)到新的場景酸役,并且將場景入棧,你可以稍后跳轉(zhuǎn)過去
pop() - 跳轉(zhuǎn)回去并且卸載掉當(dāng)前場景
replace(route) - 用一個新的路由替換掉當(dāng)前場景
replaceAtIndex(route, index) - 替換掉指定序列的路由場景
replacePrevious(route) - 替換掉之前的場景
resetTo(route) - 跳轉(zhuǎn)到新的場景,并且重置整個路由棧
immediatelyResetRouteStack(routeStack) - 用新的路由數(shù)組來重置路由棧
popToRoute(route) - pop到路由指定的場景涣澡,在整個路由棧中贱呐,處于指定場景之后的場景將會被卸載。
popToTop() - pop到棧中的第一個場景暑塑,卸載掉所有的其他場景吼句。
??5、Navigator屬性
??initialRoute object
??提供一個路由集合用來初始化事格。如果沒有設(shè)置初始路由的話則必須設(shè)置該屬性。如果沒有提供該屬性搞隐,它將被默認(rèn)設(shè)置成一個只含有initialRoute的數(shù)組驹愚。
??initialRoute示例
           /*初始化路由,Navigator首先顯示的是哪一個界面劣纲。默認(rèn)頁面,
            name: 默認(rèn)頁面組件名, component: 默認(rèn)頁面渲染組件*/
           initialRoute={{ name: 'Boy', component: Boy }}
??configureScene function
??可選的函數(shù)逢捺,用來配置場景動畫和手勢。會帶有兩個參數(shù)調(diào)用癞季,一個是當(dāng)前的路由劫瞳,一個是當(dāng)前的路由棧。然后它應(yīng)當(dāng)返回一個場景配置對象
?? configureScene示例
(route, routeStack) => Navigator.SceneConfigs.FloatFromRight
??或者
         // 頁面切換動畫
           configureScene={(route) => {
               return Navigator.SceneConfigs.PushFromRight;
           }}
??SceneConfigs的值為
Navigator.SceneConfigs.PushFromRight (默認(rèn))
Navigator.SceneConfigs.FloatFromRight
Navigator.SceneConfigs.FloatFromLeft
Navigator.SceneConfigs.FloatFromBottom
Navigator.SceneConfigs.FloatFromBottomAndroid
Navigator.SceneConfigs.FadeAndroid
Navigator.SceneConfigs.HorizontalSwipeJump
Navigator.SceneConfigs.HorizontalSwipeJumpFromRight
Navigator.SceneConfigs.VerticalUpSwipeJump
Navigator.SceneConfigs.VerticalDownSwipeJump
??renderScene function
??必要參數(shù)绷柒。用來渲染指定路由的場景志于。調(diào)用的參數(shù)是路由和導(dǎo)航器。
??renderScene示例
(route, navigator) =>
  <MySceneComponent title={route.title} navigator={navigator} />
??或者
         /* 頁面在渲染的時候會調(diào)用  將頁面參數(shù)和navigator注入渲染組件中 */
           renderScene={(route, navigator) => {
               let Component = route.component;
               return <Component {...route.params} navigator={navigator} />
           }}
??initialRouteStack [object]
??提供一個路由集合用來初始化废睦。如果沒有設(shè)置初始路由的話則必須設(shè)置該屬性伺绽。如果沒有提供該屬性,它將被默認(rèn)設(shè)置成一個只含有initialRoute的數(shù)組嗜湃。
??navigationBar node
??可選參數(shù)奈应,提供一個在場景切換的時候保持的導(dǎo)航欄。
??navigator object
??可選參數(shù)购披,提供從父導(dǎo)航器獲得的導(dǎo)航器對象杖挣。
??onDidFocus function
??每當(dāng)導(dǎo)航切換完成或初始化之后,調(diào)用此回調(diào)刚陡,參數(shù)為新場景的路由
??onWillFocus function
??會在導(dǎo)航切換之前調(diào)用惩妇,參數(shù)為目標(biāo)路由
??sceneStyle [View#style]
??將會應(yīng)用在每個場景的容器上的樣式。
??

彈出視圖(三方:react-native-popover)

直接把popover.js文件導(dǎo)入項(xiàng)目中

示例代碼:

<Popover
            isVisible={this.state.isVisible}
            fromRect={this.state.buttonRect}
            placement="bottom"
            onClose={()=>this.closePopover()}
            contentStyle={{backgroundColor:'#343434',opacity:0.82}}
        >
            {timeSpanTextArray.map((result,i,arr)=>{
              return <TouchableOpacity
                  key={i}
                  underlayColor='transparent'
                  onPress={()=>this.onSelectTimeSpan(arr[i])}
                  >
                  <Text

                     style={{fontSize:18,color:'white',fontWeight:'400',padding:8}}
                  >{arr[i].showText}</Text>
              </TouchableOpacity>
            })}

        </Popover>

彈出視圖的代碼:其中button為自己設(shè)置的標(biāo)識

showPopover(){
    this.refs.button.measure((ox,oy,width,height,px,py) => {
      this.setState({
        isVisible:true,
        buttonRect:{x:px,y:py,width:width,height:height}
      });
    });
  }

關(guān)閉彈出視圖的代碼:

closePopover(){
    this.setState({
        isVisible:false
    })
  }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末橘荠,一起剝皮案震驚了整個濱河市屿附,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌哥童,老刑警劉巖挺份,帶你破解...
    沈念sama閱讀 222,729評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異贮懈,居然都是意外死亡匀泊,警方通過查閱死者的電腦和手機(jī)优训,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來各聘,“玉大人揣非,你說我怎么就攤上這事《阋颍” “怎么了早敬?”我有些...
    開封第一講書人閱讀 169,461評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長大脉。 經(jīng)常有香客問我搞监,道長,這世上最難降的妖魔是什么镰矿? 我笑而不...
    開封第一講書人閱讀 60,135評論 1 300
  • 正文 為了忘掉前任琐驴,我火速辦了婚禮,結(jié)果婚禮上秤标,老公的妹妹穿的比我還像新娘绝淡。我一直安慰自己,他們只是感情好苍姜,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,130評論 6 398
  • 文/花漫 我一把揭開白布牢酵。 她就那樣靜靜地躺著,像睡著了一般怖现。 火紅的嫁衣襯著肌膚如雪茁帽。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,736評論 1 312
  • 那天屈嗤,我揣著相機(jī)與錄音潘拨,去河邊找鬼。 笑死饶号,一個胖子當(dāng)著我的面吹牛铁追,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播茫船,決...
    沈念sama閱讀 41,179評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼琅束,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了算谈?” 一聲冷哼從身側(cè)響起涩禀,我...
    開封第一講書人閱讀 40,124評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎然眼,沒想到半個月后艾船,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,657評論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,723評論 3 342
  • 正文 我和宋清朗相戀三年屿岂,在試婚紗的時候發(fā)現(xiàn)自己被綠了践宴。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,872評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡爷怀,死狀恐怖阻肩,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情运授,我是刑警寧澤烤惊,帶...
    沈念sama閱讀 36,533評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站吁朦,受9級特大地震影響撕氧,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜喇完,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,213評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望剥啤。 院中可真熱鬧锦溪,春花似錦、人聲如沸府怯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽牺丙。三九已至则涯,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間冲簿,已是汗流浹背粟判。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留峦剔,地道東北人档礁。 一個月前我還...
    沈念sama閱讀 49,304評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像吝沫,于是被迫代替她去往敵國和親呻澜。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,876評論 2 361

推薦閱讀更多精彩內(nèi)容