React Native Navigation Between Different Stacks - react-native

How can i Navigate from Screen1 in Stack1 to Screen2 in Stack2 in React-Native ,Or Navigate from Stack1 to Stack2 assuming each stack has its own default start Screen

It's easy.
navigation.navigate('NameOfTheStack', {
screen: 'NameOfTheScreen',
params: {anyParams},
})
Make sure that the two stacks are housed under the same Stack Navigator.

Related

React Native Navigation: best way to organize component references in tab navigators nested in a stack navigator?

In my React Native app I have a stack navigator called StackNavigator that contains two tab navigators TabNavigator1 and TabNavigator2. TabNavigator1 contains the screens TabNavigator1_Screen1 and TabNavigator1_Screen2, and TabNavigator1 contains TabNavigator2_Screen1, and TabNavigator2_Screen2.
From all four of those screens, the user needs to be able to navigate to various other screens, Screen1, Screen2, and Screen3.
I'm using react-navigation#4.x
What I Want To Know:
Where is the best place to put references to Screen1, Screen2, and Screen3? The only place I know I can add them is when defining StackNavigator. So I would do
createStackNavigator(
{
TabNavigator1,
TabNavigator2,
TabNavigator1_Screen1,
TabNavigator1_Screen2,
TabNavigator2_Screen1,
TabNavigator2_Screen2,
Screen1,
Screen2,
Screen3,
Screen4,
}
)
and then in TabNavigator1 and TabNavigator1 pass their navigation prop to the screens with
screenProps={{
navigation: this.props.navigation
}}
so that TabNavigator1_Screen1 can navigate to Screen1 with this.props.screenProps.navigation.navigate('Screen1').
Is there a way I can organize all those screen references so that I define specific screens that screens in TabNavigator1 can navigate to, and others that screens in TabNavigator1 can navigate to?

Passing params to nested screens in createStackNavigator

I have main drawer navigator with a few nested stack navigators.
I'm initializing the nested stack navigators with default params.
Currently, I'm using the function dangerouslyGetParent in the screens of the stack navigator to get the parameters from the drawer.
Is there a way to pass the parameters from the stack navigator to the nested screens?
I have tried something like this, but it doesn't work:
PersonalSettings: {
screen: PersonalSettingsScreen,
navigationOptions: ({ navigation }) => ({
collectionName: navigation.state.params.collectionName,
}),
},
Thank you from advance.
Use react navigations setParam and getParam functions inside the screen itself
https://reactnavigation.org/docs/en/navigation-prop.html
this.props.navigation.setParams({collectionName: collectionName})
this.props.navigation.getParam("collectionName")

Navigation of Tabnavigator in Stacknavigator

I am working on a react native Project, where I am using both Stack navigator and Tab navigator.
The main flow of the application should be in stack navigation.I have added a button on one of the screens which is in tab navigation but the navigation is not happening!
How can I get that kindly help me out
Sample code :
const Nav=createStackNavigator({
Splash: Splash,
Login: Login,
Tab:tab
})
const Tab=createBottomNavigator({
Home:Home,
Profile:Profile // i added button in this screen want to navigate to Login
})
I am able to solve the navigation issue by creating another stack for the screens which I want in tab navigation just as below and able to achieve the navigation.
//New Stack
const Stack=createStackNavigator({
Profile:Profile,
Login:Login
})
//Old Stacks
const Tab=createBottomTabNavigator({
Home:Home,
Profile:Profile
})
const Nav=createStackNavigator({
Splash:Splash,
Login:Login,
Tab:Tab
})

How to build a nested drawer menu with React Native or stack navigation inside Drawer Navigation

I am trying to build an app using react-native and got stuck in navigation. I want a nested drawer menu inside my app.
For creating a drawer in react native you can use react-navigation in that there are two components such as stack navigation it is for making the navigation between the screen and for the drawer, there is Drawernavigator by this you can easily make the navigation as well as the drawer in the app in react native.
const Drawer = createDrawerNavigator({
"Here put the screen on which you need drawer."
},{
contentComponent: SideDrawer,
})
after that add the drawer to the stack navigator.
const stack = StackNavigator({
drawer:{screen: Drawer},
"And add the screens on which you don't want drawer."
}, {
headerMode: 'none',
});
It is the way you can make a drawer.

react navigation two navigators on one screen nested in StackNavigator

I got one screen where I need to get createMaterialTopTabNavigator and createBottomTabNavigator it is nested in createStackNavigator.
So I click on button on HomeScreen and StackNavigator navigates me to screen where is
createBottomTabNavigator primary navigation and createMaterialTopTabNavigator is different for each screen in createBottomTabNavigator
So it should be
createStackNavigator
createBottomTabNavigator
createMaterialTopTabNavigator
SomeTabBarScreen
SomeTabBarScreen
createMaterialTopTabNavigator //if I click on icon in BottomNavigator to navigate on another screen I want different TopNavigator
SomeTabBarScreen
SomeTabBarScreen
I'll just write out some pseudo code here, but you can nest stacks like so:
const FirstMatTab = createMaterialTopTabNavigator({//Routes here});
const SecondMatTab = createMaterialTopTabNavigator({//Routes here});
const TabNav = createBottomTabNavigator({
FirstTab: FirstMatTab,
SecondTab: SecondMatTab
});
const MainStack = createStackNavigator({
Tab: TabNav,
})
This means you can just call in your render function the component you want it rendered in.