react-navigation / react-navigation/react-navigation.github.io

createDrawerNavigator and createStackNavigator not working fine with each other.

未關閉
#466 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
JavaScript
星號
324
分支
2k
PR 合併指標
30 天內沒有已合併 PR

描述

I'm using createDrawerNavigator and createStackNavigator. But when I implemented Drawer Navigator in my app its disabling my navigationOption and defaultNavigationOption. I want different header title for each screen by navigationOptions and also I want to set same header background color for all over the app by defaultNavigationOptions. I also tried to set navigationOption in the class component but not working there also. I have tried several ways but not working good for me.
I'm using expo. react-navigation version is 3.11.1

----------Route.js-----------
import { createStackNavigator,
createAppContainer,
createSwitchNavigator,
createDrawerNavigator}
from 'react-navigation';

import Splash from '../app/component/Splash';
import Login from '../app/component/Login';
import SignUp from './component/signup';
import InitialScreen from './component/InitialScreen';
import CreateCircle from './component/CreateCircle';

export const AppDrawerNavigator = createDrawerNavigator(
{
initialScreen:{
screen: InitialScreen,
drawerLabel: "Initial Screen",
},
createCircle:{
screen: CreateCircle,
drawerLabel: "Create Circle",
}
},
{
drawerPosition: "left",
drawerWidth: 300,
},
)
// AppDrawerNavigator.navigationOptions = {
// title: 'My Chats',
// headerBackTitleVisible: false,
// headerStyle: {
// backgroundColor: '#87dfff',
// },
// headerTitleStyle: {
// textAlign:"center",
// flex:1
// },
// };

// THIS ABOVE COMMENTED THING WORKS BUT I WANT DIFFERENT HEADER NAME FOR ALL THE PAGES

const AppStack = createStackNavigator({

initialScreen:{
screen: InitialScreen,
navigationOptions: {
headerTitle: "Initial Screen" // Not showing me this title when I use createDrawerNavigator
}
},

createCircle:{
screen: CreateCircle,
navigationOptions: {
headerTitle: "Second Screen" // Not showing me this title when I use createDrawerNavigator
}
},
},
{
defaultNavigationOptions: {
headerBackTitleVisible: false,
headerStyle: {
backgroundColor: '#87dfff',
},
headerTitleStyle: {
textAlign:"center",
flex:1
},
}
// defaultNavigationOptions also does not working after using createDrawerNavigator
}
)

const AuthStack = createStackNavigator({
login: {
screen: Login,
navigationOptions: {
header: null
}
},
signup:{
screen: SignUp,
navigationOptions: {
header: null
}
},
Drawer:{screen: AppDrawerNavigator } // if I Comment out this line, all navigationOptions working fine.
// but I want Drawer in my app
},
)
const SwitchNavigator = createSwitchNavigator(
{ Splash: Splash,
Auth: AuthStack,
App: AppStack
},
{initialRouteName : 'Splash'}
)

export default createAppContainer(SwitchNavigator)

--------App.js------------
import React from 'react'
import {View} from 'react-native'
import NavRoutes from './app/Routes'
export default class App extends React.Component{
render(){
return(

)
}
}

貢獻指南

這個儲存庫沒有索引到貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Route.js 開始,接著將 createDrawerNavigator 和 createStackNavigator 的巢狀設定與 React Navigation 3.x 的 navigation-options 文件進行比較。透過 App.js 執行 Expo 應用程式,並確認每個 drawer 畫面都顯示其設定的標題,同時共用的 header 樣式仍會套用;記錄支援的巢狀設定和任何必要的變更。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
javascript, react-native
領域
mobile
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。