2017-03-28 27 views
3

嗨,朋友我在過去2天反應導航,我嘗試了很多事情(文檔似乎對初學者來說似乎並不明顯),所以現在我面臨這似乎有點複雜,我和所以我尋求建議和幫助進行further.following的情況/問題/情景我尋求的幫助幾個問題 -抽屜沒有包括在反應導航中的標題

  1. 反應的導航不包括頭和狀態 ,我想實現類似gmail,但我結束了像this

我用下面的代碼塊,以達到這一點

import React, {Component} from 'react'; 
import { AppRegistry, View, BackAndroid, StatusBar,} from 'react-native'; 
import { 
    NavigationActions, 
    addNavigationHelpers, 
    StackNavigator, 
    DrawerNavigator 
} from 'react-navigation'; 


import LandingScreen from 'src/screens/landingScreen'; 
import Login from 'src/screens/login' 
import SignUp from 'src/screens/signUp' 
import ForgotPassword from 'src/screens/forgotPassword' 
import Dashboard from 'src/screens/dashboard' 
import UserProfile from 'src/screens/userProfile' 

export const Drawer = DrawerNavigator({ 
    Dashboard:{ 
    path:'/', 
    screen:Dashboard, 
    }, 
    UserProfile:{ 
    path:'/' 
    screen:UserProfile 
    }, 
}, { 
    initialRouteName: 'Dashboard', 
    contentOptions: { 
    activeTintColor: '#e91e63', 
    }, 
    headerMode: 'screen', 
}); 

const routesConfig = { 
    Landing:{screen:LandingScreen}, 
    Login: { screen: Login }, 
    SignUp: { screen: SignUp }, 
    ForgotPassword: { screen: ForgotPassword }, 
    Drawer:{screen:Drawer} 
}; 

export const AppNavigator = StackNavigator(routesConfig, { 
    initialRouteName: 'Drawer' 
}); 
AppRegistry.registerComponent('Riduk',() => AppNavigator); 
  • 其他問題是如何應該我在我的應用程序在相同的屏幕
  • 添加2個抽屜
    +0

    您是否找到解決方案? – itsashis4u

    +0

    我用drawerNavigator作爲我的應用程序的父導航器,看看我的導航結構https://github.com/manjeets12/riduk/blob/master/src/containers/AppNavigator.js –

    +0

    謝謝,我已經實現了類似解決方案和它的工作 – itsashis4u

    回答

    0

    按我的知識,你必須做兩件事情:在導航堆棧的頂部 1.把抽屜控制。 2.設置translucent屬性格式狀態欄

    <StatusBar 
           translucent 
           backgroundColor="rgba(0, 0, 0, 0.24)" 
           animated 
          /> 
          { Platform.OS === 'android' && Platform.Version >= 20 ? 
           <View 
            style={{ 
             height: 24, 
             backgroundColor: "#512DA8", 
            }} 
           /> 
           : null } 
    

    請讓我知道,如果它的工作。

    1

    在DrawerNavigator中有一個用於標題的issue

    但是你可以通過使用內部DrawerNavigator StackNavigator修復

    export const Drawer = DrawerNavigator({ 
        Dashboard:{ 
        path:'/', 
        screen: StackNavigator({ Screen1: { 
           screen: Dashboard 
          }}) 
        }, 
        UserProfile:{ 
        path:'/', 
        screen: StackNavigator({ Screen1: { 
           screen: UserProfile 
          }}) 
        }, 
    }}); 
    

    然後設置headerMode: 'none'根StackNavigator

    export const AppNavigator = StackNavigator(routesConfig, { 
        headerMode: 'none' 
    }); 
    

    這裏,AppNavigator是根StackNavigator和routesConfig具有上述DrawerNavigator等屏幕。

    +0

    這工作,但我已經添加了導航抽屜的圖標完全熄滅,我已經在抽屜組件下添加了圖標。 –

    +0

    將headerleft添加到內部堆疊導航器(screen1)後,圖標返回。 –

    2

    下面是一個簡單的例子:

    const FooStackNavigator = StackNavigator({ 
        Foo: { 
        screen: FooScreen, 
        navigationOptions: { 
         title: 'Foo', 
        } 
        }, 
    }); 
    const BarStackNavigator = StackNavigator({...}); 
    
    const MyDrawerNavigator = DrawerNavigator({ 
        FooStack: { 
        screen: FooStackNavigator, 
        navigationOptions: { 
         drawer:() => ({ 
         label: 'Foo', 
         }) 
        }, 
        }, 
        BarStack: { 
        screen: BarStackNavigator, 
        navigationOptions: { 
         drawer:() => ({ 
         label: 'Bar', 
         }) 
        }, 
        } 
    }); 
    
    const AppNavigator = StackNavigator({ 
        Drawer: { screen: MyDrawerNavigator }, 
    }, { 
        headerMode: 'none', 
    }); 
    
    0

    DrawerNavigator必須在上StackNavigator,這是我的方式來解決這個問題:

    const navStack = StackNavigator({ 
        Home: { screen: Main, }, 
        Example01: { screen: Example01, }, 
        Example02: { screen: Example02, }, 
    }); 
    
    const navDrawer = DrawerNavigator({ 
        Home: { 
        screen: navStack, // Drawer over on StackNavigator 
        navigationOptions: { 
         drawerLabel: 'Home', 
         header: null, 
        } 
        }, 
        Example03: { 
        screen: Example03, 
        navigationOptions: { 
         drawerLabel: 'Example03', 
        } 
        }, 
    }, 
    { 
        headerMode: 'none', 
        headerVisible: false, 
        navigationOptions: { 
        header: null 
        } 
    }); 
    

    希望這有助於。

    +0

    看起來你想在第一句中寫'StackNavigator'和'DrawerNavigator',而不是'DrawerNavigator'兩次,請修復,如果是這樣的話;另外,請澄清一下:根本沒有動詞。你的意思是'StackNavigator'應該在'DrawerNavigator'之前構建? – YakovL

    +0

    謝謝,修正了第一句話。 – Daniel

    +0

    此示例在所有StackNavigator屏幕上顯示DrawerNavigator並禁用所有StackNavigator屏幕標題,如Example01和Example02 – Daniel