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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header Icon Button #1989

Closed
jonathanroze opened this issue Jun 26, 2017 · 6 comments
Closed

Header Icon Button #1989

jonathanroze opened this issue Jun 26, 2017 · 6 comments
Labels

Comments

@jonathanroze
Copy link

Hey,

I need to put an Icon in the left corner of my Header but, how can i link onPress with a method of my Component ?

I've tried a lot of code but nothing work!

So, if you have already did that, if you have some code piece 馃憤

Thanks :)

@matthamil
Copy link
Member

Can you post what you've tried?

You can use headerLeft https://reactnavigation.org/docs/navigators/stack#headerLeft to render a custom component.

static navigationOptions = ({ navigation }) => ({
  headerLeft: <MyCustomComponent>
});

@lucianomlima
Copy link

lucianomlima commented Jul 16, 2017

@matthamil Seizing this issue, when I set a custom button in the headerLeft in a StackNavigator, the back button is no longer displayed.

How can I add a button in headerLeft and keep the back button when a new view is pushed?
Same question: #1417

@vonovak
Copy link
Member

vonovak commented Oct 19, 2017

closing since the original question is a duplicate of #145

@lylest
Copy link

lylest commented Apr 28, 2019

how to add onpress event to that this was added to headerLeft?

@lylest
Copy link

lylest commented Apr 28, 2019

static navigationOptions = ({ navigation }) => ({
  headerLeft: <MyCustomComponent>
});

how to add functionality to it

@matthamil
Copy link
Member

@lylest , check out this page in the docs: https://reactnavigation.org/docs/en/header-buttons.html#adding-a-button-to-the-header.

Here's an example of adding an onPress to a header button:

class YourScreenComponent extends React.Component {
  static navigationOptions = ({ navigation }) => {
    return {
      headerLeft: (
        <Button
          onPress={navigation.getParam('onPressHeaderButton')}
        />
      ),
    };
  };

  componentDidMount() {
    this.props.navigation.setParams({ onPressHeaderButton: this.showAlert });
  }

  showAlert = () => {
    Alert.alert('Huzzah!', 'You pressed a button in the header!')
  };

  render() {
  // ...
}

@react-navigation react-navigation locked as resolved and limited conversation to collaborators Apr 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants