【发布时间】:2018-10-09 20:58:52
【问题描述】:
我遵循了关于身份验证流程 (https://reactnavigation.org/docs/en/auth-flow.html) 的反应导航指南,但略有不同。我在 LoginScreen 中嵌套了一个选项卡导航器。我不知道为什么,因为我对 React Native 很陌生,但是登录功能中的所有内容似乎都可以正常工作,除了应该移动到主导航器的部分。
基本上我想做的就是从绿色变成红色,但是没有任何反应
navigation.navigate('App');
这是我的导航文件:
AuthNavigator
import{
createSwitchNavigator
} from 'react-navigation';
//Import necessary Components and Navigators
import AuthLoading from '../components/AuthLoadingComponent';
import DrawerNavigator from './DrawerNavigator';
import AuthComponent from '../components/AuthComponent';
export default createSwitchNavigator(
{
AuthLoading: AuthLoading,
App: DrawerNavigator,
Auth: AuthComponent
},
{
initialRouteName: 'AuthLoading',
}
);
AuthComponent(包含社交登录按钮和 LoginNavigator)
export default class AuthComponent extends Component{
constructor(props){
super(props);
}
facebookLogin(){
}
googleLogin(){
}
render() {
return(
<View style={styles.container}>
<View style={styles.socialContainer}>
<SocialIcon
title='Conectar con Facebook'
button
type='facebook'
/>
<Divider/>
<SocialIcon
title='Conectar con Google'
button
type='google-plus-official'
/>
</View>
<Divider style={styles.divider}/>
{/*Navegador de Tab con Login y Register*/}
<LoginNavigator/>
</View>
);
}
}
登录导航器
export default createMaterialTopTabNavigator(
{
Login: {
screen: LoginComponent,
navigationOptions: {
tabBarLabel: 'Iniciar sesión',
tabBarIcon: ({tintColor}) => (
<Icon
name='lock-open'
color={tintColor}
/>
)
}
},
Register: {
screen: RegisterComponent,
navigationOptions: {
tabBarLabel: 'Crear cuenta',
tabBarIcon: ({tintColor}) => (
<Icon
name='person-add'
color={tintColor}
/>
)
}
}
},
{
tabBarPosition: 'top',
swipeEnabled: true,
animationEnabled: true,
tabBarOptions:{
showIcon: true,
}
}
);
登录组件
export default class LoginComponent extends Component{
constructor(props){
super(props);
this.state = {
email: ' ',
password: ' '
};
}
emailLogin(email, password){
FirebaseService.firebaseApp.auth().signInWithEmailAndPassword(email, password)
.then((user) => {
//AsyncStorage.setItem('userToken', pUser);
Alert.alert(
'¡Éxito!',
'Inicio de sesión exitoso',
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
]
);
this.props.navigation.navigate('App');
})
.catch((error) => {
Alert.alert(
'¡Ooops, algo salió mal!',
'Revisa el correo electrónico y/o contraseña.',
[
{text: 'OK', onPress: () => console.log(error)},
]
);
});
}
render() {
return(
<View style={styles.container}>
<FormLabel labelStyle={styles.label}>Correo electrónico</FormLabel>
<FormInput
placeholder='ejemplo@nomnom.com'
onChangeText={(value) => this.setState({email: value})}
/>
<FormLabel labelStyle={styles.label}>Contraseña</FormLabel>
<FormInput
placeholder='contraseña'
secureTextEntry={true}
onChangeText={(value) => this.setState({password: value})}
/>
<Button
title='Iniciar sesión'
icon={{name: 'check'}}
backgroundColor= 'green'
buttonStyle={styles.button}
onPress={this.emailLogin.bind(this, this.state.email, this.state.password)}
/>
</View>
);
}
}
我正在使用
"react-native": "0.56.0",
"react-navigation": "^2.17.0"
非常感谢您。
【问题讨论】:
标签: react-native react-navigation