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

Add method to hide Navigator.NavigationBar #3005

Closed
satya164 opened this issue Sep 24, 2015 · 6 comments
Closed

Add method to hide Navigator.NavigationBar #3005

satya164 opened this issue Sep 24, 2015 · 6 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@satya164
Copy link
Contributor

Is there a way to hide the Navigator.NavigationBar?

For example, I have a search button, when it is pressed, I want to hide the navigation bar, and show the search bar in place of it. Is it possible?

It'll be very useful to add such a method, and users will be able to do lots of things like hide navigation bar on scroll etc.

@mkonicek
Copy link
Contributor

Can you please use Stack Overflow to ask questions and tag them with react-native? http://stackoverflow.com/questions/tagged/react-native

Many people from the community hang out on Stack Overflow and will be able to see your question. Using Stack Overflow for questions also helps us use Github issues to keep track of bugs that need to be fixed.

@satya164
Copy link
Contributor Author

I'll ask on StackOverflow. BTW, I've changed my title to reflect that it is more of a feature request than just a question.

@satya164 satya164 changed the title Hiding Navigator.NavigationBar Add method to hide Navigator.NavigationBar Sep 24, 2015
@mkonicek
Copy link
Contributor

👍 Thanks @satya164!

@hedgerwang
Copy link

@satya164

We'd like to avoid imperativeAPI as possible as we can.

If you want to make the "hidden" state controllable, you may do this.

var NavigationBarOne = React.createClass({
  render() {
    if (this.props.hidden) {
      return null;
    }
    return <Navigator.NavigationBar {...this.props} />
  }
});

Still, if imperativeAPI is what you'd like to have, you can do this:

var NavigationBarTwo = React.createClass({
  render() {
    if (this.state.hidden) {
      return null;
    }
    return <Navigator.NavigationBar {...this.props} />
  },

  hide() {
    this.setState({hidden: true});
  },

  show() {
    this.setState({hidden: false});
  },
});

IMHO, this isn't really the core feature that needs to be backed into the core component and there
more ways to do this.

For now, we're working on refactoring the Navigator API so stabilizing the API is high priority for now.

@satya164
Copy link
Contributor Author

@hedgerwang Understood. Looking forward to the improved navigator API.

Just returning null won't be enough in my case as I'll want to animate hiding there navbar. I'll try playing with Animated to try and achieve that.

Thank you.

@despairblue
Copy link
Contributor

@hedgerwang the imperative approach does not work since it is impossible to get a ref to NavigationBarTwo. A ref callback added to the component that is passed to the Navigator's navigationBar property is never called.
I also could not get the NavigationBarOne approach to work. Eventually the navigation bar is rendered, but only after a second render pass. The first render pass still renders the navigation bar with the old props, so the view slides in, shows no navigation bar (what I want is to hide the navbar for the first route, and show it for subsequent ones), after a while (when the app is rerendered for some reason) the navigation bar updates and renders correctly.

I'll try to make some minimal examples.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 21, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

5 participants