React Navigation 5.x Show Image Icon in Header Bar React Native

Displaying Image Icon in header bar is easy in latest 5.x react navigation version. This method is known as replacing header bar title bar Title with custom component in react native. Because by default only Title of activity screen will display on header bar but using headerLeft prop we can easily replace Title text with custom component. In this case our custom component is Image component which display my image from online URL. I am also cropping image in round shape because in many social chatting applications like Whats-app and Hike we have seen image in same size. We would also display the header title text using headerTitle prop. So in this tutorial we would React Navigation 5.x Show Image Icon in Header Bar React Native Android iOS Example Tutorial.

Contents in this project React Navigation 5.x Show Image Icon in Header Bar React Native Android iOS Example Tutorial:

1. Before getting started the coding part we have to install the latest version of React Navigation in our current react native project. To install all the compulsory packages read my this tutorial.

2. After finishing installation of React Native 5.x latest version open your project’s main App.js file and import react-native-gesture-handler, StyleSheet, Text, View, Image, NavigationContainer and createStackNavigator components.

3. Create a custom class function named as ActionBarIcon(). In this function we would create a Image component in return block. We would use this function component to replace the current title in action title bar. I’m calling my image from WordPress Gravatar website.

4. Creating another function named as HomeScreen. This is our main home screen for our application.

5. Creating a constant Stack of createStackNavigator() type. We would use this Stack to add all the screens.

6. Creating a function named as App. In this function we would make NavigationContainer -> Stack.Navigator -> Stack.Screen component. Now we would call the headerLeft prop in options and pass the ActionBarIcon component here to display the image icon in Action title bar.

  • headerTitle : Used to display activity screen Title text in title bar.
  • headerLeft : Used to display custom component in action title bar.

7. Creating Style.

8. Now we have to call our main Root App using export default syntax.

9. Complete Source Code for App.js file:

Screenshot:

React Navigation 5.x Show Image Icon in Header Bar React Native