Combining multiple Stack navigators in React Native

I am currently developing a React Native application using TypeScript and functional components. My app has a deep level of nesting in its stack navigation.

App: {
  NavigationConatainer: {
    DrawerNavigation: {
      StackNavigator1: {
        HomeScreen,
        DetailedScreen,
        ButtonTabNavigator: {
          InfoScreen,
          StackNavigation2: {
            MainScreen,
            SubScreen1,
            SubScreen2,
          },
          MetaScreen
        }
      }
    },
    SomeCustomDrawerItems,
  }
}

I hope this gives you an idea of the architecture.

However, I am facing two issues:

  1. The SubScreen1 appears above the Tab of ButtonTabNavigation.
  2. How can I hide the header from StackNavigation1 on SubScreen1 and 2, and show the new header from StackNavigation2?

It seems like the stacks are overlapping. When pressing the back button on SubScreen1, it navigates to DetailedScreen from StackNavigation1.

Is there anyone who knows how to properly implement nested stacks like this?

Answer №1

Feel free to test out this navigation structure and let me know if you encounter any issues.

Here's how we create the navigator objects (Drawer, Bottom tab & Stack):

const Drawer = createDrawerNavigator()
const BottomTab = createBottomTabNavigator()

const Stack1 = createStackNavigator()
const Stack2 = createStackNavigator()

We then proceed to create functional components for each navigator:

const stack_1 = () => {
 return (
    <Stack1.Navigator
      screenOptions={{ gestureEnabled: false, headerShown: false }}
    >
      // Add your screen components here
    </Stack1.Navigator>
  )
}

const stack_2 = () => {
 return (
    <Stack2.Navigator
      screenOptions={{ gestureEnabled: false, headerShown: false }}
    >
      // Add your screen components here
    </Stack2.Navigator>
  )
}

const bottom_tab = () => {
 return (
    <BottomTab.Navigator
      screenOptions={{ gestureEnabled: false, headerShown: false }}
    >
      // Add your screen components here
    </BottomTab.Navigator>
  )
}

By using this structure, we address your first issue in a way that subscreen1 and subscreen2 are displayed within the bottom tab navigator.

To tackle your second issue, setting headerShown to false ensures no headers are visible on any screen within the stacks.

It's recommended to create a custom header component for more customization options and flexibility. This helps avoid confusion and allows you to have full control over the headers.

Creating the customized header component:

// Header component code goes here

export default Header

// Styles for the header component
const styles = nav_container: {
    flexDirection: 'row',
    ...styling.navHeaderSize,
    backgroundColor: colors.black,
    alignItems: 'center',
    paddingTop: DeviceInfo.hasNotch() === true ? '20@ms' : '20@ms',
    paddingHorizontal: '20@ms',
  },

You can easily implement this header component in any screen as needed for a seamless user experience.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Could the delete button in a Chip component from Material-UI be customized with a unique style?

I'm having no issues styling the label or background color of the chip itself. However, it appears that the delete button inside the chip is an SVG icon. Is there a method to change the color of this icon? ...

Encountering the error "Typescript: No overload matches this call" while attempting to include custom attributes in styled-components

While working on a TypeScript-React project, I encountered an error when creating an image component using styled-components. Below is the snippet from my style.ts file: https://i.sstatic.net/nVm4n.png The error message I received is: https://i.sstatic.ne ...

Need help triggering Ajax code upon clicking a link?

Can someone help me find the issue with my script? Below is the code snippet: <script> $(".icross").click(function(e){ e.preventDefault(); var obj = $(this); $.ajax({ type: "GET", url: "supprimer.php", data: 'id=&a ...

What is the best way to loop through the keys of a generic object in TypeScript?

When I come across a large object of unknown size, my usual approach is to iterate over it. In the past, I've used generators and custom Symbol.iterator functions to make these objects iterable with a for..of loop. However, in the ever-evolving world ...

What is the proper way to utilize $location within a standard function?

I am working on an Angular app that consists of both AngularJS and plain JavaScript such as Ajax. I am trying to figure out how to use $location within a function without passing it as a parameter. function x() { $location.path('/error').repl ...

Default cursor for Internet Explorer: automatic

I have a container div that holds all of my website's content. I want this container to change the cursor to a pointer when clicked on, but I don't want the elements inside the container to inherit this cursor style: https://i.sstatic.net/8joJo. ...

Untangling REGEX URLs for Effective Filtering

I am currently working on creating a filter for a video list. I have successfully put together a string that includes all the values selected by the user for filtering. Right now, I am passing this string as a parameter through the URL. For example: NOTE ...

What is the most efficient way to transfer sample code to the clipboard by simply clicking a button?

UPDATE START***** This question is unique and not a duplicate. Here is my revised code snippet: I am able to retrieve innerHTML but facing an issue with copying it. Can someone help me test this on jsFiddler? Here's the HTML code: <div id="mydiv ...

adjust the child component by directly accessing its reference

Struggling to update a child component from the parent component using its reference, but running into some issues. Here's what I've attempted so far: class MainApp extends React.Component<any, any> { construct ...

Change the label's class when the input area is selected

Looking to add a new class to a label when its corresponding input element is in focus. A form consists of 10 input fields and 10 labels, one for each field. const inputFields = document.querySelectorAll('.form-control'); console.log(inputFie ...

What is the method for transferring the value of a jQuery variable to a PHP variable without using AJAX?

Here is my JavaScript code: $('#affiliates_name').change(function(){ var id = $('#affiliates_name').val(); }); Below is the corresponding HTML: <select id="affiliates_name" style="display: none;" name="affiliates_name"> < ...

Using selectors and mappers in Typescript generics

I am looking to create a versatile selector and mapper method. interface State { user: { name: string; age: number; } } const pickName = (state: State) => state.user.name; const selectAge = (state: State) => state.user.age; ...

Swapping out one variable for another

After tweaking my code a bit, I'm still struggling to get it right. User input: !change Hi var A = "Hello" if (msg.content.includes ('!change')) { A = msg.content.replace('!change ', ''); } msg.send(A); //the change ...

Step-by-step guide on saving an array to localStorage using AngularJS

Currently working on constructing a shopping cart. My goal is to include the array invoice in localstorage for future reference. I suspect there may be some flaws with this particular approach. angular.module('myApp', ['ngCookies']); ...

What is the process for accessing a website using Java programming language?

Currently, I have a jar file up for sale that requires users to sign up on a particular website in order to download it. My issue lies in wanting to verify if purchasers have a valid login for the site when they run the jar file. Despite my attempts with h ...

Reduce the number of redundant fields in MongoDB collections

I'm facing an issue with my model structure. Here is the schema: var accountSchema = new mongoose.Schema({ 'seeker': { 'fullName': String, 'ageGroup': String, 'education': String, ...

The method this.$refs.myProperty.refresh cannot be invoked as it is not a valid

I have added a reference value 'callingTable' to a vue-data-table (using vuetify) like so: <v-data-table :headers="callingTableHeaders" :items="getCallingDetails" class="elevation-1" ref="callingTable&quo ...

AngularJS allows you to dynamically disable a button based on a value in an array

I have an array containing letters from A to Z and I want to create a list of buttons using them. $scope.alphabet = "abcdefghijklmnopqrstuvwxyz".split(""); I also have another array: $scope.uniqChar = ['a', ' ...

Creating and Injecting Singleton in Angular 2

I have a custom alert directive set up in my Angular app: import { Component } from 'angular2/core'; import { CORE_DIRECTIVES } from 'angular2/common'; import { Alert } from 'ng2-bootstrap/ng2-bootstrap'; @Component({ sele ...

Modifying Div Size with Jquery

I am working on populating the div container with square boxes, but I'm having trouble adjusting the size of my #gridSquare div. Despite trying to change its height and width using jQuery, it doesn't seem to work as expected. $('#gridSquare ...