我是新来的反应母语和我以前遇到过这样的问题:(路由组件“委托人”必须是一个阵营component.For例如:...) 。
我想将DrawerNavigator放在StackNavigator中。我已经知道这是个好方法,但是它给了我我一直在寻找的错误,但我无法解决。
谢谢
App.js
import React, { Component } from 'react';
import {createAppContainer,createStackNavigator,createDrawerNavigator} from 'react-navigation';
import Login from './pantallas/login';
import Registro from './pantallas/registro';
import PantallaPrincipal from './pantallas/pantallaPrincipal';
import SolicitudCitas from './pantallas/socitudCitas';
import {Header,Icon} from 'native-base';
export default class App extends Component {
render() {
return <AppContainer/>;
}
}
const AppStackNavigator = createStackNavigator({
Login: { screen: Login },
Registro: { screen: Registro },
Principal: {screen: AppDrawerNavigator}
},{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
}
}
);
const AppDrawerNavigator = createDrawerNavigator({
PantallaPrincipal:{screen: PantallaPrincipal},
SolicitudCitas: {screen: SolicitudCitas}}
,{
defaultNavigationOptions: ({ navigation }) => {
return {
headerLeft: (
<Header>
<Icon
style={{ paddingLeft: 10 }}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}/>
</Header>
)
};
}
}
);
const AppContainer = createAppContainer(AppStackNavigator);
pantallaPrincipal.js
import React, { Component } from 'react';
import { Text, View,StyleSheet } from 'react-native';
export default class pantallaPrincipal extends Component {
render() {
return (
<View style={styles.backgroundContainer}>
<Text>Pantalla principal</Text>
</View>
);
}
}
const styles = StyleSheet.create({
backgroundContainer : {
flex: 1,
width: null,
height: null,
justifyContent: 'center',
alignItems: 'center'
}
});
solicitudCitas.js
import React, { Component } from 'react';
import { Text, View } from 'react-native';
export default class solicitudCitas extends Component {
render() {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Solicitud Citas</Text>
</View>
);
}
}
只需在要使用它的Stack导航器上方声明并初始化DrawerNavigator。这只是由于提升JS基础而发生的。在javascript中,只悬挂声明,而不初始化,因此,当您使用时Principal: {screen: AppDrawerNavigator}
,JS并不知道它AppDrawerNavigator
实际上是一个React组件,因为在使用它之前没有对其进行初始化。您可以在此处学习有关JS吊装的更多信息。
希望这可以帮助。编码愉快!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句