We use cookies to enhance your browsing experience, serve personalized ads or content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.
Customize Consent Preferences
We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.
The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ...
Always Active
Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.
No cookies to display.
Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.
No cookies to display.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.
No cookies to display.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
No cookies to display.
Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.
I’m going to explain how to open another tab within a screen (outside the tab but within the execution stack) that already has content in our tab.
For example, we have the following screen and we want to perform the navigation shown in the video:
And we want to open the “Buscar” tab using the “Click here to search” button, which is contained within a different screen and added to the “Mis Cursos” tab.
The code is as follows:
MenuTab.js
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import React from "react";
import { View, StyleSheet, Text, Button } from "react-native";
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
As you can see in this code, we have only created a bottom tab navigator.
Now we are going to create the Mis Cursos screen, which in turn will contain another NavigationContainer that will display one screen or another as appropriate.
MenuMisCursos.js
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import React, { useState, useEffect } from "react";
import { View, StyleSheet } from "react-native";
import { NavigationContainer, NavigationActions } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
In this code, we create a NavigationContainer that contains two screens. The goal is to open the “Buscar” tab from one of these screens by pressing a button.
To do this, we first pass the navigation attribute as a parameter that comes from the Navigation.Tab:
{ navigation }
{ navigation }
This way, we pass the navigation stack of the previous screen that corresponds to the tabs.
We want to navigate within the screen we have created, so we pass it as a parameter:
initialParams={{ navigationTab: { navigation }}}
initialParams={{ navigationTab: { navigation } }}
We have created an attribute called navigationTab and passed the corresponding navigation parameter to it.
Now we just have to retrieve this attribute and use it within the corresponding button in the MisCursos.js screen:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import React, { useState } from "react";
import { View, StyleSheet, Text } from "react-native";
//Import components:
import Button from '../components/Button';
//Button component
const MisCursos = ({ navigation, route }) =>{
const { navigationTab } = route.params;
return(
<View style={[styles.contenedorInicio]}>
<View style={[styles.contenedorInicio]}>
<Text style={[styles.texto]}>You don't have any courses</Text>
<Button text="Click here to search" onPress={() => navigationTab.navigation.navigate('Buscar')} />
To receive the parameter we want to navigate to, it is passed in the render function as “route”:
const MisCursos = ({ navigation, route }) =>{
const MisCursos = ({ navigation, route }) => {
*Do not confuse navigation with the previous object, as this navigation belongs to the Stack.Screen of the MenuMisCursos.js screen. The one we are interested in is within route, as we have passed it as initialParams.