React Native路由react-navigation導(dǎo)航菜單(五)

知識(shí)點(diǎn):

1.?createStackNavigator?

2.?createBottomTabNavigator?底部菜單

3.?createMaterialTopTabNavigator?頂部菜單

4.?Icon菜單圖標(biāo) react-native-vector-icons

5.?源代碼地址:https://github.com/ysb002003/ReactNativeLearning_ReactNavigation

效果圖:


代碼實(shí)現(xiàn):

1.?導(dǎo)入底部與頂部方法到App.js進(jìn)行路由配置

import { createStackNavigator, createBottomTabNavigator, createMaterialTopTabNavigator } from 'react-navigation';

2.? 安裝圖標(biāo)組件??https://github.com/oblador/react-native-vector-icons

npm install --save?react-native-vector-icons

3.?導(dǎo)航結(jié)構(gòu):


4.?文件目錄結(jié)構(gòu)


5.?App.js?路由配置代碼:

a.?根路由代碼:

const App = createStackNavigator({

? WelcomePage: {

? ? screen: WelcomePage,

? ? navigationOptions: {

? ? ? gesturesEnabled: true,//是否可以使用手勢關(guān)閉此屏幕

? ? ? headerTitle: null//去掉 react-navigation提供的標(biāo)題

? ? }

? },

? BottomTab: {

? ? screen: BottomTab,

? ? navigationOptions: {

? ? ? gesturesEnabled: true,

? ? ? headerTitle: null

? ? }

? }

}, {

? ? mode: 'card', //頁面切換模式,左右:card, 上下:modal

? ? headerMode: 'none', //默認(rèn)導(dǎo)航欄:screen漸變棋嘲,float:無透明效果惫霸,none隱藏

? ? transitionConfig: () => ({ //切換動(dòng)畫

? ? ? screenInterpolator: CardStackStyleInterpolator.forHorizontal //水平

? ? })

? });

export default App

b.?底部路由:

const BottomTab = createBottomTabNavigator({

? IndexPage: {

? ? screen: IndexPage,

? ? navigationOptions: {

? ? ? header: null,

? ? ? tabBarLabel: '首頁',

? ? ? tabBarIcon: ({ focused, tintColor }) => (

? ? ??

? ? ? )

? ? }

? },

? CategoryPage: {

? ? screen: CategoryPageTopTab,

? ? navigationOptions: {

? ? ? header: null,

? ? ? tabBarLabel: '分類',

? ? ? tabBarIcon: ({ focused, tintColor }) => (

? ? ? ?

? ? ? )

? ? }

? },

? CartPage: {

? ? screen: CartPage,

? ? navigationOptions: {

? ? ? header: null,

? ? ? tabBarLabel: '購物車',

? ? ? tabBarIcon: ({ focused, tintColor }) => {


? ? ? }

? ? }

? },

? MyPage: {

? ? screen: MyPage,

? ? navigationOptions: {

? ? ? header: null,

? ? ? tabBarLabel: '個(gè)人中心',

? ? ? tabBarIcon: ({ focused, tintColor }) => {


? ? ? }

? ? }

? }

}, {

? ? tabBarOptions: {

? ? ? activeTintColor: theme.primaryColor,

? ? ? inactiveBackgroundColor: theme.lightGray,

? ? }

? });

c.?頂部路由

const CategoryPageTopTab = createMaterialTopTabNavigator({

? CategoryPage: {

? ? screen: CategoryPage,

? ? navigationOptions: {

? ? ? tabBarLabel: '品類'

? ? }

? },

? BrandPage: {

? ? screen: BrandPage,

? ? navigationOptions: {

? ? ? tabBarLabel: '品牌'

? ? }

? }

}, {

? ? swipeEnabled: true, //是否可以左右滑動(dòng)

? ? animationEnabled: true, // 切換頁面時(shí)是否有動(dòng)畫效果

? ? backBehavior: 'none',// 按 back 鍵是否跳轉(zhuǎn)到第一個(gè)Tab(首頁), none 為不跳轉(zhuǎn)

? ? tabBarOptions: {

? ? ? labelStyle: {

? ? ? },

? ? ? style: {

? ? ? ? height: theme.actionBar.height + theme.barContentPad,

? ? ? ? marginHorizontal: theme.screenWidth / 6,

? ? ? ? paddingTop: theme.barContentPad,

? ? ? ? backgroundColor: '#fff'

? ? ? },

? ? ? tabStyle: {

? ? ? ? width: theme.screenWidth / 3

? ? ? },

? ? ? activeBackgroundColor: '#fff',

? ? ? activeTintColor: theme.primaryColor, //活躍狀態(tài)下前景色

? ? ? inactiveBackgroundColor: '#fff',

? ? ? inactiveTintColor: theme.lightBlack,

? ? ? showIcon: false,

? ? ? showLabel: true,

? ? ? pressOpacity: 0.3,

? ? ? indicatorStyle: {

? ? ? ? height: 2,

? ? ? ? width: theme.screenWidth / 9,

? ? ? ? backgroundColor: theme.primaryColor,

? ? ? ? left: theme.screenWidth / 9

? ? ? }

? ? },

? ? // tabBarComponent: (props) => (

? ? //?

? ? // )

? });


d. theme.js配置文件:

import { Dimensions, Platform } from 'react-native';

export default module = {

? ? screenWidth: Dimensions.get('window').width,

? ? screenHeight: Dimensions.get('window').height,

? ? primaryColor: '#ee0000',

? ? lightGray: '#f5f5f5',

? ? darkGray: '#e5e5e5',

? ? lightBlack: '#333333',

? ? actionBar: {

? ? ? ? height: Platform.OS === 'android' ? 56 : 44,

? ? ? ? backgroundColor: '#fff'

? ? },

? ? barContentPad: (Platform.OS === 'android' ? 0 : 20),

? ? bottomPadding: isIphoneX() ? 18 : 0,

? ? btnActiveOpacity: 0.5

}

export function isIphoneX(){

? ? return false;

}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末架诞,一起剝皮案震驚了整個(gè)濱河市炎辨,隨后出現(xiàn)的幾起案子羡滑,更是在濱河造成了極大的恐慌,老刑警劉巖唠梨,帶你破解...
    沈念sama閱讀 218,204評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件声畏,死亡現(xiàn)場離奇詭異,居然都是意外死亡姻成,警方通過查閱死者的電腦和手機(jī)插龄,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來科展,“玉大人均牢,你說我怎么就攤上這事〔哦茫” “怎么了徘跪?”我有些...
    開封第一講書人閱讀 164,548評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵甘邀,是天一觀的道長。 經(jīng)常有香客問我垮庐,道長松邪,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,657評(píng)論 1 293
  • 正文 為了忘掉前任哨查,我火速辦了婚禮逗抑,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘寒亥。我一直安慰自己邮府,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,689評(píng)論 6 392
  • 文/花漫 我一把揭開白布溉奕。 她就那樣靜靜地躺著褂傀,像睡著了一般。 火紅的嫁衣襯著肌膚如雪加勤。 梳的紋絲不亂的頭發(fā)上仙辟,一...
    開封第一講書人閱讀 51,554評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音鳄梅,去河邊找鬼叠国。 笑死,一個(gè)胖子當(dāng)著我的面吹牛卫枝,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播讹挎,決...
    沈念sama閱讀 40,302評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼校赤,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了筒溃?” 一聲冷哼從身側(cè)響起马篮,我...
    開封第一講書人閱讀 39,216評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎怜奖,沒想到半個(gè)月后浑测,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,661評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡歪玲,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,851評(píng)論 3 336
  • 正文 我和宋清朗相戀三年迁央,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片滥崩。...
    茶點(diǎn)故事閱讀 39,977評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡岖圈,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出钙皮,到底是詐尸還是另有隱情蜂科,我是刑警寧澤顽决,帶...
    沈念sama閱讀 35,697評(píng)論 5 347
  • 正文 年R本政府宣布,位于F島的核電站导匣,受9級(jí)特大地震影響才菠,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜贡定,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,306評(píng)論 3 330
  • 文/蒙蒙 一赋访、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧厕氨,春花似錦进每、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至国葬,卻和暖如春贤徒,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背汇四。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評(píng)論 1 270
  • 我被黑心中介騙來泰國打工接奈, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人通孽。 一個(gè)月前我還...
    沈念sama閱讀 48,138評(píng)論 3 370
  • 正文 我出身青樓序宦,卻偏偏與公主長得像,于是被迫代替她去往敵國和親背苦。 傳聞我的和親對(duì)象是個(gè)殘疾皇子互捌,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,927評(píng)論 2 355

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