1

I am fairly new to react native, but I have some experience. I am creating my own app for both iOS and Android by following along with a tutorial course that I had already completed and making my own modifications. I am having an issue with displaying my custom header on the pages besides the Home screen. The header only shows on the Home screen within the pages on the BottomTabNavigator.

I had this same issue with the pages in the left menu tab inside of the DrawerNagivator. However, I fixed that issue by creating a stack navigator for each page. But I haven't had the same outcome with the bottom menu in the BottomTabNavigator. After struggling with this for several days, I'm desperate, so I decided to ask my question here.

I am also using React Navigation v.4 to follow along with the tutorial.

Here is my code snippet:

    import React from "react";
    import {
      View,
      BlurView,
      StyleSheet,
      Image,
      TouchableOpacity,
    } from "react-native";
    import {
      createStackNavigator,
      TransitionPresets,
    } from "react-navigation-stack";
    import { createAppContainer } from "react-navigation";
    import { createBottomTabNavigator } from "react-navigation-tabs";
    import { createDrawerNavigator } from "react-navigation-drawer";
    import { Ionicons } from "@expo/vector-icons";
    import {
      FontAwesome,
      FontAwesome5,
      SimpleLineIcons,
    } from "@expo/vector-icons";
    
    import HomeScreen from "../screens/app/HomeScreen/HomeScreen";
    import ReadScreen from "../screens/app/ReadScreen/ReadScreen";
    import PrayerScreen from "../screens/app/PrayerScreen/PrayerScreen";
    import ListenScreen from "../screens/app/ListenScreen/ListenScreen";
    import SearchScreen from "../screens/app/SearchScreen/SearchScreen";

const defaultStackNavOptions = {
  ...TransitionPresets.SlideFromRightIOS,
  cardStyle: { backgroundColor: "transparent" },
  headerShown: true,
  headerTransparent: true,
};

const LifelineNavigator = createStackNavigator(
  {
    Home: HomeScreen,
    Read: ReadScreen,
    Prayer: PrayerScreen,
    Listen: ListenScreen,
    Search: SearchScreen,
  },
  {
    defaultNavigationOptions: defaultStackNavOptions,
  }
);

const TodaysLifelineNavigator = createStackNavigator({
  TodaysLifeline: TodaysLifelineScreen,
});

const LifelineTabNavigator = createBottomTabNavigator(
  {
    Home: {
      screen: LifelineNavigator,
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          return (
            <FontAwesome name="home" size={24} color={tabInfo.tintColor} />
          );
        },
      },
    },
    Read: {
      screen: ReadScreen,
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          return (
            <FontAwesome5 name="bible" size={24} color={tabInfo.tintColor} />
          );
        },
      },
    },
    Listen: {
      screen: ListenScreen,
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          return (
            <Ionicons name="ios-ear" size={24} color={tabInfo.tintColor} />
          );
        },
      },
    },
    Prayer: {
      screen: PrayerScreen,
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          return (
            <FontAwesome5 name="pray" size={24} color={tabInfo.tintColor} />
          );
        },
      },
    },
    Search: {
      screen: SearchScreen,
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          return (
            <Ionicons name="md-search" size={24} color={tabInfo.tintColor} />
          );
        },
      },
    },
  },
  {
    tabBarOptions: {
      activeTintColor: Colors.blue,
      inactiveTintColor: Colors.midGray,
      labelStyle: {
        fontFamily: "Gotham-Medium",
      },
      style: {
        position: "absolute",
        height: 55,
        backgroundColor: Colors.transparent,
      },
    },
  }
);

......Other Code for Navigation.....

export default createAppContainer(MainNavigator);

Here is the code for my header that I have on each screen:

HomeScreen.navigationOptions = (navData) => {
  return {
    headerTitle: () => (
      <View>
        <Image
          style={{
            width: 175,
            height: 175,
            alignSelf: "center",
            marginBottom: 5,
            resizeMode: "contain",
          }}
          source={require("/Users/tamirab2/Desktop/The Lifeline Code/the-lifeline-app/src/assets/images/lifeline-logo-bold-dark-blue.png")}
        />
      </View>
    ),
    headerLeft: () => (
      <HeaderButtons HeaderButtonComponent={CustomHeaderButton}>
        <Item
          title="Menu"
          iconName="ios-menu"
          onPress={() => {
            navData.navigation.toggleDrawer();
          }}
        />
      </HeaderButtons>
    ),
    headerStyle: { height: 140 },
  };
};

Here are my images:

Home Screen Header Shown

Search Screen Header Not Shown

Braiam
  • 1
  • 11
  • 47
  • 78
  • You can create a JS file and design there a header and after that you call that functional component on header ? If you want code for your reference, I will send. I am not sending it now as it becomes messy there !! – Jagroop Apr 10 '22 at 04:02
  • Hi @Jagroop, I did try something along those lines, but I failed. I am kind of struggling with React Native. But if you are willing, do you mind sending me an example? I would truly appreciate it! Thanks so much for your reply! – Tamira Bell Apr 10 '22 at 04:07
  • I just added the code to the headerTitle on each screen in my post above. Sorry, I forgot to include it. – Tamira Bell Apr 10 '22 at 04:13
  • Wow! Awesome! I will definitely take a look through this! I truly appreciate your help! @Jagroop – Tamira Bell Apr 10 '22 at 04:20

1 Answers1

2
Home: {
      screen: LifelineNavigator,
      options={{ title: 'My home' }}
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          return (
            <FontAwesome name="home" size={24} color={tabInfo.tintColor} />
          );
        },
      },
    }

enter image description here

Add option attribute to your Screens

Also u can add title Dynamically , like this .....

enter image description here

Vijay
  • 275
  • 2
  • 11
  • Thank you so much for your reply! I truly appreciate it! I actually have custom logo image in my headerTitle. I just added the code to the headerTitle on each screen in my post above. Sorry, I forgot to include it. How would I include that in the option attribute? – Tamira Bell Apr 10 '22 at 04:15
  • Thank you so much @Vijay for your reply! I truly appreciate it! I actually have custom logo image in my headerTitle. I just added the code to the headerTitle on each screen in my post above. Sorry, I forgot to include it. How would I include that in the option attribute? – – Tamira Bell Apr 10 '22 at 04:17
  • Thanks, I'll try to see if this will work! @Vijay – Tamira Bell Apr 10 '22 at 04:19