Customizing default navigation bar of react-native-router-flux - react-native

I am using react native router flux for navigation in my react native project. Router flux has a default navBar.
Is there a way to customize the navBar? like, changing colour of text and background.
I tried editing the file in node_modules/react-native-router-flux/src/navBar.js but it doesn't seem to work.
Please help me.

In your Router.js file where you create your scenes give a navBar property like for eg:
navBar={NavBar} and here my NavBar is actually a NavBar.js file in which I have customized the navigation bar
just have a look on my codes if that helps u
Router.js file:
import React from 'react';
import { Scene, Router } from 'react-native-router-flux';
import mainScreen from './components/mainScreen';
import challengeScreen from './components/challengeScreen';
import NavBar from './components/NavBar';
const RouterComponent = () => {
return (
<Router>
<Scene key="root">
<Scene key="homeScreen" component={mainScreen} hideNavBar={1} />
<Scene
key="screen2" component={challengeScreen} navTransparent={1}
navBar={NavBar}
/>
</Scene>
</Router>
);
};
export default RouterComponent;
NavBar.js file
import {
View, Image, StatusBar, TouchableWithoutFeedback
} from 'react-native';
import React, { Component } from 'react';
import { Actions, Router, Scene } from 'react-native-router-flux';
class NavBar extends Component {
render() {
return (
<View style={styles.backgroundStyle}>
<StatusBar />
<View style={{ flexDirection: 'row' }}>
<TouchableWithoutFeedback onPress={() => Actions.homeScreen()}>
<Image
source={require('./Images/back-arrow.png')}
style={styles.backarrowStyle} />
</TouchableWithoutFeedback>
<Image
source={require('./Images/help.png')}
style={styles.helpStyle} />
<Image
source={require('./Images/setting.png')}
style={styles.settingStyle} />
</View>
</View>
);
}
}
const styles = {
backgroundStyle: {
backgroundColor: 'transparent'
},
backarrowStyle: {
resizeMode: 'contain',
flexDirection: 'row',
width: 50,
height: 50,
left: 0,
justifyContent: 'flex-start'
},
helpStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
left: 220,
justifyContent: 'flex-end',
position: 'relative'
},
settingStyle: {
resizeMode: 'contain',
width: 50,
height: 50,
justifyContent: 'flex-end',
position: 'relative',
left: 210
}
};
export default NavBar;
This helped me to customize navigation bar
hope that it helps you

You should add navigationBarStyle property for customizing navigation bar.You can review following code:
<Scene key="key1" icon={TabIcon} title="book-open">
<Scene key="key2" hideNavBar={false}
navigationBarStyle={{backgroundColor:'transparent',marginTop:8, borderBottomWidth:0}}
component={TestComponent}
title=""/>
</Scene>
Also this subject is mentioned in here.https://github.com/aksonov/react-native-router-flux/issues/160

There is a working example in the examples folder of the react-native-router-flux repository.
For instance, your custom navbar would be:
import { Image, Platform, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import React from 'react';
import { Actions } from 'react-native-router-flux';
const styles = StyleSheet.create({
container: {
height: Platform.OS === 'ios' ? 64 : 54,
flexDirection: 'row',
paddingTop: 20,
},
navBarItem: {
flex: 1,
justifyContent: 'center',
},
});
export default class CustomNavBar extends React.Component {
// constructor(props) {
// super(props)
// }
_renderLeft() {
if (Actions.currentScene === 'customNavBar1') {
return (
<TouchableOpacity onPress={() => console.log('Hamburger button pressed')} style={[styles.navBarItem, { paddingLeft: 10 }]}>
<Image
style={{ width: 30, height: 50 }}
resizeMode="contain"
source={{ uri: 'https://upload.wikimedia.org/wikipedia/commons/thumb/b/b2/Hamburger_icon.svg/1200px-Hamburger_icon.svg.png' }}
/>
</TouchableOpacity>
);
}
return (
<TouchableOpacity onPress={Actions.pop} style={[styles.navBarItem, { paddingLeft: 10 }]}>
<Image style={{ width: 30, height: 50 }} resizeMode="contain" source={{ uri: 'https://image.flaticon.com/icons/png/512/0/340.png' }} />
</TouchableOpacity>
);
}
_renderMiddle() {
return (
<View style={styles.navBarItem}>
<Text>{this.props.title}</Text>
</View>
);
}
_renderRight() {
return (
<View style={[styles.navBarItem, { flexDirection: 'row', justifyContent: 'flex-end' }]}>
<TouchableOpacity onPress={() => console.log('Share')} style={{ paddingRight: 10 }}>
<Image style={{ width: 30, height: 50 }} resizeMode="contain" source={{ uri: 'https://cdn3.iconfinder.com/data/icons/glypho-free/64/share-512.png' }} />
</TouchableOpacity>
<TouchableOpacity onPress={() => console.log('Search')} style={{ paddingRight: 10 }}>
<Image style={{ width: 30, height: 50 }} resizeMode="contain" source={{ uri: 'https://maxcdn.icons8.com/Share/icon/p1em/Very_Basic//search1600.png' }} />
</TouchableOpacity>
</View>
);
}
render() {
let dinamicStyle = {};
if (Actions.currentScene === 'customNavBar1') {
dinamicStyle = { backgroundColor: 'red' };
} else {
dinamicStyle = { backgroundColor: 'yellow' };
}
return (
<View style={[styles.container, dinamicStyle]}>
{this._renderLeft()}
{this._renderMiddle()}
{this._renderRight()}
</View>
);
}
}
It works perfectly for me. Just don't forget to set the navBar property of your Scene or Stack:
<Scene navBar={CustomNavBar} key='myKey' component={MyComponent} />

react-native-router-flux provide some api to do this, take a look at https://github.com/aksonov/react-native-router-flux/blob/master/docs/API_CONFIGURATION.md, maybe titleStyle and navigationBarStyle are what you need.

Related

KeyboardAvoidingView doesn't work properly on my app

I searched a lot about this issue and I don't know what to do now so I decided to ask here and any help would be appreciated. in my register screen I have some input that user must fill and for the last one I need to avoid keyboard overlay. so I used KeyboardAvoidingView component to solve this but as you can see in the screenshot the device keyboard still overlay my input (birth date).
here is my code for this screen :
import React, { useState } from 'react';
import { View, Text, KeyboardAvoidingView, Image, Dimensions, PixelRatio, StyleSheet } from 'react-native';
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
import { COLORS } from '../Constants/COLORS';
import PrimaryButton from '../Components/PrimaryButton';
import PrimaryInput from '../Components/PrimaryInput';
import CheckBox from '../Components/CheckBox';
const Register = (props) => {
const [lisenceTerm, setLisenceTerm] = useState(true);
const [privacyPolicy, setPrivacyPolicy] = useState(true);
return (
<View style={styles.screen}>
<View style={styles.imageContainer}>
<Image style={styles.image} source={require('../assets/Img/office_5.jpg')} />
</View>
<View style={styles.loginContainer}>
<View style={styles.headerContainer}>
<Text style={styles.headerText}>Join us</Text>
</View>
<KeyboardAvoidingView style={styles.inputContainer}>
<PrimaryInput placeholder='Name Surname' />
<PrimaryInput placeholder='Your Email' />
<PrimaryInput placeholder='Phone Number (05***)' />
<PrimaryInput placeholder='Birth Date' />
</KeyboardAvoidingView>
<View style={styles.checkBoxContainer}>
<CheckBox text='Kvkk sözleşmesini okudum, kabul ediyorum' active={lisenceTerm} onPress={() => setLisenceTerm(!lisenceTerm)} />
<CheckBox text='Kullanıcı sözleşmesini okudum, kabul ediyorum' active={privacyPolicy} onPress={() => setPrivacyPolicy(!privacyPolicy)} />
</View>
<View style={styles.buttonsContainer}>
<PrimaryButton
buttonStyle={styles.button}
textStyle={styles.buttonText}
title='Register' />
</View>
</View>
</View>
)
}
const styles = StyleSheet.create({
screen: {
flex: 1,
},
imageContainer: {
width: '100%',
height: '34%'
},
image: {
width: '100%',
height: '100%'
},
loginContainer: {
backgroundColor: 'white',
width: '100%',
height: '71%',
position: 'absolute',
zIndex: 1,
bottom: 0,
borderTopLeftRadius: 40,
borderTopRightRadius: 40,
alignItems: 'center'
},
buttonsContainer: {
width: '100%',
justifyContent: 'center',
alignItems: 'center'
},
button: {
justifyContent: 'center',
alignItems: 'center',
width: '75%',
paddingVertical: '3%',
marginTop: hp(1.2),
borderRadius: hp(3.5),
backgroundColor: COLORS.royalBlue
},
buttonText: {
fontSize: hp(3.2),
fontFamily: 'BalooPaaji2ExtraBold',
color: 'white'
},
arrow: {
right: 20
},
inputContainer: {
width: '100%',
justifyContent: 'center',
alignItems: 'center',
marginBottom: hp(1),
},
headerContainer: {
marginTop: hp(3),
marginBottom: hp(2),
width: '75%',
},
headerText: {
fontSize: hp(3.5),
fontFamily: 'BalooPaaji2Bold',
color: COLORS.royalBlue
},
checkBoxContainer: {
width: '70%',
justifyContent: 'flex-start',
marginBottom: hp(1)
}
})
export default Register;
and here below is the result. btw I used behavior and keyboardVerticalOffset props to control the way this component behave but still same problem.
Your KeyboardAvoidingView component must be on top of render tree
In order to scroll onto your Join us view, you must set a ScrollView in your KeyboardAvoidingView and those component must be on top of renderer.
Try this (based on my iOS / android setup) :
import { KeyboardAvoidingView, ScrollView } from 'react-native';
const Register = (props) => {
const [lisenceTerm, setLisenceTerm] = useState(true);
const [privacyPolicy, setPrivacyPolicy] = useState(true);
return (
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={(Platform.OS === 'ios') ? 'padding' : null}
enabled
keyboardVerticalOffset={Platform.select({ ios: 80, android: 500 })}>
<ScrollView>
<View style={styles.screen}>
<View style={styles.imageContainer}>
<Image style={styles.image} source={require('../assets/Img/office_5.jpg')} />
</View>
<View style={styles.loginContainer}>
<View style={styles.headerContainer}>
<Text style={styles.headerText}>Join us</Text>
</View>
<View style={styles.inputContainer}>
<PrimaryInput placeholder='Name Surname' />
<PrimaryInput placeholder='Your Email' />
<PrimaryInput placeholder='Phone Number (05***)' />
<PrimaryInput placeholder='Birth Date' />
</View>
<View style={styles.checkBoxContainer}>
<CheckBox text='Kvkk sözleşmesini okudum, kabul ediyorum' active={lisenceTerm} onPress={() => setLisenceTerm(!lisenceTerm)} />
<CheckBox text='Kullanıcı sözleşmesini okudum, kabul ediyorum' active={privacyPolicy} onPress={() => setPrivacyPolicy(!privacyPolicy)} />
</View>
<View style={styles.buttonsContainer}>
<PrimaryButton
buttonStyle={styles.button}
textStyle={styles.buttonText}
title='Register' />
</View>
</View>
</View>
</ScrollView>
</KeyboardAvoidingView>
)
}
you need to install react-native-keyboard-aware-scroll-view by
yarn add react-native-keyboard-aware-scroll-view
and you need to wrap KeyboardAwareScrollView instead of KeyboardAvoidingView
like
import {KeyboardAwareScrollView} from 'react-native-keyboard-aware-scroll-view';
<KeyboardAwareScrollView>
<View>
...
</View
</KeyboardAwareScrollView>
import { useHeaderHeight } from "#react-navigation/elements"
import {
Keyboard,
Platform,
TouchableWithoutFeedback,
View,
KeyboardAvoidingView
} from "react-native"
const Chat = () => {
// This is the crucial variable we will place it in
// KeyboardAvoidingView -> keyboardVerticalOffset
const headerHeight = useHeaderHeight()
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<KeyboardAvoidingView
style={{ position: "absolute", bottom: 0, left: 0, right: 0 }}
behavior={Platform.OS === "ios" ? "padding" : "height"}
// If you want the input not to stick exactly to the keyboard
// add a const here for example headerHeight + 20
keyboardVerticalOffset={headerHeight}
>
<View style={{ flex: 1, justifyContent: "flex-end" }}>
<InputWrapper>
<RawInput />
</InputWrapper>
</View>
</KeyboardAvoidingView>
</TouchableWithoutFeedback>
)
}
Also take a look at this article it might be helpful: https://medium.com/#nickyang0501/keyboardavoidingview-not-working-properly-c413c0a200d4

How to fix react navigation displacing my component from top of screen?

I am working on a react native application and am trying to understand how to deal with react navigation as it affects my styling. Essentially when I navigate to a page, react navigation's top arrow with header is displacing my components (I'd like to move my black header bar up and use react navigation's arrow ideally):
I have react navigation set up in the following manner:
App.js
const ProfileNavigator = createStackNavigator({
//Profile: { screen: Profile},
QR: { screen: GenerateQR },
EditAccount: { screen: EditAccount }
});
const AppNavigator = createSwitchNavigator({
tabs: bottomTabNavigator,
profile: ProfileNavigator
})
const AppContainer = createAppContainer(AppNavigator);
I have a header component I put together for styling that I use on top of each page:
pageTemplate
import React, {Component} from 'react';
import {Text,View, StyleSheet} from 'react-native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import { Ionicons } from '#expo/vector-icons';
class PageTemplate extends Component {
render() {
return (
<View
style={{
flexDirection: 'row',
height: 130,
alignSelf: 'stretch',
width: '100%'
}}>
<View style={{backgroundColor: 'black', alignSelf: 'stretch',width: '100%'}} />
<View style=
{{position:'absolute',
marginTop: '16%',
marginLeft: '3%',
display: 'flex',
flexDirection: 'row',
flex:1
}}>
<TouchableOpacity onPress={this.props.navigate}>
<Ionicons name="ios-arrow-dropleft" size={32} color="white" />
</TouchableOpacity>
</View>
<Text
style={{
position: 'absolute',
marginTop: '15%',
marginLeft: '12%',
color: 'white',
fontSize: 30}}
>
{this.props.title}
</Text>
</View>
);
}
}
export default PageTemplate;
I have a tab called profile which navigates through a list item to get to an account edits page:
Profile
import React from 'react';
import { StyleSheet, Text, View, Image, TouchableOpacity, TouchableHighlight } from 'react-native';
import { Ionicons } from '#expo/vector-icons';
import { List, ListItem } from 'react-native-elements'
import GenerateQR from './generateQR';
import PageTemplate from './smallComponents/pageTemplate';
import pic from '../assets/bigRate.png'
export default class Profile extends React.Component {
render() {
const { navigate } = this.props.navigation;
navigateBack=()=>{
navigate('Queue')
}
return(
<React.Fragment>
<PageTemplate title={'Profile Settings'} navigate={navigateBack} />
{/*<Image source={pic} />*/}
{/** Frst Section */}
<View style={{
//backgroundColor:'blue'
}}>
<Text style={styles.section}>Account Information</Text>
</View>
<TouchableOpacity
onPress={()=>{navigate('EditAccount')}}
style={{position: 'absolute',
marginTop:'32%',
flex:1,
flexDirection: 'row',
flexWrap: 'wrap'}}>
<View style={{
marginLeft:'5%',
flex:1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'flex-start',
//backgroundColor:'yellow',
alignItems: 'center',
//borderRadius:50,
//height:'60%'
}} >
<Ionicons style={{marginLeft:'20%'}} name="ios-person" size={72} />
</View>
<View style={{paddingTop:50,
marginRight:'40%',
flex:2,
flexDirection: 'row',
flexWrap: 'wrap',
//backgroundColor: 'red'
}}
>
<Text>Sylvester Stallone</Text>
<Text>+1 646-897-0098</Text>
<Text>SlyLone#gmail.com</Text>
</View>
</TouchableOpacity>
{/**add line section */}
</React.Fragment>
);
}
}
const styles = StyleSheet.create({
option : {
//position: 'absolute',
marginLeft:'7%',
alignSelf: 'stretch',
width: '100%',
height: '15%',
//flexWrap: 'wrap',
justifyContent:'space-between',
//padding:20
},
section : {
fontSize:20,
marginLeft:'5%'
}
})
/**
*
*
*
<View style={styles.option}>
<Ionicons name="ios-gift" size={32} />
<TouchableHighlight>
<Text>Rewards</Text>
</TouchableHighlight>
</View>
*
*/
Ideally it be nice to drop the arrow icon and move the header up keeping react-navigations arrow.
If you want to get rid of the arrows, you can create your own headers.
Example
class LogoTitle extends React.Component {
render() {
return (
<Image
source={require('#expo/snack-static/react-native-logo.png')}
style={{ width: 30, height: 30, alignSelf:"center" }}
/>
);
}
}
class HomeScreen extends React.Component {
static navigationOptions = {
// headerTitle instead of title
headerTitle: () => <LogoTitle />,
headerLeft: () => (
<Button
onPress={() => alert('This is a button!')}
title="back"
color="#fff"
/>
),
};

React native elements header background image

I made a header using react native elements, and I want to add background image into it. Is there anyway to do it?
I am using react-native-elements: "^0.19.1"
Here is my header code
render() {
return (
<View style={{ paddingTop: Constants.statusBarHeight, backgroundColor: color.light_grey }}>
<Header
leftComponent={this.props.left ? this.props.left : <IconWrapper name='menu' color='black' size={28} style={styles.icon} onPress={() => Actions.drawerOpen()} />}
centerComponent={<Text style={styles.headerText}>{this.props.title}</Text>}
rightComponent={this.props.right ? this.props.right : <IconWrapper name='handbag' type='simple-line-icon' color='black' size={28} style={styles.icon} onPress={() => Actions.BagContents()} />}
outerContainerStyles={[styles.headerOuterContainer, { height: 0.08 * windowHeight() }]}
/>
</View>
)
}
}
You can always create your own <Header/> component, probably will take you more time but you will be able to understand it and edit it as you like. I created a simple Header component to show you how you can accomplish adding a background image to your header. See the snack #abranhe/stackoverflow-56729412
Header.js
import React, { Component } from 'react';
import { View, TouchableOpacity, StyleSheet, Dimensions, ImageBackground } from 'react-native';
export default class Header extends Component {
renderContent() {
return (
<View style={styles.content}>
<View style={styles.left}>{this.props.left}</View>
<View style={styles.center}>{this.props.center}</View>
<View style={styles.right}>{this.props.right}</View>
</View>
);
}
renderHeaderWithImage() {
return (
<ImageBackground style={styles.container} source={this.props.imageSource}>
{this.renderContent()}
</ImageBackground>
);
}
renderHeaderWithoutImage() {
return (
<View style={[{ backgroundColor: '#f8f8f8' }, styles.container]}>
{this.renderContent()}
</View>
);
}
render() {
return this.props.image
? this.renderHeaderWithImage()
: this.renderHeaderWithoutImage();
}
}
const styles = StyleSheet.create({
container: {
top: 0,
position: 'absolute',
width: Dimensions.get('window').width,
backgroundColor: '#f8f8f8',
borderBottom: 1,
borderColor: '#f8f8f8',
shadowColor: '#000',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.5,
},
content: {
width: '100%',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginTop: Dimensions.get('window').height * 0.03,
height: Dimensions.get('window').height * 0.045,
},
left: {
marginHorizontal: 5,
},
center: {
marginHorizontal: 5,
},
right: {
marginHorizontal: 5,
},
});
and then on when you want to use the Header component you can set the image prop to true, eg:
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Ionicons } from '#expo/vector-icons';
import Header from './components/Header';
export default () => {
return (
<View>
<Header
image
imageSource={{ uri: 'https://yourimage.png' }}
left={<Ionicons name="md-arrow-round-back" size={25} />}
center={<Text>Projects</Text>}
right={<Ionicons name="ios-camera" size={25} />}
/>
</View>
);
};
and then if you set the image prop to false you will remove the image from the background.
<Header
image={false}
imageSource={{ uri: 'https://yourimage.png' }}
left={<Ionicons name="md-arrow-round-back" size={25} />}
center={<Text>Projects</Text>}
right={<Ionicons name="ios-camera" size={25} />}
/>
There is ReactNative's component ImageBackground you can use it.
like this,
<ImageBackground source={...} style={{width: '100%', height: '100%'}}>
<Header
leftComponent={this.props.left ? this.props.left : <IconWrapper name='menu' color='black' size={28} style={styles.icon} onPress={() => Actions.drawerOpen()} />}
centerComponent={<Text style={styles.headerText}>{this.props.title}</Text>}
rightComponent={this.props.right ? this.props.right : <IconWrapper name='handbag' type='simple-line-icon' color='black' size={28} style={styles.icon} onPress={() => Actions.BagContents()} />}
outerContainerStyles={[styles.headerOuterContainer, { height: 0.08 * windowHeight() }]}
/>
</ImageBackground>
You can always style it your way.
assuming you are using react-navigation
You need to add a custon header component in navigationOptions,
import { Header } from 'react-navigation';
static navigationOptions = ({ navigation }) => {
return {
header: (props) => <View >
<LinearGradient
style={{ height: '100%', width: '100%', position: 'absolute' }}
start={{ x: 0, y: 1 }} end={{ x: 1, y: 0 }} colors={['#1A9EAE', '#4EAE7C']}
/>
<Header {...props} style={{ backgroundColor: Colors.transparent }} />
</View>,
}
}
This works for me.
<Header
backgroundImage={require("../../assets/images/btn-header-background.png")}
centerComponent={{
text: i18n.t("stats.title"),
style: { fontFamily: "FunctionLH", fontSize: 30, color: "#fff" }
}}
containerStyle={{
backgroundColor: "transparent",
justifyContent: "space-around"
}}
statusBarProps={{ barStyle: "light-content" }}
/>

How to cover the whole tabbed app using react native and router flux?

lightBox : {
width: Dimensions.get('window').width,
height: Dimensions.get('window').height,
backgroundColor: rgba(0,0,0,0.7),
position: 'absolute',
top: -0,
left: 0,
zIndex: 9999,
justifyContent : 'center'
}
The problem is: The Tab Bar is still active, the user are capable to navigate to other tab while it's busy. Also, the navigation bar is not covered.
Any solution for this ?
You might not have structured your scenes appropriately. The Lightbox styles seems to work fine for me. Here is a simple example demonstrating your requirement.
import React from "react";
import { StyleSheet, Text, View, Dimensions } from "react-native";
import {
Router,
Scene,
Actions,
Lightbox,
Tabs
} from "react-native-router-flux";
export default (App = () => (
<Router>
<Lightbox>
<Tabs key="root">
<Scene key="events" component={Events} title="Events" />
<Scene key="missions" component={Missions} title="Missions" />
<Scene key="share" component={Share} />
</Tabs>
<Scene key="uploading" component={Uploading} />
</Lightbox>
</Router>
));
class Missions extends React.Component {
render() {
return (
<View style={styles.container}>
<Text onPress={() => null}>Missions</Text>
</View>
);
}
}
class Uploading extends React.Component {
render() {
return (
<View
style={{
width: Dimensions.get("window").width,
height: Dimensions.get("window").height,
backgroundColor: "rgba(0, 0, 0, 0.7)",
position: "absolute",
top: 0,
left: 0,
zIndex: 9999,
justifyContent: "center",
alignItems: "center"
}}
>
<Text style={{ color: "white" }} onPress={() => null}>
Uploading
</Text>
</View>
);
}
}
class Share extends React.Component {
render() {
return (
<View style={styles.container}>
<Text onPress={() => Actions.uploading()}>Share</Text>
</View>
);
}
}
class Events extends React.Component {
render() {
return (
<View style={styles.container}>
<Text onPress={() => null}>Events</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
}
});

React navigation status bar alert

I'm using react-native-status-bar-alert in combination with react-navigation.
In the latest version of react-navigation there's a problem with the height.
The height of the header is too big when the alert is active.
Anyone else experienced this issue and has a solution?
I think you should use a plugin: navigationbar-react-native
First, if you use react-navigation you should hide header-bar and use custom header-bar
export const RootStack = createStackNavigator(
{
Home: {
screen: HomeComponent,
navigationOptions: {
header: null,
},
},
},
{
initialRouteName: 'Home',
}
);
1, Install package
npm i navigationbar-react-native --save
2, Using
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,Image,
View,
TouchableOpacity,
} from 'react-native';
import NavigationBar from 'navigationbar-react-native';
const ComponentLeft = () => {
return(
<View style={{ flex: 1, alignItems: 'flex-start'}} >
<TouchableOpacity style={ {justifyContent:'center', flexDirection: 'row'}}>
<Image
source={require('./img/ic_back.png')}
style={{ resizeMode: 'contain', width: 20, height: 20, alignSelf: 'center' }}
/>
<Text style={{ color: 'white', }}>Back Home</Text>
</TouchableOpacity>
</View>
);
};
const ComponentCenter = () => {
return(
<View style={{ flex: 1, }}>
<Image
source={require('./img/ic_logo.png')}
style={{resizeMode: 'contain', width: 200, height: 35, alignSelf: 'center' }}
/>
</View>
);
};
const ComponentRight = () => {
return(
<View style={{ flex: 1, alignItems: 'flex-end', }}>
<TouchableOpacity>
<Text style={{ color: 'white', }}> Right </Text>
</TouchableOpacity>
</View>
);
};
class App extends Component {
render() {
return (
<View style={styles.container}>
<NavigationBar
componentLeft = { () => {<ComponentLeft /> }
componentCenter = { () => {<ComponentCenter /> }
componentRight = { () => {<ComponentRight /> }
navigationBarStyle= {{ backgroundColor: ''#215e79'' }}
statusBarStyle = {{ barStyle: 'light-content', backgroundColor: '#215e79' }}
/>
</View>
);
}
}
Easy create custom header bar in react native