Navigation Bar - React Native - navigationbar

I am creating a mobile application with React Native and I decided to use a navigation bar that comes from the site 'https://github.com/beefe/react-native-navigation-bar', but I do not know how to use it in my code.
I would like you to send me examples of the navigation bar of the site 'https://github.com/beefe/react-native-navigation-bar'.

This document is clearly shows how to use this component. Just 2 steps:
Install package.
npm install react-native-navigation-bar --save
Import and use. Change attributes the way you like.
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import NavigationBar from 'react-native-navigation-bar';
export default class Example extends Component {
render() {
return (
<View>
<NavigationBar
title='Main title'
height={50}
leftButtonTitle='back'
rightButtonTitle='forward'
/>
<Text>ABC</Text>
</View>
);
}
}

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(
{
App: {
screen: AppComponent,
navigationOptions: {
header: null,
},
},
},
{
initialRouteName: 'App',
}
);
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

Related

Hello,everyone I am new to react native, I am trying to build a page when you on the page and the camera shows up like snap chat camera on the phone

import React, { useState, useEffect, Component} from 'react';
import { StyleSheet, Text, TouchableOpacity, View, SafeAreaView, Image } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import { Permissions } from 'expo';
import { Container, Content, Header, Item, Icon, Input, Button } from 'native-base';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { Camera,CameraType } from 'expo-camera';
export default function VideoScreen() {
const [hasCameraPermission, sethasCameraPermission] = useState(null);
const [camera, setCamera] = useState(null);
const [image, setImage] = useState(null);
const [type, setType] = useState(Camera.Constants.Type.front);
useEffect(() => {
(async () => {
const cameraStatus = await Camera.requestCameraPermissionsAsync();
sethasCameraPermission(cameraStatus.status === 'granted');
})();
}, []);
const takePicture = async () => {
if (Camera) {
const data = await camera.takePictureAsync(null)
setImage(data.uri);
}
}
if (hasCameraPermission === false) {
return <Text>No Camera Access</Text>;
}
return (
<View style={{ flex: 1 }}>
<Camera ref={ref => setCamera(ref)} style={{ flex: 1, justifyContent:'space-between' }}>
<Header
searchBar rounded
style={{position: 'absolute', backgroundColor: 'transparent',
left:0, top: 0, right: 0, zIndex:100}}>
<View style={{flexDirection:'row', flex:4}}>
<Icon name="campfire" style={{ color: 'white' }} />
<Item style={{ backgroundColor: 'transparent' }}>
<Icon name="ios-search" style={{color:'white',fontSize:24, fontWeight:'bold'}}></Icon>
<Input placeholder="Search"
placeholderTextColor="white"/>
</Item>
</View>
<View style={{flexDirection:'row', flex:2,justifyContent:'space-around'}}>
<Icon name="ios-flash" style={{ color: 'white', fontWeight:'bold'}} />
<Icon
name="ios-reverse-camera"
style={{ color: 'white', fontWeight: 'bold' }}
onPress={() => {
setType(type ===
Camera.Constants.Type.front ?
Camera.Constants.Type.back :
Camera.Constants.Type.front)
}} />
</View>
</Header>
<View style={{ flexDirection: 'row', justifyContent: 'space-between', paddingHorizontal: 10, marginBottom: 15,alignItems:'flex-end'}} >
<MaterialCommunityIcons name="message-reply"
style={{ color: 'white', fontSize: 36 }}>
</MaterialCommunityIcons>
<View style={{ alignItems: 'center' }}>
<MaterialCommunityIcons name="circle-outline"
style={{ color: 'white', fontSize: 100 }}
onPress={() => takePicture()}>
{image && <Image source={{uri:image}} style={{flex:1}}/>}
</MaterialCommunityIcons>
<Icon name="ios-images" style={{ color: 'white', fontSize: 36 }} />
</View>
<MaterialCommunityIcons name="google-circles-communities"
style={{ color: 'white', fontSize: 36 }}>
</MaterialCommunityIcons>
</View>
</Camera>
</View>
  );
};
I am trying to Add a camera page like snapchat camera when you open the app the camera shows up,and you can take the picture or record a video on that, I have try my best to write the code and check agian, and I still keep getting the mistakes saying Rendor Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed
up default and named imports.
Check the render method of VideoScreen.

How can I create a middle tab button like these with React Navigation?

I need to create a bottom tab navigation with React Navigation (v6) like this one:
So far what I did was:
import * as React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
function HomeScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home!</Text>
</View>
);
}
function SettingsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator>
<Tab.Screen name="ForYou" component={ForYouScreen} />
<Tab.Screen name="Maps" component={MapsScreen} />
<Tab.Screen name="Premium" component={PremiumScreen} />
<Tab.Screen name="Shop" component={ShopScreen} />
<Tab.Screen name="Media" component={MediaScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}
But I'm not sure the right approach for styling, should I try to style 3rd tab button somehow? or should I create a 4 tabs navigation and create a floating button on the middle, but in this case how do I create room for it within the tabs on the middle?
Any idea or snippet is appreciated.
What you can do is add a custom tabBarButton and use svg in it like this (you will need to install react-native-svg)
//background svg which will create space
const TabBg = ({ color = '#FFFFFF', ...props }) => {
return (
<Svg width={75} height={61} viewBox="0 0 75 61" {...props}>
<Path
d="M75.2 0v61H0V0c4.1 0 7.4 3.1 7.9 7.1C10 21.7 22.5 33 37.7 33c15.2 0 27.7-11.3 29.7-25.9.5-4 3.9-7.1 7.9-7.1h-.1z"
fill={color}
/>
</Svg>
);
};
//custom tabBarButton
const TabBarAdvancedButton = ({ bgColor, ...props }) => {
return (
<View style={styles.container} pointerEvents="box-none">
<TabBg color={bgColor} style={styles.background} />
<TouchableOpacity
style={styles.button}
onPress={props.onPress}>
// any image or icon here
</TouchableOpacity>
</View>
);
};
const styles = StyleSheet.create({
container: {
position: 'relative',
width: 75,
alignItems: 'center'
},
background: {
position: 'absolute',
top: 0,
},
button: {
top: -22.5,
justifyContent: 'center',
alignItems: 'center',
width: 50,
height: 50,
borderRadius: 27,
backgroundColor: '#E94F37',
},
buttonIcon: {
fontSize: 16,
color: '#F6F7EB'
}
});
// add your custom tabBarButton component
<Tab.Screen
name="Premium"
component={PremiumScreen}
options={{
tabBarButton: (props) => (
<TabBarAdvancedButton
bgColor={barColor} // background space color.
{...props}
/>
)
}}
/>
You can customize this the way you want if you need more help you can follow the below mentioned article. This works with react-navigation v6.
ReactNative: TabBar With Float Button

CSS breaking when using padding

I have a JS class
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { Avatar, Accessory } from 'react-native-elements';
import PropTypes from 'prop-types';
import MenuButton from './MenuButton';
import AppStyles from '../AppStyles';
import Api from '../Api';
export default class DrawerContainer extends React.Component {
render() {
const { navigation, onLogout } = this.props;
return (
<View style={styles.content}>
<Avatar size={100}
rounded
source={{
uri:
'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg',
}}
/>
<View style={styles.container}>
<MenuButton
title="Home"
source={AppStyles.iconSet.home}
onPress={() => {
navigation.navigate('Home');
}}
/>
<MenuButton
title="Logout"
source={AppStyles.iconSet.logout}
onPress={() => {
onLogout();
Api.logout();
}}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
content: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
paddingTop: 75
},
container: {
flex: 1,
alignItems: 'center',
paddingHorizontal: 20,
alignItems: 'flex-end'
},
});
DrawerContainer.propTypes = {
navigation: PropTypes.object,
onLogout: PropTypes.func,
};
Here is the output generated from the same.
What I want to achieve is to have a gap between the image and the icons displayed. I tried using padding but the text overflows with the same. Can anyone suggest as to what wrong am I doing here?
container: {
flex: 1,
alignItems: 'center',
paddingHorizontal: 20,
alignItems: 'flex-end'
margin-top: 10%;
},
Try to reate a margin-top for .container

React Navigation - padding bottom on header not working

In my React-Native app I have an icon and SearchBar in my header (from react navigation).
The following code:
static navigationOptions = ({ navigation }) => {
const { params = {} } = navigation.state;
return {
headerTitle:
<View style={{ flex: 1, flexDirection: "row", paddingHorizontal: 15, alignItems: "center" }}>
<StatusBar default style={{ flex: 1, height: getStatusBarHeight() }} />
<Icon name="chevron-left" size={28} />
<SearchBar round platform={"default"} placeholder="Search" containerStyle={{
flex: 1, backgroundColor: "transparent"
}} />
</View>,
headerStyle: {
backgroundColor: '#e54b4d',
}
};
}
outputs this:
So far so good. However, I want to have padding below the SearchBar. In other words, I want to have the distance from the top of the screen to the SearchBar as a padding below the SearchBar. (I can obtain the distance value using getStatusBarHeight() from rn-status-bar-height)
However, if I put paddingBottom: getStatusBarHeight() to the headerStyle, I get this result:
Basically, now I have the padding that I wanted, however, the StatusBar overlaps with the SearchBar.
How can I put paddingBottom without making the StatusBar and SearchBar overlap?
To change the padding of the header in your case you'll need to change headerTitleContainerStyle and not headerTitle.
For example :
headerTitleContainerStyle: { paddingVertical: 10 }
You can still check the doc.
For ios you will need to set backgroundColor.Below code is fit for android ios both.Hope it helps you.
import React, { Component } from 'react';
import { getStatusBarHeight } from 'react-native-status-bar-height';
import {
Modal,
Button,
View,
Text,
StyleSheet,
StatusBar,
Image,
Platform,
} from 'react-native';
import { SearchBar, Icon } from 'react-native-elements';
export default class AssetExample extends React.Component {
static navigationOptions = ({ navigation }) => {
const { params = {} } = navigation.state;
return {
headerTitle: (
<View
style={{
flex: 1,
backgroundColor: Platform.OS === 'ios' ? '#e54b4d' : '',
alignItems: 'center',
flexDirection: 'row',
paddingHorizontal: 10,
height: StatusBar.currentHeight,
}}>
<Icon name="chevron-left" size={28} />
<SearchBar
round
platform={'default'}
placeholder="Search"
containerStyle={{
flex: 1,
backgroundColor: 'transparent',
}}
/>
</View>
),
headerStyle: {
backgroundColor: '#e54b4d',
},
};
};
render() {
return (
<View style={styles.container}>
<Text>Screen</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: { flex: 1, alignItems: 'center', justifyContent: 'center' },
});
when i checked your code on my device its properly viewing with padding.

How to use Flex in a Row for its two Child Views in React Native?

My code is like this---
import React from 'react';
import {View,Text,Alert,StyleSheet} from 'react-native';
const data = ['All','Electronics','Baby and Child','Property'];
const styles=StyleSheet.create({
itemStyles: {
color: "#F456A3",
fontSize:30,
fontWeight:"bold",
},
CategoryStyle: {
flex:1,
justifyContent:'center',
flexDirection:'row'
}
});
export default class FilterScreen extends React.Component {
constructor(){
super();
this.test;
}
renderCategories = () =>{
//Alert.alert(data[0]);
this.test=data.map(item => {
return(
<View key={item} style={styles.CategoryStyle}>
<Text style={styles.itemStyles}>{item}</Text>
</View>
)
})
return this.test;
}
render(){
return(
<View>
<Text>hello world</Text>
{this.renderCategories()}
</View>
)
}
}
I have to apply styling to the Text present in render categories such that it should come with 2 text in a row. So, here there will be 2 rows with 2 texts.
How can that be done?
For styles.itemStyles set it to width: '50%' and add flexWrap to parent. Try this:
const styles=StyleSheet.create({
itemStyles: {
color: "#F456A3",
fontSize:30,
fontWeight:"bold",
width: '50%' ///////////////// i added this
},
CategoryStyle: {
flex:1,
justifyContent:'center',
flexDirection:'row',
flexWrap: 'wrap' ///////// added this
}
});
Here is a snack expo that works - https://snack.expo.io/BJY_WnrrG
import React, { Component } from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<Text style={[styles.text, styles.textPink]}>a</Text>
<Text style={[styles.text, styles.textBlue]}>b</Text>
<Text style={[styles.text, styles.textPink]}>c</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
height: '100%',
flexDirection: 'row',
justifyContent: 'flex-end',
flexWrap: 'wrap',
alignContent: 'space-around',
alignItems: 'flex-start',
backgroundColor: 'steelblue'
},
text: {
width: '50%'
},
textBlue: {
backgroundColor: 'skyblue'
},
textPink: {
backgroundColor: 'pink'
}
});
When items wrap, you get the new style property of alignContent check it out - http://facebook.github.io/react-native/docs/layout-props.html#aligncontent
Also when items wrap, justifyContent only affects rows where there is space left over, as seen in the third text item above.

Resources