reactnative項目(一)

為了規(guī)范代碼管理,現(xiàn)將app代碼全部放入app文件夾中女仰,操作如下:

開發(fā)環(huán)境配置:http://www.reibang.com/p/970c44cf800e
初始化項目:RNTestProject
react-native init RNTestProject
react-native init RNTestProject --verbose --version 0.22.2 //使用特定版本的react-native依賴初始化項目
創(chuàng)建一個app文件夾和app.js文件围苫,如圖:
創(chuàng)建app文件夾.png
刪掉上圖中默認(rèn)創(chuàng)建的App.js文件磕潮,修改默認(rèn)創(chuàng)建的index.js文件效床,如圖:
原圖.png

修改.png
import App from './app/app.js';
首先給項目集成三方庫react-native-router-flux:http://www.reibang.com/p/68df640242c2
在app.js文件中輸入如下:
import React, { Component } from 'react'
import {
  Platform,
  StyleSheet,
  Text,
  View,
  NativeModules,
  Modal,
  Button,
  Image,
} from 'react-native'
import { Scene, Actions } from 'react-native-router-flux'

import { TabNavigator,TabBarBottom } from 'react-navigation';

import Home from './pages/home/index'
import Category from './pages/category/index'
import ShoppingCart from './pages/shoppingCart/index' 
import Mine from './pages/mine/index'

class Root extends React.Component {
  render() {
    return (
      // <Router scenes={scenes} />
      <MainScreenNavigator />
    )
  }
}

const scenes = Actions.create(
  <Scene key='root'>
    <Scene key='Home' component={Home} title='主頁' />
    <Scene key='Category' component={Category} title='分類' />
    <Scene key='ShoppingCart' component={ShoppingCart} title='購物車' />
    <Scene key='Mine' component={Mine} hideNavBar />
  </Scene>
)

const MainScreenNavigator = TabNavigator({
  Home: {
    screen: Home,
    navigationOptions: {
      tabBarLabel: '首頁',
      tabBarIcon: ({ tintColor, focused }) => {
        return  focused ? <Image source={require('./images/home_select.png')}  style={styles.tabBarImage}/> : <Image source={require('./images/home.png')}  style={[styles.tabBarImage,{tintColor: tintColor}]}/>
      }
    }
  },
  Category: {
    screen: Category,
    navigationOptions: {
      tabBarLabel: '分類',
      tabBarIcon: ({ tintColor, focused }) => {
        return focused ? <Image source={require('./images/category_select.png')}  style={styles.tabBarImage}/> : <Image source={require('./images/category.png')}  style={[styles.tabBarImage,{tintColor: tintColor}]}/>
      }
    }
  },
  ShoppingCart: {
    screen: ShoppingCart,
    navigationOptions: {
      tabBarLabel: '購物車',
      tabBarIcon: ({ tintColor, focused }) => {
        return focused ? <Image source={require('./images/shoppingCart_select.png')}  style={styles.tabBarImage}/> : <Image source={require('./images/shoppingCart.png')}  style={[styles.tabBarImage,{tintColor: tintColor}]}/>
      }
    }
  },
  Mine: {
    screen: Mine,
    navigationOptions: {
      tabBarLabel: '我的',
      tabBarIcon: ({ tintColor, focused }) => {
        return focused ? <Image source={require('./images/mine_select.png')}  style={styles.tabBarImage}/> : <Image source={require('./images/mine.png')}  style={[styles.tabBarImage,{tintColor: tintColor}]}/>
      }
    }
  }
}, 
{ 
  tabBarComponent:TabBarBottom, // 為了適配安卓添加
  tabBarPosition: 'bottom', // android 默認(rèn)顯示在頂部候引,ios默認(rèn)顯示在底部
  swipeEnabled: false,
  animationEnabled: false,
  showIcon: true, // android 默認(rèn)不顯示 icon, 需要設(shè)置為 true 才會顯示
  tabBarOptions:{
    activeTintColor: '#ffad16', // 選中的顏色
    inactiveTintColor: '#333', // 不選中的顏色
    showIcon: true, // android 默認(rèn)不顯示 icon, 需要設(shè)置為 true 才會顯示
    style: {
      height: 49,           //iPhone X 49 + 34
      paddingBottom: 0,      //iPhone X 34
      backgroundColor: 'white',
      padding: 1,
      // borderTopColor: 'lightgray',
      shadowColor: 'lightgray',
      shadowOffset: {width: 0,  height: 0},
      shadowOpacity: 10,
      shadowRadius: 2,
    },
    labelStyle: {
      fontSize: 11
    },
    tabStyle: { // 設(shè)置底部圖標(biāo)的樣式
      backgroundColor: 'white'
    }
  }
})
// 定義樣式
const styles = StyleSheet.create({
  tabBarImage: {
      width: 24,
      height: 24,
  }
})

export default Root

運行iOS模擬器们童,效果如下圖:


iOS模擬器效果.png

未完待續(xù)...

續(xù)集移步畔况,項目(二):
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市慧库,隨后出現(xiàn)的幾起案子跷跪,更是在濱河造成了極大的恐慌,老刑警劉巖齐板,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吵瞻,死亡現(xiàn)場離奇詭異葛菇,居然都是意外死亡,警方通過查閱死者的電腦和手機橡羞,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進(jìn)店門眯停,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人卿泽,你說我怎么就攤上這事莺债。” “怎么了签夭?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵齐邦,是天一觀的道長。 經(jīng)常有香客問我第租,道長措拇,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任慎宾,我火速辦了婚禮丐吓,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘趟据。我一直安慰自己汰蜘,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布之宿。 她就那樣靜靜地躺著族操,像睡著了一般。 火紅的嫁衣襯著肌膚如雪比被。 梳的紋絲不亂的頭發(fā)上色难,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天,我揣著相機與錄音等缀,去河邊找鬼枷莉。 笑死,一個胖子當(dāng)著我的面吹牛尺迂,可吹牛的內(nèi)容都是我干的笤妙。 我是一名探鬼主播,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼噪裕,長吁一口氣:“原來是場噩夢啊……” “哼蹲盘!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起膳音,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤召衔,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后祭陷,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體苍凛,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡趣席,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了醇蝴。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片宣肚。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖悠栓,靈堂內(nèi)的尸體忽然破棺而出霉涨,到底是詐尸還是另有隱情,我是刑警寧澤闸迷,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布,位于F島的核電站俘枫,受9級特大地震影響腥沽,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜鸠蚪,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一今阳、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧茅信,春花似錦盾舌、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至酌摇,卻和暖如春膝舅,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背窑多。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工仍稀, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人埂息。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓技潘,卻偏偏與公主長得像,于是被迫代替她去往敵國和親千康。 傳聞我的和親對象是個殘疾皇子享幽,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,713評論 2 354

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