how to style react-native-router-flux?
Asked Answered
G

5

9

I am using react-native-router-flux 4.0.0-beta.17 for my learning project. I need to customize the header. for instance the background color, the title alignment, etc. I couldn't find a good document about it. One of them had something like

 <Router sceneStyle={{backgroundColor: '#81b71a'}}>
     <Scene key="root">
        <Scene key='login' component={LoginForm} title='Please Login :)' />
     </Scene>
 </Router>

but it doesn't do anything.

Please give me some reference about good docs and also if possible, some information about how to style the router. where can I find a comprehensive document?

Germinal answered 15/8, 2017 at 2:25 Comment(1)
So basically you want to give custom style to all of router flux header?Emilieemiline
E
20

The sceneStyle props is used to styling all of your RNRF scene/screen, which is the content part of your screen (below of the header). If you want to give the custom style to all of your RNRF scene header, you have to use navigationBarStyle props in your RNRF Router component.

<Router navigationBarStyle={{ backgroundColor: '#81b71a' }}>
  <Scene key="root">
    <Scene key='login' component={LoginForm} title='Please Login :)' />
  </Scene>
</Router>

Below is one of the snapshot example if I use it.

enter image description here

Ref: https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md

Emilieemiline answered 4/9, 2017 at 8:5 Comment(0)
J
6

Maybe you can following this reference, It may be your problem because it is not right to put the style because if you want to change header background color you can use navigationBarStyle not using sceneStylelike this :

<Router navigationBarStyle={styles.navBar} titleStyle={styles.navTitle} sceneStyle={styles.routerScene}>
  <Schema .../>
  <Route .../>
</Router>

const styles = StyleSheet.create({
  navBar: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: 'red', // changing navbar color
  },
  navTitle: {
    color: 'white', // changing navbar title color
  },
  routerScene: {
    paddingTop: Navigator.NavigationBar.Styles.General.NavBarHeight, // some navbar padding to avoid content overlap
  },
})

I hope this reference can help you.

Journal answered 15/8, 2017 at 3:51 Comment(2)
How about that @farmcommand2, is it working on your project ?Journal
it says `Navigator is deprecated'!Germinal
D
6

You can hide the default header by using hideNavBar={true} and use your own header component to have a fully customizable header. In this way you can use the header component of a UI component package like native-base.

Damselfly answered 15/8, 2017 at 5:50 Comment(4)
how to use a custom header component? I can hide the navbar but don't know how to inject a new header.Pejorative
In a simple way, the header can be a part of each page.Damselfly
@VahidBoreiri This is exactly what I want to do, but I don't understand how to make your own custom header. Is there any documentation on how to do this?Lambertson
@Lambertson You can use your own component or some UI component package like react-native-elements.github.io/react-native-elements/docs/… or docs.nativebase.io/Components.html#textarea-textbox-headrefDamselfly
S
0

sceneStyle prop in Router is a style applied to all scenes, which is completely optional.

<Router sceneStyle={{ backgroundColor: '#81b71a' }}>
  <Stack key="root">
    <Scene key='sample page' component={Sample} title='Sample Page'/>
  </Stack>
</Router>

This will give result like this:

enter image description here

you can use navigationBarStyle props in Router as mentioned above by @wlisrausr

<Router navigationBarStyle={{ backgroundColor: '#81b71a' }}>
      <Stack key="root">
        <Scene key='sample page' component={Sample} title='Sample Page'/>
      </Stack>
    </Router>

which will give result:

navigationBarStyle

Self answered 14/8, 2019 at 14:34 Comment(0)
S
0

Easy Way To channge Header Bar Text Style in : react-native-router-flux

<Scene key="myJobs"
  title={'My Listings'}
  iconName="myJobs"
  hideNavBar={false}
  component={MyJobs}
  titleStyle={{
    color: '#ffffff',
    fontSize: 22,
    fontFamily: FontFamilyBold,
    fontWeight: '700',
    justifyContent: 'center',
    marginLeft: 30,
  }}
/>
Snail answered 10/9, 2019 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.