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

[NavigatorIOS] Add ability to set custom component as title #514

Closed
Alexxzz opened this issue Mar 30, 2015 · 26 comments
Closed

[NavigatorIOS] Add ability to set custom component as title #514

Alexxzz opened this issue Mar 30, 2015 · 26 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@Alexxzz
Copy link

Alexxzz commented Mar 30, 2015

UIKit's UINavigationItem has a UIView property 'titleView' which allows to set custom view as a navigation bar title. Would be nice to have that in react-native.
Two ways as I see it:

  1. Child component of the NavigatorIOS:
<NavigatorIOS
  itemWrapperStyle={styles.nav}
  initialRoute={{
    component: NewsView
  }}>
{someFancyCustomTitleComponent}
</NavigatorIOS>
  1. Parameter of the NavigatorIOS:
<NavigatorIOS
  itemWrapperStyle={styles.nav}
  initialRoute={{
    component: NewsView
  }}
  titleComponent={someFancyCustomTitleComponent}
/>

So probably child component or parameter(or other way of ding it?) should be set to the instance of RCTNavItem and then RCTWrapperViewController should set it to corresponding UINavigationItem's titleView, but I don't have any idea how to convert react component to UIView.

@ericvicenti
Copy link
Contributor

We don't need this internally, but we would be happy to accept a pull request for this.

What do you think about this API:

<NavigatorIOS
  itemWrapperStyle={styles.nav}
  initialRoute={{
    component: NewsView
  }}
  renderTitle={(route) => <MyFancyTitleComponent title={route.title} />}
/>

@Alexxzz
Copy link
Author

Alexxzz commented Mar 31, 2015

Nice, will look in this direction.

@sophiebits
Copy link
Contributor

What's the advantage of making it a function here? I'd default to making it a normal element-typed prop.

@AllanChen
Copy link

how about hidden the navigation bar ?

@ericvicenti
Copy link
Contributor

@spicyj If not a function, then how would you change the title for each new scene? Maybe we could put a title element on the new route object, but I'd like to make the API start to resemble the Navigator API

@sophiebits
Copy link
Contributor

Right, that makes sense. Having title as a property of the route or similar seems to make the most sense though, akin to UINavigationItem on iOS? I'm not familiar with the Navigator API, so I'll let you figure it out. :)

@chirag04
Copy link
Contributor

@ericvicenti Is it possible to set an image/logo instead of title in the navigation bar?

@chirag04
Copy link
Contributor

I feel like spicyj's suggestion of having a route property makes sense. I can try to explore this area if you agree @ericvicenti regarding this api.

@meric426
Copy link

+1 would love this feature

@ericvicenti
Copy link
Contributor

For Navigator, the reason we don't put the title or scene components directly on the route is because it takes extra computation and memory to load and render them before they need to be displayed.

I think it would be nice if we could start making the API for NavigatorIOS more closely resemble Navigator. However, this is a community-maintained component, so I will let you all decide on the API. We are happy to accept additional features however you'd like to implement them.

@jessepollak
Copy link

+1 this would be rad.

@brentvatne brentvatne changed the title NavigatorIOS: Add ability to set custom component as title [NavigatorIOS] Add ability to set custom component as title May 31, 2015
@chenbrian
Copy link

Was looking for a feature like OP and came across this project: https://github.com/t4t5/react-native-router
Just thought I'd share...

@ghost
Copy link

ghost commented Aug 4, 2015

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

@ghost
Copy link

ghost commented Jan 28, 2016

Agreed, this would be very useful. Has anybody looked at implementing this feature?

@The0racle
Copy link

Just started using react native and not being able to do that is a super bummer for me since my app customizes the navigation title. Is anybody implementing this feature?

@lprhodes
Copy link
Contributor

lprhodes commented Mar 2, 2016

I'm looking to implement this as a PR but I'm struggling to find the right code in react native that takes the component JSON sent over the bridge and transforms it into usable Obj C views (to be used in a new method inside RCTConvert) - any pointers?

@lprhodes
Copy link
Contributor

lprhodes commented Mar 2, 2016

In the interim I'll be developing it as such:

<NavigatorIOS
  initialRoute={{
    component: MyComponent,
    titleView: {
      class: 'MyCustomView',
      title: 'View Title',
      textSize: 15,
      someOtherSetter: true
  }}
/>

You can then do any customisations you need in native code.

If you need to pass data back to RN (e.g. on selection of a segmented control) then normal event emitters can be used.

@omeid
Copy link
Contributor

omeid commented May 7, 2016

@lprhodes Have you got any updates on this?

@singno
Copy link

singno commented Jul 31, 2016

Any plans for this feature? It would be so nice to have such a feature.

@omeid
Copy link
Contributor

omeid commented Aug 17, 2016

For anyone else who has this issue, I ended up using Navigator Experimental (plays really nice with Flux, Redux in our case) and implemented the Nav in React.

@lprhodes
Copy link
Contributor

Sorry for leaving this so long - I've ended up using https://github.com/wix/react-native-navigation and https://github.com/wix/react-native-controllers.

I'm sure this is heavily debated elsewhere but for me the idea of React Native was to use native components (as per above)...not a non-native feeling replacement (Navigator Experimental)

@charpeni
Copy link
Contributor

@facebook-github-bot label Icebox

@charpeni
Copy link
Contributor

Hi there! This issue is being closed because it has been inactive for a while.

But don't worry, it will live on with ProductPains! Check out its new home: https://productpains.com/post/react-native/navigatorios-add-ability-to-set-custom-component-as-title

ProductPains helps the community prioritize the most important issues thanks to its voting feature.
It is easy to use - just login with GitHub.

Also, if this issue is a bug, please consider sending a PR with a fix.
We're a small team and rely on the community for bug fixes of issues that don't affect fb apps.

@charpeni
Copy link
Contributor

@facebook-github-bot close

@facebook-github-bot
Copy link
Contributor

@charpeni tells me to close this issue. If you think it should still be opened let us know why.

@facebook-github-bot facebook-github-bot added Ran Commands One of our bots successfully processed a command. Icebox labels Nov 14, 2016
@Alexxzz
Copy link
Author

Alexxzz commented Apr 14, 2017

Easily achievable with https://reactnavigation.org now.

@facebook facebook locked as resolved and limited conversation to collaborators Jul 23, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests