2017-05-05 61 views
0

有什麼好的沒有bug的StackNavigator例子在DrawerNavigator裏面? 正如在我的示例中,當抽屜打開時,頂部導航標題被隱藏,當我在NewScreen頁面內時,無法打開抽屜(帶有幻燈片)。 所以我想打開標題和任何頁面上的抽屜。 感謝Q:ReactNative StackNavigator裏面的DrawerNavigator

http://image.prntscr.com/image/eb4d869acbcf4d22a08159b072aae930.png

下面是代碼

import React, { Component } from 'react'; 
import { 
    AppRegistry, 
    Button, 
    Platform, 
    ScrollView, 
    StyleSheet, 
    TouchableHighlight, 
    Text, 
} from 'react-native'; 
import { 
    DrawerNavigator,StackNavigator 
} from 'react-navigation'; 

import FontAwesome from "react-native-vector-icons/FontAwesome"; 

class ScreenHome extends Component{ 
    static navigationOptions = { 
     title: 'ScreenHome', 
    }; 
    render() { 
     const { navigate } = this.props.navigation; 
     return (
      <Button 
       title="Go to Jane's profile" 
       onPress={() => navigate('New', { name: 'Jane' })} 
      /> 
     ); 
    } 
} 

class NewScreen extends Component{ 
    static navigationOptions = { 
     title: 'New screen', 
    }; 
    render() { 
     const { navigate } = this.props.navigation; 
     return (
      <Text>Some new screen</Text> 
     ); 
    } 
} 

class ScreenRegister extends Component{ 
    static navigationOptions = { 
     title: 'ScreenRegister', 
    }; 
    render(){ 
     return <Text>ScreenRegister</Text> 
    } 
} 

const MainScreenNavigator = DrawerNavigator({ 
    Recent: { 
     screen: ScreenHome 
    }, 
    All: { 
     screen: ScreenRegister 
    }, 
}); 

export default SimpleApp = StackNavigator({ 
    Home: { 
     screen: MainScreenNavigator 
    }, 
    Chat: { 
     screen: ScreenHome 
    }, 
    New: { 
     screen: NewScreen 
    } 
}); 

AppRegistry.registerComponent('naviTest',() => SimpleApp); 
+1

[看起來是個未解決的問題](https://github.com/react-community/react-navigation/issues/165)。您應該查看可能的解決方法的註釋,但在閱讀完所有解決方案後,看起來每個解決方案都存在某種錯誤。 –

回答

0

如果我正確地得到了你的問題,你想:

1)從任何網頁

訪問抽屜

2)打開時,抽屜蓋上標題欄。

爲了實現1號

有兩種方法可以做到這一點,他們是:
一)添加一個按鈕/圖標觸發上點擊抽屜。當您使用此解決方案時,由於DrawerNavigator明確控制此功能,因此您仍然沒有滑動功能。b)將NewScreen添加到抽屜中,因爲您希望在屏幕內訪問整個抽屜時

爲了實現2號

這是一個很常見的問題中StackNavigator嵌套DrawerNavigator時。爲了解決這個問題,請修改StackNavigator

export default SimpleApp = StackNavigator({ 
    Home: { 
     screen: MainScreenNavigator 
    }, 
    Chat: { 
     screen: ScreenHome 
    }, 
    New: { 
     screen: NewScreen 
    } 
}, { 
    navigationOptions: { header: false } 
});