我有一个InitialScreen,用于检查用户之前是否已登录。如果是,则将用户导航到main
屏幕,如果不是,则将用户导航到signUp
屏幕(使用stack navigation
)。
这正常工作,但是我试图同时使用stack
和sideMenu
导航。当用户导航到main screen
时,我想在用户单击sideMenu
或sideMenu icon
时打开swipe-to-right
。
这是我的Initalzing
屏幕
import React from 'react'
import {
View,
Text,
StyleSheet,
AsyncStorage
} from 'react-native'
import { goToSignUp, goToMain } from './navigation'
import { USER_KEY } from './Config/config'
export default class Initialising extends React.Component {
async componentDidMount() {
try {
const user = await AsyncStorage.getItem(USER_KEY)
console.log('user: ', user)
if (user) {
goToMain()
} else {
goToSignUp()
}
} catch (err) {
console.log('error: ', err)
goToSignUp()
}
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Loading</Text>
</View>
)
}
}
const styles = StyleSheet.create({
welcome: {
fontSize: 28
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
}
})
这是我想将sideMenu嵌套在mainScreen
import { Navigation } from 'react-native-navigation'
//if user not sign in go to signUpScreen
export const goToSignUp = () => Navigation.setRoot({
root: {
stack: {
id: 'StackId',
children: [
{
component: {
name: 'SignUpScreen',
},
},
],
}
}
});
//if user has signed in go to mainScreen
//I want to nest sideMenu in here!!
export const goToMain = () => Navigation.setRoot({
root: {
stack: {
id: 'App',
children: [
{
component: {
name: 'MainScreen',
}
}
],
}
}
})
我的问题是,如何将sideMenu嵌套在根导航中?任何意见或建议将非常有帮助。提前致谢! :)