react-native-navigation V2:如何将sideMenu嵌套在stackView中

时间:2019-02-25 06:29:55

标签: javascript react-native react-native-navigation

我有一个InitialScreen,用于检查用户之前是否已登录。如果是,则将用户导航到main屏幕,如果不是,则将用户导航到signUp屏幕(使用stack navigation)。

这正常工作,但是我试图同时使用stacksideMenu导航。当用户导航到main screen时,我想在用户单击sideMenusideMenu 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嵌套在根导航中?任何意见或建议将非常有帮助。提前致谢! :)

0 个答案:

没有答案