Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default style for a Navigator.NavigationBar (title)

I've created a navigation bar in my react-native app using the following syntax

<Navigator
  renderScene={this.renderScene.bind(this)}
  navigator={this.props.navigator}
  navigationBar={
    <Navigator.NavigationBar 
      style={styles.navbar}  
      routeMapper={NavigationBarRouteMapper} />
      } />

By default the navigation bar has a layout where the LeftButton is aligned to the left side of the bar and the RightButton is aligned to right side of the bar. But the Title is aligned to the left side of it's container flexbox. Which is next to the LeftButton.

What I'm trying to achieve is very simple I just want the Title centered between the two buttons of the navigation bar.

My title is just a < Text> component like so

<Text style={styles.navbarTitleText}>
 Welcome
</Text>

I thought I could achieve this using the following style

alignSelf: 'center'

this almost works but it became apparent that the container flexbox for the Title starts on the righthand edge of the LeftButton and ends at the end of the navigation bar at the edge of the screen, so it's centered between those 2 points. Which isn't the center of the screen/navbar.

I just want a central title, can anyone help?

like image 726
Mark Silver Avatar asked Mar 08 '16 12:03

Mark Silver


People also ask

How do I change the navigation bar style?

From Settings, tap Display. Tap Navigation bar, and then choose Swipe gestures.

How do you change the header title in react-native?

To configure the header bar of a React Native application, the navigation options are used. The navigation options are a static property of the screen component which is either an object or a function. headerTitle: It is used to set the title of the active screen. headerStyle: It is used to add style to the header bar.

How do I customize the navigation bar title in SwiftUI?

titleview in UIKit. To customize a navigation bar title view in SwiftUI, we simply set ToolbarItem of placement type . principal to a new . toolbar modifier.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.


1 Answers

I assume this problem occurred for you on Android. I had the same issue with the title being placed on the left. What worked out for me was the following:

<NavigationBar
        routeMapper={NavigationBarRouteMapper}
        style = {styles.navigationBar}
        navigationStyles={Navigator.NavigationBar.StylesIOS}
/>

The StylesIOS makes the navbar resemble the iOS-look, where the title is centered.

like image 199
pinewood Avatar answered Oct 12 '22 05:10

pinewood