Is there a way to use a component in two separate stack navigator screens without losing their distinctiveness?

Suppose we have the following scenario:

<Stack.Screen name="Home" component={BottomTab}
  options = {{title:'Home', headerShown: false}}
  />
  
        
  <Stack.Screen name = 'Create' component={BottomTab}
  options = {{title:'Create'}}

The issue here is that the "Create" screen has the exact same content as the "Home" screen because they both utilize the same BottomTab component. How can I maintain the same BottomTabNavigator in both screens without them being identical? Note: These Stack.Screen elements belong to the same Stack Navigator and NavigationContainer.

Here is the code for my BottomTab component:

function BottomTab() {
return (
  <Tab.Navigator
    screenOptions={{
      headerShown: false,
      labelStyle: {fontSize:18},
      activeTintColor: 'green',
      tabBarVisible:false,
      tabBarShowLabel: false,
    }}
    >

  
    <Tab.Screen
    name="Home"
    component={Home}
    options={{
      tabBarIcon: ({ focused }) => (
        <Ionicons
        name={focused ? "home" : "home-outline"}
        size={20}
        color = {focused ? "black" : "#748c94"}
        type={'Ionicons'}
        />
      )
    }}
    />



    <Tab.Screen
      name="Search"
      component={Search} 
      options={{
        tabBarIcon: ({ focused }) => (
          <Ionicons
          name={focused ? "search" : "search-outline"}
          size={20}
          color = {focused ? "black" : "#748c94"}
          type={'Ionicons'}
          />          
        )
      }} 
    />
    

    <Tab.Screen
      name="Topic"
      component={EmptyScreen}
      options={{
        tabBarIcon: ({ focused }) => (
          <TouchableHighlight onPress={() => console.log('HHH')} underlayColor="white" activeOpacity={1}>
            <View 
            style={{
              width: 80,
              height: 80,
              backgroundColor: 'white',
              borderRadius: 50,
              justifyContent: 'center',
              alignItems: 'center'
            }}>
              <AddButton/>
            </View>
          </TouchableHighlight>
        )
      }}  
    />
    

    <Tab.Screen
      name="Notification"
      component={Notification}
      options={{
        tabBarIcon: ({ focused }) => (
          <Ionicons
          name={focused ? "notifications" : "notifications-outline"}
          size={20}
          color = {focused ? "black" : "#748c94"}
          type={'Ionicons'}
          />          
        )
      }}  
    />

    
    <Tab.Screen
      name="Message"
      component={Message}
      options={{
        tabBarIcon: ({ focused }) => (
          <Ionicons
          name={focused ? "mail" : "mail-outline"}
          size={20}
          color = {focused ? "black" : "#748c94"}
          type={'Ionicons'}
          />          
        )
      }}  
    />

  </Tab.Navigator>  
  );
}

Answer №1

In my opinion, it's best to refrain from passing your BottomTabNavigator component to multiple screens. Instead, consider creating a centralized 'main' screen where you can place your tab navigator:

import React from 'react';
import TabNavigator from '../navigators/TabNavigator';

const MainScreen = ({}) => {
  return <TabNavigator />;
};

export default MainScreen;

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

Are instance prototypes exhibiting static behavior?

I'm in the process of creating a game for Windows 8 using HTML/Javascript and WinJS, but I'm running into issues with "prototypes" acting statically when they shouldn't. This is my first time working extensively with Javascript and dealing w ...

Creating a Vue application utilizing a function with an unspecified purpose

Looking to create an app with a function that is currently undefined. On the production server, there is a function called __doPostBack which I am calling from my Vue app like this: getLabel(templateName) { __doPostBack(templateName, ""); } Afte ...

Attempting to create a responsive Boxplot in Three.js

I created a basic three.js boxplot that loads individual jpg images for each mesh (bar). The boxplot appears fine on desktop, but is stretched/distorted on mobile devices. Is there a recommended approach to make it responsive? For simplicity, I will use e ...

Pair a specific portion of text with another string

I'm having trouble finding a substring within a string. The substring and the string are as follows: var str="My name is foo.I have bag(s)" var substr="I have bag(s)" When I use str.match(substr), it returns null, probably because the match() funct ...

Using data across multiple instances in node.js EJS partials

I need some advice regarding my nodejs project. I have created a sidebar partial that requires user data to be displayed on it. This sidebar is utilized across multiple pages in the project. However, currently, I have to include the user data in every func ...

Tokenizer method utilizing strings

Imagine a scenario where strings adhere to this specific format: id-string1-string2-string3.extension In this case, id, string1, string2, and string3 can all vary in length, with extension being a standard image extension type. To illustrate, here are a ...

Leveraging jquery datatable for displaying JSON data

Here is the JSON output I have: [{"param1":"value1","param2":"value2","param3":"value3"},{"param1":"value1","param2":"value2","param3":"value3"}] I have coded my AJAX request within a function that can be triggered by a button click: function callAjaxRe ...

What is the process for converting a URL or HTML document to a PDF using the html2pdf JavaScript library?

I am working on creating a button that utilizes the html2pdf library to convert an HTML page into a PDF. Instead of selecting an element with query selector or getElementById, I would like to pass a URL because the page I want to convert is not the same as ...

Having trouble viewing the header in devtools for $http requests?

The data in the request header is not visible to me. Here's what I'm using: $http.post('http://localhost/api/validate', {}, { headers: key } ); https://i.sstatic.net/yioTT.png The form that gets passed during runtime is shown below: ...

Triggering a sweet alert on a mouse click

Here is a code snippet I found on . It shows an alert box that doesn't disappear when clicked outside of it. swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, ...

Exploring timezones using moment.js

I have received scheduledTime and timezone data from an API, for example: scheduledTime: 1603890000000 timezone: "EDT" My goal is to display this information in the user's device timezone, such as CST. What would be the most effective approach to ach ...

Modifying a variable within the return statement in a React Native component

I am relatively new to React and React-native and I am facing challenges in understanding how to update a variable within the return method. Here is my current code snippet: import React, { Component } from "react"; import { View, StyleSheet, Platform, T ...

The module schedule cannot be found within the Haste module map

Greetings Hey everyone, I've come across similar queries regarding this common issue, but unfortunately, I've had no luck resolving it. Initial inquiry GitHub discussion My Attempts I attempted to follow the first link provided, but to no av ...

Steps for automatically closing a TextPrompt if the end user does not respond within a specific time frame

How can I programmatically close a Prompt in Microsoft Chatbot SDK v4, such as TextPrompt or ConfirmPrompt, and end the dialog after a certain period of time if the user does not reply? I attempted to use setTimeout and step.endDialog but encountered issu ...

Is there a way to transform a stringified array into an array in JavaScript if I do not have access to the original string?

Recently, I encountered a challenge where I had an array of items enclosed within "", and not '' (if that distinction matters): "['item 1', 'item2', 'item 3']" I am interested in converting it to ...

Dynamically insert <td> elements into <tr> element using both jQuery and JavaScript

I am facing an issue with adding a new table data (td) element dynamically to the first table row (tr) in my JavaScript code. Here is the original table before adding the new td element: <table> <tbody> <tr> <t ...

Tips for transforming videos into base64 format with the help of jquery and phonegap

After attempts to obtain video data in base64 using JavaScript with Phonegap, I am encountering difficulties. function captureVideo() { navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1}); } function captureSuccess(med ...

The navbar's background sections have various colors

Struggling to grasp React? Want to create a partially transparent Bootstrap navbar and customize the color, but encountering inconsistency due to the main background color setting. How can this be resolved? My App: function App() { return ( < ...

Picking a specific field from an array depending on a filtered value

Hello everyone, I am a newcomer to Angular and the entire MEAN stack ecosystem. Currently, I have a MongoDB database collection structured like this: db.users({ username: "Test1", fname: "Bob", lname: "Saget", email: "<a href="/cdn ...

List of sortable components

I have successfully implemented a filters section using vue.js to display dynamic responses based on user-selected filters. The components, in this case, represent cars with attributes such as price and brand. Now, I want to add two more filters that will ...