React Native Header Icon Not Showing on the Left Side

I'm brand new to react and currently working on a project where navigation is done through a hamburger menu. I haven't encountered any errors in my code, but for some reason, the hamburger menu icon isn't displaying as expected. Interestingly, when I swipe across the screen, the menu does pop up.

Here's the snippet of my Portfolio.js file:

import React, {Component} from 'react';
import {StyleSheet, Text, View} from 'react-native';
import HamburgerIcon from '../assets/HamburgerIcon';

export default class Portfolio extends Component {
    static navigationOptions = () => {
        return {
            headerLeft: <HamburgerIcon/>
        };
    };
    render() {
        return (
                <View style={styles.container}>
                    <Text style={styles.title}>Green Screen</Text>
                </View>
        );
    }
 }
  const styles = StyleSheet.create({
    container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: 'green',
    },
    title: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
    }
 });

As for the HamburgerIcon.js code:

import React, {Component} from 'react';
import { withNavigation } from 'react-navigation';
import { TouchableOpacity } from "react-native-gesture-handler";
import Icon from 'react-native-vector-icons/SimpleLineIcons';

class HamburgerIcon extends Component{
    render() {
    return (
        <TouchableOpacity
        style={{
            width: 44,
            height: 44,
            marginLeft: 20
        }}
        onPress={()=>{
            this.props.navigation.openDrawer();
        }}>
            <Icon name='menu' size={20} color='black'/>
        </TouchableOpacity>
    )
    };
}
export default withNavigation(HamburgerIcon);

Update:

The NavigationBar.js contains the following code:

import { createDrawerNavigator} from 'react-navigation-drawer'; 
import { createAppContainer } from "react-navigation";
import HomePage from '../Pages/HomePage';
import Portfolio from '../Pages/Portfolio';


const HamburgerNavigation = createDrawerNavigator(
    {
        Portfolio: Portfolio,
        HomePage: {
            screen: HomePage,
        }
    },
    {
        initialRouteName: 'HomePage',
        
    }
);
export default createAppContainer(HamburgerNavigation);

If anyone can assist me in figuring out how to display the icon properly, that would be greatly appreciated!

Answer №1

function setNavigationOptions({ navigation }) {
    return {
        header: (
            <View style={{flex:0, 
                flexDirection: 'row', 
                justifyContent: 'flex-start'
            }}>
                <HamburgerIcon/>
            </View>
        )
    };
}

If you are using react-native element, you can refer to this documentation.

Answer №2

Due to limitations, I had to incorporate the Appbar component since navigationOptions is only compatible with StackNavigator and not DrawerNavigator like I initially intended

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 there any straightforward methods to fully freeze an object along with all its descendants in JavaScript (Deep Freeze)?

Often when passing an object as a parameter, functions may access the object by reference and make changes to the original object. This can sometimes lead to unwanted outcomes. Is there a way to ensure that an object remains unchanged? I am aware of the Ob ...

Overriding JSON variables globally

In my project, I needed to utilize json2.js since the JSON object in the browser (IE8) was not capable of parsing strings into JSON. After reviewing json2.js, I have a question regarding the variable declaration within it. The json2.js file declares a gl ...

I created a customized version of jQuery tabs, but I am looking for an external link to display the tab content and to style the original navigation

I've been experimenting with modifying a tabs script in jQuery that I came across. It seems like my attempt to enhance it has made things more complex than necessary. While I know creating tabs with jQuery is simple, I wanted to create my own version ...

Error: Unable to access the property 'fontSize' as it is undefined

<!DOCTYPE HTML> <html> <head> <title>Interactive Web Page</title> <link id="mycss" rel="stylesheet" href="mycss.css"> <script> function resizeText(size) { va ...

The peculiar actions of the Array.function(Object.keys(Obj[0]).map()) function

In my current code implementation, I have a hard coded [0] value that is used in rendering data for a table. However, instead of rendering only the first row as expected, it is displaying all rows. I am confused as to why this is resulting in rendering al ...

JavaScript - Uncaught ReferenceError: WebSocket is undefined

Looking at just the client side API (since each server side language has its own API), this code snippet demonstrates opening a connection, setting up event listeners for connect, disconnect, and message events, sending a message to the server, and closing ...

Encountering an issue with React Redux and Typescript involving the AnyAction error while working on implementing

While integrating redux-persist into my React project, I encountered an error. Previously, Redux was working smoothly, but upon the addition of redux-persist, I started receiving this error message: Types of property 'dispatch' are incompatib ...

Executing JavaScript in Rails after dynamically adding content through AJAX

Looking for advice on integrating JavaScript functions into a Rails app that are triggered on elements added to the page post-load via AJAX. I've encountered issues where if I include the code in create.js.erb, the event fires twice. However, removing ...

Executing multiple HTTP requests in parallel with AXIOS and retrieving the responses even if one of the requests fails

I am currently working on optimizing server get requests to run concurrently. To achieve this, I have developed the following function. Issue The problem arises when one request fails, causing me to lose track of the responses from the other requests. e ...

Passing and removing array parameters in HTTP requests using Angular

I have an Array of statuses objects. Each status has a name and a boolean set to false by default. These represent checkboxes in a form with filters - when a checkbox is checked, the boolean value is set to true: const filters.statuses = [ { name ...

Ways to transfer information among Angular's services and components?

Exploring the Real-Time Binding of Data Between Services and Components. Consider the scenario where isAuthenticated is a public variable within an Authentication service affecting a component's view. How can one subscribe to the changes in the isAut ...

Utilizing a drop-down menu in AngularJS to dynamically change a URL and fetch images

Currently, I am in the process of creating a website using AngularJS that accesses images from reddit and showcases them based on various parameters such as number of votes and date posted. While this is not groundbreaking, my main goal is to enhance my sk ...

Guide on how to clear and upload personalized information to Stormpath

After receiving JSON data from my client, I am looking to store it in Stormpath's custom data using node.js with express.js: I have set up a basic post route: app.post('/post', stormpath.loginRequired, function(req, res){ var data = req.b ...

Retrieving the inner content of several paragraph elements, all consolidated into a single string

I'm trying to extract the inner HTML of multiple paragraph elements from a string and I need some help. Here's an example input: let HTML = "<p class="Paragraph" >Hello, World 1!</p><p class="Paragraph" >Hell ...

Deactivate a span in real-time using ng-model

I found a helpful guide on creating a custom editable <span> using ngModelController here: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController#example Now, I am looking to implement a feature that allows me to dynamically disable editin ...

A step-by-step guide on sending a fetch request to TinyURL

I have been attempting to send a post request using fetch to tinyURL in order to shorten a URL that is generated on my website. The following code shows how I am currently writing the script, however, it seems like it's not returning the shortened URL ...

Displaying a div on click using Jquery will only impact one div at a time

I am encountering an issue with my WordPress setup. Within my loop, I have a clickable link that toggles a div to show or hide content. However, since each item in the loop uses the same class, clicking on one link activates all of them simultaneously. &l ...

Updating state in React with a nested promise within the useEffect hook

Trying to update the component state using React.useState with the help of useEffect. The reason behind using useEffect is that the API call response (EmployeeState > init()) determines what gets displayed on the UI. Component: import { EmployeeState } ...

Is it possible to ensure that an asynchronous function runs before the main functional component in React js?

My challenge involves extracting data from an API by manipulating a URL. Specifically, I must retrieve a specific piece of information upon page load and then incorporate it into my URL before fetching the data. var genre_id; var genre; const MOVIE_URL = ` ...

Is there a method to remove a buffer in threejs in order to minimize GPU memory leakage?

I am facing an issue with a large mesh containing over 5 million triangles. I utilized BufferGeometry with attributes such as position, color, normal, and index. However, there comes a point where I need to remove certain indices from the index attribute. ...