react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[NavigatorIOS] Add ability to set custom component as title

Open Alexxzz opened this issue 11 years ago • 26 comments

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.

Alexxzz avatar Mar 30 '15 22:03 Alexxzz

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} />}
/>

ericvicenti avatar Mar 30 '15 23:03 ericvicenti

Nice, will look in this direction.

Alexxzz avatar Mar 31 '15 20:03 Alexxzz

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

sophiebits avatar Mar 31 '15 20:03 sophiebits

how about hidden the navigation bar ?

AllanChen avatar Apr 01 '15 01:04 AllanChen

@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

ericvicenti avatar Apr 10 '15 20:04 ericvicenti

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. :)

sophiebits avatar Apr 10 '15 20:04 sophiebits

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

chirag04 avatar Apr 13 '15 18:04 chirag04

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.

chirag04 avatar May 19 '15 00:05 chirag04

+1 would love this feature

meric426 avatar May 19 '15 08:05 meric426

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.

ericvicenti avatar May 19 '15 17:05 ericvicenti

+1 this would be rad.

jessepollak avatar May 21 '15 20:05 jessepollak

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

chenbrian avatar Jun 12 '15 07:06 chenbrian

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 avatar Aug 04 '15 18:08 ghost

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

ghost avatar Jan 28 '16 21:01 ghost

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?

The0racle avatar Feb 15 '16 20:02 The0racle

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 avatar Mar 02 '16 07:03 lprhodes

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.

lprhodes avatar Mar 02 '16 08:03 lprhodes

@lprhodes Have you got any updates on this?

omeid avatar May 07 '16 12:05 omeid

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

singno avatar Jul 31 '16 08:07 singno

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.

omeid avatar Aug 17 '16 23:08 omeid