In React Native how to create UI same as attached image? - react-native

I have to create user interface same as attached image. I have to wrap the tabs according to size of text which is dynamic(may be of different size). How to do this in React Native Screenshot of UI

You can use react-native-selectmultiple-button module if you are using UI to select many things.
You can run npm install react-native-selectmultiple-button --save
Example
import {
SelectMultipleButton,
SelectMultipleGroupButton
} from "react-native-selectmultiple-button";
<SelectMultipleButton
buttonViewStyle={{
borderRadius: 10,
height: 40
}}
textStyle={{
fontSize: 15
}}
highLightStyle={{
borderColor: "gray",
backgroundColor: "transparent",
textColor: "gray",
borderTintColor: ios_blue,
backgroundTintColor: ios_blue,
textTintColor: "white"
}}
multiple={true}
value={interest}
selected={this.state.multipleSelectedData.includes(interest)}
singleTap={valueTap => this._singleTapMultipleSelectedButtons(interest)}
/>;
<SelectMultipleGroupButton
containerViewStyle={{
justifyContent: "flex-start"
}}
highLightStyle={{
borderColor: "gray",
backgroundColor: "transparent",
textColor: "gray",
borderTintColor: ios_blue,
backgroundTintColor: "transparent",
textTintColor: ios_blue
}}
onSelectedValuesChange={selectedValues =>
this._groupButtonOnSelectedValuesChange(selectedValues)
}
group={multipleGroupData}
/>;

hi #shivam tiwari this can be acheived in many ways. in that one of the best method is using .map function with parent view styles of flexdirection : row and flexWrap: 'wrap'
also take a boolean value selected for each item in the array initially to false and update the particular item to true or false based on selection.
Please check below example:
let industries = this.state.industries
for (let i = 0; i < industries.length; i++) {
industries[i].selected = false
}
this.setState({industries: industries})
<View style={{ flexDirection: 'row', flexWrap: 'wrap', margin: 10, marginTop: 5 }}>
{this.renderIndustry(this.state.preferredIndustry)}
and in renderIndustry method you can do .map functionality like
//RENDER INDUSTRY
renderIndustry(data) {
if (data.length === 0) {
return null
}
return data.map((item, index) => {
return (
<CardView
key={item.industryname}
style={[styles.cardView, { backgroundColor: item.selected ? '#4291E2' : '#F9FAFB', borderWidth: 1, borderColor: item.selected ? '#4291E2' : '#E0E8F1' }]}
cardElevation={item.selected ? 3 : 0}
cardMaxElevation={5}
cornerRadius={10}
cornerOverlap={false}
>
<TouchableWithoutFeedback onPress={() => { this.selectIndustry(item, index) }}>
<View style={{
alignItems: 'center',
justifyContent: 'center',
height: '100%',
width: '100%',
backgroundColor: '#0000'
}}>
<Text style={{ fontSize: 14, color: item.selected ? '#fff' : '#000', margin: 15 }}>{item.industryname}</Text>
</View>
</TouchableWithoutFeedback>
</CardView>
);
});
}
and in onPress change the value of selected to true or false based on the previous value like....
//SELECT INDUSTRY
selectIndustry = (item, index) => {
let industries = this.state.industries
for (let i = 1; i <= industries.length; i++) {
if (industries[i - 1].industryid === item.industryid) {
industries[i - 1].selected = !industries[i - 1].selected
}
}
this.setState({ industries: industries })
}
HOPE this helps.... Happy coding!!

I searched for the solution and found a library named react-native-tag-select that fulfilled my requirement perfectly where I can customise the view according to my requirement. Thanks all who answered.
Adding some code sample:
Setup:
npm install --save react-native-tag-select
or
yarn add react-native-tag-select
Usage:
import { TagSelect } from 'react-native-tag-select';
export default class App extends React.Component {
render() {
const data = [
{ id: 1, label: 'Money' },
{ id: 2, label: 'Credit card' },
{ id: 3, label: 'Debit card' },
{ id: 4, label: 'Online payment' },
{ id: 5, label: 'Bitcoin' },
];
return (
<View style={styles.container}>
<TagSelect
data={data}
itemStyle={styles.item}
itemLabelStyle={styles.label}
itemStyleSelected={styles.itemSelected}
itemLabelStyleSelected={styles.labelSelected}
/>
</View>
);}

Related

Dynamic textinput inside Flatlist State update

From the sample code below i am trying to render textbox along with content inside Flatlist renderItem method and simultaneously trying to update textbox value.
Bad luck is on device after typing a single character, keyboard goes down.
Please find relevant Snack expo at : https://snack.expo.io/BJGMscqsS
Here is code :
import * as React from "react";
import {
View,
Text,
FlatList,
TextInput
} from "react-native";
export default class App extends React.Component {
state = {
data: []
};
updateItem = async (index, innerindex, itemAttributeVal) => {
console.log(index, innerindex, itemAttributeVal);
console.log(this.state.data);
let { data } = this.state;
data[index][innerindex].Value = itemAttributeVal;
this.setState({
data
});
console.log("newtry", this.state.data);
};
componentDidMount = async () => {
const listdata =
{
totalRow: "2",
coddindata: [
{
"SNo": "1",
"Item": "10",
"Material Code": "SERVICE LABOUR1",
"Invoice Description": "Labour for Services1",
"Invoice Item Amt": "765000.00",
"Approved Quantity": "85",
},
{
"SNo": "2",
"Item": "20",
"Material Code": "SERVICE LABOUR1",
"Invoice Description": "Labour for Services2",
"Invoice Item Amt": "810000.00",
"Approved Quantity": "90",
}
]
}
;
const codingData = listdata.coddindata;
var finalarr = [];
var finalarr1 = [];
codingData.map(datavalue => {
finalarr1 = [];
Object.keys(datavalue).map((key, val) => {
finalarr1.push({ Key: key, Value: datavalue[key] });
});
finalarr.push(finalarr1);
});
this.setState({
data: [...this.state.data, ...finalarr],
totalCount: listdata.totalRow
});
console.log(this.state.data);
};
render() {
return (
<View style={{ flex: 1,padding: 20}}>
<FlatList
style={{ padding: 20 }}
data={this.state.data}
renderItem={({ item, index }) =>
item.map((element, innerindex) => {
// console.log(" innerindex ",innerindex);
const inputstateval = this.state.data[index][innerindex].Value;
return (
<View
key={Math.random().toString()}
style={{
alignItems: "center",
height: 30,
justifyContent: "center",
flexDirection: "row",
lineHeight: 4
}}
>
<View style={{ flex: 1, alignSelf: "stretch" }}>
<Text>{element.Key}</Text>
</View>
{/* { element.Key != "total_amount" ? */}
{element.Key !== "Approved Quantity" ? (
<View
style={{ flex: 2, alignSelf: "stretch", marginTop: 3 }}
>
<Text>{element.Value}</Text>
</View>
) : (
<View
style={{ flex: 2, alignSelf: "stretch", marginTop: 3 }}
>
<TextInput
// defaultValue={element.Value}
placeholder={element.Key}
onChangeText={text => {
console.log("in onChangeText--- ");
this.updateItem(index, innerindex, text);
}}
value={this.state.data[index][innerindex].Value}
style={{
paddingTop: 1,
fontSize: 16,
borderWidth: 1,
height: 30,
marginTop: -6
}}
/>
</View>
)}
</View>
);
})
}
keyExtractor={item => Math.random().toString()}
/>
</View>
);
}
}
In your code, you just need to fix the lines 87, and 132 to something like this:
87: key={'key'}
132: keyExtractor={(item) => ''+item}
So react knows that even after render, those text inputs are the same as the ones before the setState update.
Still, I cant manage to fix this same bug in my project.

Control word/text break on React Native <Text> element

Is there a way to control the word-break behaviour for text within a Text component? With a multiple-line Text component on iOS it automatically breaks the text where there are word breaks (I haven't checked android yet, but I'd need it to work there too). I was hoping to change that behaviour to break on the per-character level, like you can do this CSS rule:
word-break: break-all;
transform <text>str</text> to <View><text>s</text><text>t</text><text>r</text></View> by using split & map!
export default class PageCard extends React.Component {
constructor(props) {
super(props);
this.state = {
tail: false,
longWord: 'longWord longWord bbbbbbbbbbbbbbbbbbbbb longWord longWord longWord',
longWordTail: ' longWord longWord longWord bbbbbbbbbbbbbbbbbbbbb longWord longWord longWord',
longWordTail2: ' longWord longWord bbbbbbbbbbbbbbbbbbbbb longWord longWord longWord',
};
}
render() {
return (
<ScrollView style={{flex: 1, paddingTop: 60, paddingHorizontal: 10}}>
<View style={Styles.breakWordWrap}>
<Text numberOfLines={2} ellipsizeMode="tail" style={Styles.breakWord}>
{this.state.longWord}
</Text>
</View>
<View style={Styles.breakWordWrap}>
{
this.breakWord(this.state.longWord)
}
</View>
<View style={[Styles.breakWordWrap, Styles.breakWordWrapTail]}>
{
this.breakWord(this.state.longWordTail)
}
</View>
<View style={[Styles.breakWordWrap, Styles.breakWordWrapTail]}>
{
this.breakWord(this.state.longWordTail, true)
}
</View>
{/*<View style={[Styles.breakWordWrap, Styles.breakWordWrapTail]}>*/}
{/* {*/}
{/* this.breakWord(this.state.longWordTail2, true)*/}
{/* }*/}
{/*</View>*/}
</ScrollView>
)
}
breakWord = (str = '', tail = false) => {
let strArr = (tail ? str + ' ' : str).split('');
return strArr.map((item, index) => tail && strArr.length === index + 1 ?
<Text key={item + index} style={[Styles.breakWord, Styles.breakWordTail, !this.state.tail && Styles.breakWordTailHide]}>...</Text> :
(tail && strArr.length === index + 2 ? <Text key={item + index} style={[Styles.breakWord]} onLayout={this.breakWordLast}>{item}</Text>
: <Text key={item + index} style={[Styles.breakWord]}>{item}</Text>)
);
}
breakWordLast = (e) => {
console.log(e.nativeEvent.layout)
if (e.nativeEvent.layout.y > 50) {
this.setState({
tail: true
})
}
}
}
const Styles = {
box: {
marginTop: 10,
},
title: {
fontWeight: 'bold',
color: '#333',
textAlign: 'center'
},
breakWordWrap: {
flexWrap: 'wrap',
flexDirection: 'row',
// not
borderWidth: 1,
marginTop: 30,
},
breakWordWrapTail: {
position: 'relative',
height: 50,
overflow: 'hidden'
},
breakWord: {
lineHeight: 25
},
breakWordTail: {
position: 'absolute',
backgroundColor: '#fff',
right: 0,
bottom: 0,
height: 25
},
breakWordTailHide: {
opacity: 0
}
}
There is an Android-only textbreakstrategy property for Text components that allows some control on how a text should be split. The property values map to Android's native android:breakStrategy values.
This property does not seem to translate to iOS though.
Otherwise, if you have preknowledge about the Text value, you could indicate text split with a Soft Hyphen
<Text>aaaaaaaaaaaaaaaaaa bbbbbbbbbbb­CCCCC.</Text>
This would render as:
aaaaaaaaaaaaaaaaaa bbbbbbbbbbb-
CCCCC.
If neither suffice, I suppose this is beyond the capabilities of a Text component and you may have to revert to another component. Maybe one that renders simple html.
Try add flexWrap: "wrap" to the style of the Text component
Example:
Code
<View style={styles.container}>
<Text style={styles.text}>{text}</Text>
</View>
Style
export default StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
},
text: {
width: 0,
flexGrow: 1,
flex: 1,
}
});
There is the possibility with following code
<Text style={{ flexShrink: 1 }}>

How to select a single radio button at a time in react native flatlist

I am using react-native-radio-button to implement a flatlist with radio button as shown in the image.
[![enter image description here][1]][1]
But i am unable to select a single radio button at a time in flatlist.
Here is my code
import React from 'react';
import { StyleSheet, View, Text, FlatList, TouchableOpacity, Image, LayoutAnimation, UIManager, Platform } from 'react-native';
import RadioButton from 'react-native-radio-button';
import PHARMACY from './api/mockPharmacyList';
import { Colors, Fonts } from '../../styles';
interface IState {
selected: number;
selectedIndex: number;
data: any;
expanded: boolean;
checked: boolean;
}
export class TransferToPharmacy extends React.Component<{}, IState> {
constructor(props) {
super(props);
this.state = {
data: PHARMACY,
selected: 0,
selectedIndex: 0,
expanded: true,
checked: false,
};
this.onPress = this.onPress.bind(this);
this.renderItem = this.renderItem.bind(this);
this.renderSeparator = this.renderSeparator.bind(this);
this._keyExtractor = this._keyExtractor.bind(this);
this.changeLayout = this.changeLayout.bind(this);
this.onCheck = this.onCheck.bind(this);
if (Platform.OS === 'android') {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
}
changeLayout = () => {
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
this.setState({ expanded: false });
}
getInitialState() {
return {
value: 0,
};
}
onPress(value) {
this.setState({ selected: value });
}
_keyExtractor = (item, index) => item.id;
onCheck = () => {
const { checked } = this.state;
if (checked === true) {
this.setState({ checked: false });
} else {
this.setState({ checked: true });
}
}
renderItem(data) {
const { item } = data;
return (
<View style={styles.itemBlock}>
<TouchableOpacity >
<View style={styles.arrowIconStyle}>
<Text style={styles.pharmacyText}>{item.name}</Text>
<RadioButton
innerColor={Colors.darkBlue}
outerColor={Colors.lightGray}
animation={'bounceIn'}
isSelected={this.state.selectedIndex === 0}
onPress={this.onPress}
/>
</View>
</TouchableOpacity>
<Text>{item.key1}</Text>
<View style={{ height: this.state.expanded === true ? 90 : 0, overflow: 'hidden' }}>
<View style={{ flexDirection: 'row', marginTop: 5, padding: 10 }}>
<Image style={[styles.itemImage, { width: 15, height: 15, margin: 1 }]} source={require('./images/map_pic_icon.png')} />
<Text style={styles.itemText}>{item.location}</Text>
</View>
<View style={{ flexDirection: 'row', marginTop: 5, padding: 10 }}>
<Image style={[styles.itemImage, { width: 15, height: 15, margin: 1 }]} source={require('./images/phone_icon.png')} />
<Text style={styles.itemText}>{item.phone}</Text>
</View>
</View>
</View>
);
}
renderSeparator() {
return <View style={styles.separator} />;
}
render() {
return (
<View style={styles.container} >
<Text style={styles.textStyle}>Transfer to Pharmacy</Text>
<View style={styles.childViewStyle}>
<FlatList
keyExtractor={this._keyExtractor}
data={this.state.data}
renderItem={this.renderItem}
ItemSeparatorComponent={this.renderSeparator}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
textStyle: {
fontSize: 18,
color: Colors.black,
marginTop: 30,
marginLeft: 20
},
childViewStyle: {
margin: 20,
},
itemBlock: {
paddingVertical: 15,
},
itemImage: {
width: 50,
height: 50,
borderRadius: 25,
margin: 10
},
itemText: {
fontSize: 16,
justifyContent: 'center',
color: Colors.darkySkyBlue
},
itemName: {
fontSize: 20,
color: Colors.black,
},
separator: {
borderRadius: 4,
borderWidth: 1,
borderColor: Colors.lightGray,
},
pharmacyText: {
fontSize: 16,
fontFamily: Fonts.bold,
color: Colors.black
},
radioStyle: {
marginTop: 10,
marginRight: 50,
justifyContent: 'space-between'
},
arrowIconStyle: {
flexDirection: 'row',
justifyContent: 'space-between',
padding: 10
// flex: 1
}
});
with this code i am not able to select the radio button
Please let me know where it is going wrong as i am unable to select radio button in the flatlist separately.
i have changed onPress() like this
onPress( index) {
this.setState({ selected: index, });
}
and in renderItem method i have changed it like this
const { item, index } = data;
<RadioButton
innerColor={Colors.darkBlue}
outerColor={Colors.lightGray}
animation={'bounceIn'}
isSelected={this.state.selected === index}
onPress={() => this.onPress(index)}
/>
Now the output is like this
Now the first radio button is selected but when i tried to select other radio buttons they are not getting selected.
Here is my mock data file which is used for Flatlist.
export const PHARMACY = [
{
key: 0,
name: 'Plaza Pharmacy',
type: 'Urgent Care Center - 4.01 mi',
location: '3417 Gaston Avenue, Suite 195\n Dallas, TX 75202',
phone: '469.764.7100',
},
{
key: 1,
name: 'Courtyard Pharmacy',
type: 'Urgent Care Center - 4.09 mi',
location: '5236 West University Drive, Suite 1900\n MCKINNEY, TX 75071',
phone: '969.264.7190',
},
{
key: 2,
name: 'Outptaient Pharmacy at the Cancer Center',
type: 'Urgent Care Center - 4.66 mi',
location: '3800 Gaylord Parkway, Ste 110\n FRISCO, TX 75034',
phone: '890.664.8130',
},
{
key: 3,
name: 'Carrolton Pharmacy',
type: 'Urgent Care Center - 4.08 mi',
location: '5236 West University Drive, Suite 1900\n MCKINNEY, TX 75071',
phone: '969.264.7190',
},
{
key: 4,
name: 'Garland Pharmacy',
type: 'Urgent Care Center - 22.11 mi',
location: '3417 Gaston Avenue, Suite 195\n Dallas, TX 75202',
phone: '469.764.7100',
},
];
I am exporting this const PHARMACY and importing it in my class and set this to a state variable "data".
you can do something like this in renderItem
renderItem = ({item, index}) => {
.....
<RadioButton
innerColor={Colors.darkBlue}
outerColor={Colors.lightGray}
animation={'bounceIn'}
isSelected={this.state.selectedIndex === index}
onPress={() => {this.onPress(index)}}
/>
}
and replace onPress with
onPress = (index) => {
this.setState({ selectedIndex: index });
}
and update FlatList with extraData props as FlatList needs to be re-rendered as
<FlatList
keyExtractor={this._keyExtractor}
data={this.state.data}
renderItem={this.renderItem}
ItemSeparatorComponent={this.renderSeparator}
extraData={this.state}
/>
You can refer in snack here
First, you need to get the index of the current item like so:
const { item, index } = data;
After you get the index of the current item you can then check if the current radio button is selected or not and for changing the radio button you need to pass the value of the current index to the onPress function.
<RadioButton
innerColor={Colors.darkBlue}
outerColor={Colors.lightGray}
animation={'bounceIn'}
isSelected={this.state.selected === index}
onPress={() => this.onPress(index)}
/>

React Native - Changing States in an Array of another file

Hey Everyone :) This is my first post here, hope I am doing everything correctly!
I am currently working on a school project and using react-native for some weeks now.
My Problem:
I have the file data.js:
const cardOne_1 = require("../images/Vergleiche/Eisbär.jpg");
const cardTwo_1 = require("../images/Vergleiche/Android.jpg");
const cardThree_1 = require("../images/Vergleiche/Han_Solo_Alt.jpg");
const cardOne_2 = require("../images/Vergleiche/Gorilla.jpg");
const cardTwo_2 = require("../images/Vergleiche/Apple.jpg");
const cardThree_2 = require("../images/Vergleiche/Han_Solo_Jung.jpg");
export default[
{
image: cardOne_1,
image2: cardOne_2,
text: '53%',
text2: '47%',
title: 'Icebear vs Gorilla',
check: false,
},
{
image: cardTwo_1,
image2: cardTwo_2,
text: '19%',
text2: '81%',
title: 'Android vs IOS',
check: true,
},
{
image: cardThree_1,
image2: cardThree_2,
text: '70%',
text2: '30%',
title: 'Han Solo',
check: false,
},
];
My Homescreen contains two of these Deckswipers (For better clarity I will show here only the code for the first one), which are used to compare two images:
Homescreen - With two DeckSwiper
import data from '../Data.js';
export default class SwipeCards2 extends Component {
_onSwipeLeft() {
this._deckSwiper1._root.swipeLeft();
this._deckSwiper2._root.swipeRight();
}
_onSwipeRight() {
this._deckSwiper2._root.swipeLeft();
this._deckSwiper1._root.swipeRight();
}
render() {
return (
<Container style={{ backgroundColor: '#ffffff' }}>
<View>
<DeckSwiper
ref={mr => (this._deckSwiper1 = mr)}
dataSource={data}
onSwipeRight={() => this._deckSwiper2._root.swipeLeft()}
onSwipeLeft={() => this._deckSwiper2._root.swipeRight()}
looping={true}
renderEmpty={() => (
<View style={{ alignSelf: 'center' }}>
<Text>Das war´s!</Text>
</View>
)}
renderItem={item => (
<Card
style={{
elevation: 3,
height: 335,
justifyContent: 'center',
width: Dimensions.get('window').width + 1,
marginLeft: -1,
marginTop: 0,
}}>
<TouchableWithoutFeedback onPress={() => this._onSwipeRight()}>
<CardItem cardBody style={{ alignItems: 'center' }}>
<Image
style={{
resizeMode: 'cover',
flex: 1,
height: 335,
}}
source={item.image}
/>
</CardItem>
</TouchableWithoutFeedback>
</Card>
)}
/>
</View>
</Container>
);
}
}
I want to set the state "check" in data.js to true, everytime the user does swipe to the right.
A Third Screen renders a List component, which should show the previous made decisions of the user. This list is based on "check" of data.js.
Screen 3 - List of all the decisions
I tried for almost three days and can not find any good solution!
Do you have any suggestions how to achieve this?
Thanks :)
I'm not sure how things work with this DeckSwiper component but since you are importing a static data, if you need to change the data you need to clone it and then change it. Assigning data clone to a state variable and then giving it to the component will reflect the changes to the component.
To change a property on a specific object in your array you also need an unique identifier like an ID or similar.
Example
import data from '../Data.js';
export default class SwipeCards2 extends Component {
constructor(props) {
super(props);
// clone the static data to state
this.state = {
data: [...data]
}
}
changingCheckFunction(obejctsUniqueId) {
this.setState((prevState) => {
// find the object's id
const itemIndex = prevState.data.findIndex(x => x.id == obejctsUniqueId);
// copy the item and assign the new checked value
const newItem = Object.assign({}, prevState.data[itemIndex], { checked: !prevState.data[itemIndex]});
// copy the previous data array
const newData = [...prevState.data];
// set the newItem to newData
newData[itemIndex] = newItem;
// return the new data value to set state
return { data: newData };
});
}
_onSwipeLeft() {
this._deckSwiper1._root.swipeLeft();
this._deckSwiper2._root.swipeRight();
}
_onSwipeRight() {
this._deckSwiper2._root.swipeLeft();
this._deckSwiper1._root.swipeRight();
}
render() {
return (
<Container style={{ backgroundColor: '#ffffff' }}>
<View>
<DeckSwiper
ref={mr => (this._deckSwiper1 = mr)}
dataSource={this.state.data}
onSwipeRight={() => this._deckSwiper2._root.swipeLeft()}
onSwipeLeft={() => this._deckSwiper2._root.swipeRight()}
looping={true}
renderEmpty={() => (
<View style={{ alignSelf: 'center' }}>
<Text>Das war´s!</Text>
</View>
)}
renderItem={item => (
<Card
style={{
elevation: 3,
height: 335,
justifyContent: 'center',
width: Dimensions.get('window').width + 1,
marginLeft: -1,
marginTop: 0,
}}>
<TouchableWithoutFeedback onPress={() => this._onSwipeRight()}>
<CardItem cardBody style={{ alignItems: 'center' }}>
<Image
style={{
resizeMode: 'cover',
flex: 1,
height: 335,
}}
source={item.image}
/>
</CardItem>
</TouchableWithoutFeedback>
</Card>
)}
/>
</View>
</Container>
);
}
}

How to add icon in each tab in custom Tabs?

I am using react-navigation .
I want to add icon for the tab.
CustomTabs.js from example directory
if you are to use react-native-vector-icon is much easier, just create an array like the one i created below, for all the names of the icon you want to use and if you want to use image, then you will have to use image links because the last time i checked react native won't allow you to load static assets dynamically.
Benefit of using an icon especially react-native-vector-icon:
Access to tonnes of iconsets.
Styling based on if its focused or not.
....and others things i can't remember.
`
.....
import Icon from 'react-native-vector-icons/Ionicons';
const styles = {
body: {
backgroundColor: '#3b4147',
height: 60,
},
tabWrapper: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
height: 50,
},
tabInnerWrapper: {
marginRight: 12,
marginLeft: 12,
justifyContent: 'center',
alignItems: 'center',
},
textStyle: {
fontSize: 12,
color: '#62666b',
},
focusTextStyle: {
fontSize: 12,
color: '#acafb1',
},
};
const {body, tabWrapper, tabInnerWrapper, textStyle, focusTextStyle} = styles;
const focusIconColor = '#acafb1';
const iconColor = '#62666b';
const IconNames = ['ios-compass-outline', 'ios-cut-outline', 'ios-chatboxes-outline'];
const IconNamesFocus = ['ios-compass', 'ios-cut', 'ios-chatboxes'];
const CustomTabBar = ({ navigation: { state, navigate }}) => {
const { routes } = state;
return (
<View style={body}>
<View style={tabWrapper}>
{routes && routes.map((route, index) => {
const focused = index === state.index;
return (
<TouchableOpacity
key={route.key}
onPress={() => navigate(route.routeName)}
style={tabInnerWrapper}
>
<Icon
name={focused ? IconNamesFocus[index] : IconNames[index]}
size={25}
color={focused ? focusIconColor : iconColor}
/>
<Text style={focused ? focusTextStyle : textStyle}>
{route.routeName}
</Text>
</TouchableOpacity>
);
})}
</View>
</View>
);
};
`