Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to style react-native-router-flux?

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?

like image 286
farmcommand2 Avatar asked Aug 15 '17 02:08

farmcommand2


3 Answers

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

like image 183
Wanda Ichsanul Isra Avatar answered Oct 03 '22 21:10

Wanda Ichsanul Isra


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.

like image 22
Syauqi Rahmat Sugara Avatar answered Oct 03 '22 22:10

Syauqi Rahmat Sugara


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.

like image 39
Vahid Boreiri Avatar answered Oct 03 '22 21:10

Vahid Boreiri