由于侧面菜单的弃用,我决定将我的应用切换到世博会建议的新反应导航。使用具有一个嵌套堆叠导航器和四个纯色屏幕的抽屉导航器,构建初始非常基本的原型以模拟当前的侧边菜单,看起来该应用程序不会从纵向模式旋转到横向模式。毋庸置疑,我目前的应用程序是在没有反应导航的情况下开发的,可以在所有屏幕上清晰地支持纵向和横向。反应导航屏幕不会从肖像切换到风景
该文档没有提供任何相关的细节,也没有提及任何可以启用/禁用屏幕旋转的设置。我也无法在其他地方找到任何有关预期行为或解释如何启用旋转的参考。
我的package.json文件如下:
{
"name": "pdpappnav",
"version": "0.0.0",
"description": "xxx",
"author": "xxx",
"private": true,
"main": "node_modules/expo/AppEntry.js",
"dependencies": {
"connect": "^3.6.5",
"expo": "^22.0.0",
"react": "[email protected]",
"react-native": "https://github.com/expo/react-native/archive/sdk-22.0.1.tar.gz",
"react-native-elements": "^0.17.0",
"react-navigation": "^1.0.0-beta.15",
"react-redux": "^5.0.6",
"redux": "^3.7.2"
}
}
主要感兴趣的代码部分是AppNavigation.js如下
import React from 'react';
import { Text, View } from 'react-native';
import { StackNavigator, DrawerNavigator, TabNavigator } from 'react-navigation';
import MainScreen from '../Containers/MainScreen';
import SideMenu from '../Components/SideMenu';
import AccountManagement from '../Containers/AccountManagement';
import Settings from '../Containers/Settings';
import DataManager from '../Containers/DataManager';
import ContactUs from '../Containers/ContactUs';
const topStack = StackNavigator({
main: { screen: MainScreen },
})
// drawer stack
const PrimaryNav = DrawerNavigator({
top: { screen: topStack },
account: { screen: AccountManagement },
settings: { screen: Settings },
datamanager: { screen: DataManager },
contact: { screen: ContactUs },
}, {
gesturesEnabled: true,
contentComponent: SideMenu,
headerMode: 'screen',
})
export default PrimaryNav
我用我自己的组件以使抽屉,但切换到默认的contentComponent似乎没有任何区别。
ReduxNavigation.js
import React from 'react'
import * as ReactNavigation from 'react-navigation'
import { connect } from 'react-redux'
import AppNavigation from './AppNavigation'
function ReduxNavigation(props) {
const { dispatch, nav } = props
const navigation = ReactNavigation.addNavigationHelpers({
dispatch,
state: nav
})
return <AppNavigation navigation={navigation} />
}
const mapStateToProps = state => ({ nav: state.nav })
export default connect(mapStateToProps)(ReduxNavigation)
最后,在这里我App.js文件
import React from 'react'
import { StyleSheet, View, StatusBar } from 'react-native'
import { Provider } from 'react-redux'
import createStore from './Redux/Reducers'
import ReduxNavigation from './Navigation/ReduxNavigation'
const store = createStore()
export default class App extends React.Component {
render() {
return (
<Provider store={store}>
<View style={styles.container}>
<StatusBar barStyle='light-content' />
<ReduxNavigation />
</View>
</Provider>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff'
},
})
有没有提供单独的屏幕价值,他们只是有几个按钮行使原型占位符。
任何帮助或澄清将不胜感激。