Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header for DrawerNavigator #68

Closed
svk31 opened this issue Jan 28, 2017 · 5 comments
Closed

Header for DrawerNavigator #68

svk31 opened this issue Jan 28, 2017 · 5 comments

Comments

@svk31
Copy link

svk31 commented Jan 28, 2017

Thanks for the awesome work on this library!

I'd like to use the classical header with a hamburger pattern in combination with the DrawerNavigator but I can't figure out how to do so apart from manually including the header in every screen where I want it rendered, which seems a bit redundant. Is that actually how I should do it or is there a better way?

An example including a header would be much appreciated. Examples of StackNavigator nested behind DrawerNavigator would be nice too.

@Steviey
Copy link

Steviey commented Jan 28, 2017

+1

@hilkeheremans
Copy link

hilkeheremans commented Jan 28, 2017

I worked on this problem today, and the approach I came up with for now is to create a class factory function (~ HOC) that takes a component and renders the drawer header around it. To actually do it properly is a bit trickier since you will want to use navigationOptions etc.

I'll post a sample tomorrow (need to generalize it a little first).

@satya164
Copy link
Member

satya164 commented Jan 29, 2017

What do you mean by a classical header? Do you have a mock-up or screenshot of what you want?

@svk31
Copy link
Author

svk31 commented Jan 29, 2017

Something like this:

image

I've continued playing around with this and I just managed to get it working, with the one issue still that the hamburger is misaligned, but that's probably just due to the component I'm using.

What I did was fetch react-navigation from github instead of using the version on npm, this fixed the header not appearing and also fixed the "header: left" property so the left button actually appears, as well as an issue with the drawer going behind the header.

The working approach I have right now looks something like this:

CompX.navigationOptions = {
        title: "CompX",
        header: ({ navigate }) => ({
            left: <Button transparent onPress={() => {navigate("DrawerOpen")}}><Icon name="ios-menu">    </Icon></Button>
        })
    };

NestedNavigator1 = StackNavigator({
    Screen1: {
        screen: Comp1
    },
    Screen2: {
        screen: Comp2
    }
})

NestedNavigator2 = StackNavigator({
    Screen3: {
        screen: Comp3
    },
    Screen4: {
        screen: Comp4
    }
})

Drawer = DrawerNavigator({
    SubNav1: {
        screen: NestedNavigator1
    },
    SubNav2: {
        screen: NestedNavigator2
    }
})

CompX without header property renders the back button as expected.

@satya164
Copy link
Member

Yes, the left key inside navigationOptions.header is the correct way of doing it. And regarding misalignment, you'll likely need to fix it in your component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants