How can I put a border radius around my sectionList like in the image?
Something you can do is use the index and the number of items in the section list section to know when a border-radius is needed.
<SectionList
sections={sections}
renderItem={({ item, section, index }) => (
<ListItem
navigation={this.props.navigation}
section={section}
item={item}
index={index}
/>
)}
/>
Inside the ListItem component do the following with the index and the section that was passed through to the ListItem.
We know that the first item in our list will always have an index of 0 thus we can set the borderTopLeftRadius and Right borderTopRightRadius to 10 when the index is 0. When the index reaches the amountOfItemsInSection(it's -1 because index always starts at 0) we know that we're at the end of the list and we need to close the borders.
function ListItem({
navigation,
section
item,
index,
}) {
const amountOfItemsInSection = section.data.length - 1
return (
<View
style={{
height: 50,
flex: 1,
flexDirection: "row",
justifyContent: "space-between",
marginHorizontal: 20,
backgroundColor: "grey",
borderWidth: 1,
borderBottomWidth: index === amountOfItemsInSection ? 1 : 0,
borderColor: 'grey',
borderTopLeftRadius: index === 0 ? 10 : 0,
borderTopRightRadius: index === 0 ? 10 : 0,
borderBottomLeftRadius: index === amountOfItemsInSection ? 10 : 0,
borderBottomRightRadius: index === amountOfItemsInSection ? 10 : 0
}}
>
{/* Left */}
<View>
<Text>{heading}</Text>
<Text>{description}</Text>
</View>
</View>
)
}
Image showing the result
Example
import React, {Component} from 'react';
import {
StyleSheet,
Text,
View,
SectionList,
Alert,
TouchableOpacity,
} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import colors from '../Component/Color';
export default class SectonLists extends Component {
GetSectionListItem = item => {
Alert.alert(item);
};
render() {
return (
<View style={styles.container}>
<SectionList
sections={[
{
title: 'City Name Starts with A',
data: ['Agra', 'Alinager', 'Amritsar'],
},
{
title: 'City Name Starts with B',
data: ['Barabanki', 'Bombay', 'Bangalore'],
},
{
title: 'City Name Starts with C',
data: ['Chakia', 'Chandauli', 'Chouk'],
},
]}
renderSectionHeader={({section}) => (
<Text style={styles.SectionHeader}> {section.title} </Text>
)}
renderItem={({item}) => (
<Text
style={styles.SectionListItemS}
onPress={this.GetSectionListItem.bind(this, item)}>
{' '}
{item}{' '}
</Text>
)}
keyExtractor={(item, index) => index}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
},
SectionHeader: {
backgroundColor: colors.primary,
fontSize: 20,
marginTop: 10,
padding: 5,
color: '#fff',
fontWeight: 'bold',
},
SectionListItemS: {
fontSize: 20,
padding: 6,
color: '#000',
backgroundColor: '#F5F5F5',
},
});
If you wrap your sectionList in a View with the desired borderRadius and with the overflow: 'hidden' style property then all of the content in the sectionList will be contained within a view with the desired borderRadius.
Example
<View style={{
width: '80%',
backgroundColor: 'white',
borderRadius: 10, ,
overflow: 'hidden'}} >
<SectionList
sections = {sections}
renderItem = {renderItem}
renderSectionHeader={renderSectionHeader}
keyExtractor = {(item, index) => index.toString()}
ListEmptyComponent={listEmptyComponent}
/>
</View>
Related
I am unable to get my Flatlist to scroll in my expo react native app. At the moment it is just static, displaying a grid of images int he Flatlist with no scrolling functionality. Please can someone advise?
I am unable to get my Flatlist to scroll in my expo react native app. At the moment it is just static, displaying a grid of images int he Flatlist with no scrolling functionality. Please can someone advise?
import { StyleSheet, Text, View, Button, TextInput, TouchableWithoutFeedback, Keyboard, FlatList, ActivityIndicator } from 'react-native';
import { Image } from '#rneui/themed';
import ImageAPI from '../shared-components/ImageAPI';
export default function Home({ navigation }) {
const onCreate = () => {
console.log('create my image now');
};
return (
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
<View style={styles.container}>
{/** Enter text prompt */}
<View style={styles.section1}>
<View style={styles.txtInputView}>
<TextInput
style={styles.txtInput}
placeholder='Enter a prompt - a description of what you want to create'
multiline={true}
numberOfLines={4}
/>
</View>
<View style={styles.buttonView}>
<Text
style={styles.createBtnText}
onPress={onCreate}
>Create</Text>
</View>
</View>
{/** PROMPT EXAMPLES */}
<View style={styles.section2}>
<View style={styles.section2_sub0}>
<Text style={styles.promptEgTxt}>Prompt Examples</Text>
</View>
<View style={styles.section2_sub1}>
<ImageAPI />
</View>
</View>
</View>
</TouchableWithoutFeedback>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
section1: {
flex: 2,
width: '100%',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ffc6e2',
},
section2: {
flex: 5,
width: '100%',
backgroundColor: '#F8DB93',
},
// section3: {
// flex: 3,
// backgroundColor: '#BCF893',
// },
txtInputView: {
flex: 3,
width: '85%',
height: '50%',
alignItems: 'center',
justifyContent: 'center',
marginTop: 20,
marginBottom: 20
},
buttonView: {
flex: 2,
width: '70%',
alignItems: 'center',
justifyContent: 'center',
marginBottom: 20,
backgroundColor: '#EE4A4A',
borderRadius: 40
},
txtInput: {
borderColor: '#AAAAAA',
borderWidth: 2,
padding: 10,
borderRadius: 15,
// width: '85%',
// height: '50%',
width: '100%',
height: '100%',
fontSize: 15,
},
createBtnText: {
fontSize: 18,
fontWeight: 'bold',
// backgroundColor: '#EEEC4A'
},
section2_sub0: {
flex: 1,
width: '100%',
height: '100%',
backgroundColor: '#EEEC4A',
justifyContent: 'center',
},
promptEgTxt: {
fontSize: 15,
fontWeight: 'bold',
marginLeft: 10
},
section2_sub1: {
flex: 8,
width: '100%',
height: '100%',
backgroundColor: '#A9F889'
},
});
This is the ImageAPI.js file:
import React from 'react';
import { FlatList, SafeAreaView, StyleSheet, ActivityIndicator, View, ScrollView } from 'react-native';
import { Image } from '#rneui/themed';
const BASE_URI = 'https://source.unsplash.com/random?sig=';
const ImageAPI = () => {
return (
<>
<SafeAreaView>
<FlatList
data={[...new Array(10)].map((_, i) => i.toString())}
style={styles.list}
numColumns={2}
keyExtractor={(e) => e}
renderItem={({ item }) => (
<Image
transition={true}
source={{ uri: BASE_URI + item }}
containerStyle={styles.item}
PlaceholderContent={<ActivityIndicator />}
/>
)}
/>
</SafeAreaView>
</>
);
};
const styles = StyleSheet.create({
list: {
width: '100%',
backgroundColor: '#000',
},
item: {
aspectRatio: 1,
width: '100%',
flex: 1,
},
});
export default ImageAPI
you need to give it a fixed height and set the contentContainerStyle prop to { flexGrow: 1 }. This will allow the content inside the FlatList to exceed the bounds of the container and be scrollable.
<View style={styles.section2_sub1}>
<FlatList
contentContainerStyle={{ flexGrow: 1 }}
data={data}
renderItem={({ item }) => <ImageAPI data={item} />}
keyExtractor={(item) => item.id}
/>
</View>
Try adding flex according to your requirement to your <SafeAreaView> which is the parent to your <Flatlist> Something like this:
<>
<SafeAreaView style = {{flex: 8}} >
<FlatList
data={[...new Array(10)].map((_, i) => i.toString())}
style={styles.list}
numColumns={2}
keyExtractor={(e) => e}
renderItem={({ item }) => (
<Image
transition={true}
source={{ uri: BASE_URI + item }}
containerStyle={styles.item}
PlaceholderContent={<ActivityIndicator />}
/>
)}
/>
</SafeAreaView>
</>
Or remove the SafeAreaView if not required.
Both should work.
How can I scroll in my profil page where is a Tab and inside a Tab is a Flatlist?
Like Instagram If you go on your profile then there is a Tab and you can scroll down until no more images available.
I use this libary: https://github.com/satya164/react-native-tab-view
I tried many times and different things but I dont succeed. I hope anyone can help me
€: I can scroll but he dont show all results. And I dont want to scroll inside a Tab I want to scroll the full profile screen
<ScrollView style={styles.containerProfil}>
<View style={{flex: 1, flexDirection: 'column', alignItems: 'center', height: height * 1, width: width * 1, position: 'relative'}}>
<TouchableOpacity style={{justifyContent: 'center', alignItems: 'center', position: 'relative'}} onPress={() => navigation.navigate('Platform')}>
<ImageBackground style={styles.profilImage} resizeMode="cover" source={require('../assets/profil.jpg')} />
</TouchableOpacity>
<View style={{justifyContent: 'center', height: 40}}>
<Text style={{ fontFamily: 'nunito-regular', color: '#333', fontSize: 20, letterSpacing: 0, marginVertical: 10}}>#lenamaier123</Text>
</View>
<View style={{flex: 1, backgroundColor: '#eee', width: width * 1}}>
<ProfileTab /> <-- HERE ARE THE TABS
</View>
</View>
</ScrollView>
Css:
containerProfil: {
flex: 1,
backgroundColor: '#fff',
position: 'relative',
padding: 0,
},
profilImage: {
width: 100,
height: 100,
borderRadius: 150 / 2,
overflow: "hidden",
borderWidth: 1,
borderColor: '#eee',
textAlign: 'center',
},
ProfileTab.js
import * as React from 'react';
import { View, Text, useWindowDimensions, Dimensions } from 'react-native';
import { TabView, SceneMap } from 'react-native-tab-view';
import MyProducts from '../../../screens/profile/myProducts';
const height = Dimensions.get('window').height;
const FirstRoute = () => (
<View style={{ flex: 1, backgroundColor: '#ff4081' }}>
<MyProducts />
</View>
);
const SecondRoute = () => (
<View style={{ flex: 1, backgroundColor: '#673ab7' }}>
<Text>Second</Text>
</View>
);
const renderScene = SceneMap({
first: FirstRoute,
second: SecondRoute,
});
export default function TabViewExample() {
const layout = useWindowDimensions();
const [index, setIndex] = React.useState(0);
const [routes] = React.useState([
{ key: 'first', title: 'First' },
{ key: 'second', title: 'Second' },
]);
return (
<TabView
navigationState={{ index, routes }}
renderScene={renderScene}
onIndexChange={setIndex}
initialLayout={{ width: Dimensions.get('window').width }}
scrollEnable={true}
style={{width: layout.width * 1}}
/>
);
}
Flatlist.js
import React, { useState } from 'react';
import { StyleSheet, Text, View, TouchableOpacity, ScrollView, FlatList, SafeAreaView, Dimensions } from 'react-native';
const width = Dimensions.get('window').width;
const myProducts = () => {
const [product, setProduct] = useState([
{key: 1, text: 'Hose'},
{key: 2, text: 'Hose'},
{key: 3, text: 'Hose'},
{key: 4, text: 'Hose'},
{key: 5, text: 'Hose'},
{key: 6, text: 'Hose'},
{key: 7, text: 'Hose'},
{key: 8, text: 'Hose'},
]);
return (
<View style={{width: width * 1}}>
<FlatList
data={product}
scrollEnabled={true}
keyExtractor={(item) => item.key.toString()}
renderItem={({item}) => (<View style={{flex: 1, height: 80, width: width * 1, padding: 20, borderWidth: 1, bordderColor: '#eee'}}><Text style={{flex: 1, backgroundColor: 'red', color: 'blue'}}>{item.text}</Text></View>)}
/>
</View>
)
};
export default myProducts;
FlatList inside a ScrollView doesn't work as expected.
FlatList inside ScrollView doesn't scroll - https://github.com/facebook/react-native/issues/19971
As a solution to your problrm I found this.
you want this;
https://www.npmjs.com/package/react-native-scrollable-tab-view-collapsible-header
Take a look.
If you are using FlatList component inside tabview, change
<HScrollView> with <HFlatList>
I have an array of months which I am using to display months using a horizontal FlatList. I want the months to change using 2 buttons that are forward button to change the month in increasing order i.e from January to February and so on and a back button to change the month backwards i.e from January to December.
How can I make the buttons do so. Below monthName is an array that contains all the month names.
<ScrollView style={{flexGrow: 1}}>
<View style={{flex: 1, backgroundColor: '#fff', height: hp('130')}}>
<View
style={{
justifyContent: 'space-evenly',
width: wp('48'),
}}>
<FlatList
data={monthName}
pagingEnabled={true}
showsHorizontalScrollIndicator={false}
renderItem={(month, index) => (
<View>
<Months
showMonth={month.item}
id={month.id}
refer={flatRef}
/>
</View>
)}
keyExtractor={(item, index) => item.id.toString()}
horizontal
// snapToInterval={Dimensions.get('window').width}
snapToAlignment={'center'}
ref={(node) => (flatRef = node)}
/>
</View>
<View
style={{
justifyContent: 'space-evenly',
width: wp('12'),
}}>
{/* {} */}
<IonIcons.Button --> the button that makes the month increment.
name="arrow-forward"
size={25}
backgroundColor="white"
color="black"
// onPress={() => console.log('pressed')}
onPress={() => {
flatRef.scrollToIndex({index: ?});
}}
/>
</View>
</View>
</ScrollView>
try to access ref using current and it should work
this.flatRef.current.scrollToIndex({index: monthName.length > this.state.currentindex ? this.state.currentindex++ : this.state.currentindex });
import React, { useRef } from 'react';
import {
FlatList,
StyleSheet,
Text,
TouchableOpacity,
View
} from 'react-native';
import { wp } from '../../constants/scaling';
import { colors } from '../../constants/theme';
import bookingprocess from '../../data/BookingProcess';
import { textStyles } from '../../styles/textStyles';
import { RFValue } from 'react-native-responsive-fontsize';
import AntDesign from 'react-native-vector-icons/AntDesign';
const BookingProcess = ({}) => {
const flatListRef = useRef(FlatList);
const nextPress = index => {
if (index <= 2) {
flatListRef?.current?.scrollToIndex({
animated: true,
index: index + 1
});
}
};
const backPress = index => {
if (index >= 1) {
flatListRef?.current?.scrollToIndex({
animated: true,
index: index - 1
});
}
};
return (
<View
style={{
...styles.cardView,
padding: 0,
elevation: 0,
borderWidth: 1,
borderColor: '#f2f2f2',
overflow: 'hidden'
}}>
<View
style={{
padding: wp(2),
backgroundColor: colors.primaryColor
}}>
<Text
style={{
...textStyles.heading,
color: '#fff'
}}>
Booking Process
</Text>
</View>
<Text
style={{
...textStyles.mediumheading,
padding: wp(2),
paddingBottom: 0
}}>
You can reserve your parking slot in advance. Please follow
these four simple steps to book your parking slot.
</Text>
<FlatList
data={bookingprocess}
horizontal={true}
ref={flatListRef}
contentContainerStyle={{ padding: wp(2) }}
showsHorizontalScrollIndicator={false}
keyExtractor={(item, index) => item.id}
renderItem={({ item, index }) => {
return (
<View style={styles.innerCard}>
{item.image}
<View style={styles.ButtonBox}>
<TouchableOpacity
onPress={() => backPress(index)}
style={{
backgroundColor: colors.secondaryColor,
borderRadius: wp(50)
}}>
<AntDesign
name="leftcircle"
size={RFValue(25)}
color={colors.primaryColor}
/>
</TouchableOpacity>
<TouchableOpacity
onPress={() => nextPress(index)}
style={{
backgroundColor: colors.secondaryColor,
borderRadius: wp(50)
}}>
<AntDesign
name="rightcircle"
size={RFValue(25)}
color={colors.primaryColor}
/>
</TouchableOpacity>
</View>
<View style={styles.innercardHeaderView}>
<Text style={styles.headingTextNumber}>
{item.id}. {item.title}
</Text>
</View>
<Text style={styles.description}>
{item.description}
</Text>
</View>
);
}}
/>
</View>
);
};
export default BookingProcess;
const styles = StyleSheet.create({
cardView: {
backgroundColor: colors.white,
margin: wp(2),
elevation: 4,
borderRadius: wp(2),
padding: wp(2),
width: wp(94)
},
innerCard: {
margin: wp(2),
borderRadius: wp(2),
padding: wp(0),
paddingTop: 0,
paddingHorizontal: 0,
overflow: 'hidden',
width: wp(90),
elevation: 5,
marginLeft: 0,
padding: wp(2),
backgroundColor: '#fff'
},
ButtonBox: {
position: 'absolute',
flexDirection: 'row',
right: 0,
justifyContent: 'space-between',
width: wp(20),
padding: wp(2)
},
innercardHeaderView: {
backgroundColor: '#0000',
flexDirection: 'row',
padding: wp(2),
paddingBottom: 0,
alignItems: 'center'
},
headingTextNumber: {
...textStyles.heading,
color: colors.primaryColor,
textAlign: 'center',
alignSelf: 'center',
textAlignVertical: 'center'
},
description: {
...textStyles.mediumheading,
paddingHorizontal: wp(2),
textAlign: 'justify'
}
});
Instead of using a FlatList I would suggest you to make a state variable and execute it like this
Working example - Here
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { AntDesign } from '#expo/vector-icons';
...
const [SelectMonth, SetSelectMonth] = React.useState(monthName[0]);
const NextPress = () => {
if (SelectMonth.id !== 12) {
let temp = monthName.find((c) => c.id === SelectMonth.id + 1);
if (temp) {
SetSelectMonth(temp);
}
}
};
const PrevPress = () => {
if (SelectMonth.id !== 1) {
let temp = monthName.find((c) => c.id === SelectMonth.id - 1);
if (temp) {
SetSelectMonth(temp);
}
}
};
return (
<View style={styles.container}>
<View style={styles.CalenderBox}>
<AntDesign
name="caretleft"
size={30}
color="black"
onPress={() => PrevPress()}
/>
<View style={styles.MonthNameBox}>
<Text style={{ fontWeight: 'bold', fontSize: 24 }}>
{SelectMonth.name}
</Text>
</View>
<AntDesign
name="caretright"
size={30}
color="black"
onPress={() => NextPress()}
/>
</View>
</View>
);
Hello Here i have some data as the form of Flatlist and i have extracted it, now i want to move on that
screen that i have clicked on example
if i clicked on screen A then i will moved to screen A,
if i clicked on screen B then i will moved on screen B,
if i clicked on screen C then i will moved to screen C,
if i clicked on screen D then i will moved on screen D, And
Show their Header Also
How to call proper screen according to their header and screen..
How to Navigate it..
Sample image here
Code Here..
import React, {useState} from 'react';
import {
FlatList,
Image,
View,
Text,
SafeAreaView,
StyleSheet,
TouchableOpacity
} from 'react-native';
import App1 from './App1';
const dummyArray = [
{id: '1', value: 'A',exdate: '2020', City: 'Delhi'},
{id: '2', value: 'A',exdate: '2019',City: 'Mumbai'},
{id: '3', value: 'C',exdate: '2015 ',City: 'Indore'},
{id: '4', value: 'D',exdate: '2016',City: 'Patna'},
{id: '5', value: 'E',exdate: '2000',City: 'Raipur'},
];
const Home = ({ navigation }) => {
const [listItems, setListItems] = useState(dummyArray);
function handlePick(item){
}
const ItemView = ({item}) => { //flatlist data view
return (
// FlatList Item
<View style={styles.itemView}>
<TouchableOpacity style={styles.button} activeOpacity={.5}
onPress={()=>handlePick(item)}>
<View style={styles.stateView}>
<Text style={styles.textItem} onPress={() => getItem(item)}>
{item.value}
</Text>
<Image source={require('./right.jpg')} style={{marginLeft: 70, marginTop: 5,width: 30, height: 30}} />
</View>
<View
style={{
marginTop: 3,
height: 1,
width: '100%',
backgroundColor: '#C8C8C8'
}}
/>
<Text style={styles.text}>Date{"\t\t\t\t"}{item.exdate}</Text> //flatlist Data
<Text style={styles.capitalText}>Capital City{"\t\t\t\t\t\t"}{item.City}</Text> //flatlistCity
</TouchableOpacity>
</View>
);
};
const ItemSeparatorView = () => {
return (
// FlatList Item Separator
<View
style={{
backgroundColor: '#C8C8C8'
}}
/>
);
};
};
return (
<SafeAreaView style={{flex: 1}}>
<View style={styles.container}>
<FlatList
data={listItems}
ItemSeparatorComponent={ItemSeparatorView}
renderItem={ItemView}
keyExtractor={(item, index) => index.toString()}
/>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
flex: 1,
marginLeft: 10,
marginRight: 10,
marginBottom: 10,
},
textItem: {
marginTop: 5,
fontSize: 18,
flexDirection: 'row',
fontWeight: 'bold',
height: 20,
width: 250,
},
itemView: {
height: 150,
padding: 10,
margin: 8,
backgroundColor: '#fff'
},
stateView:{
height: 40,
flexDirection: 'row',
},
text:{
marginTop: 5,
width: 300,
height: 28
},
});
export default Home;
Please Suggest any solution..
Thanks..
Try this way
function handlePick(item){
const route = `Screen${item.value}`; // dynamic screen like 'ScreenA' or 'ScreenB' etc...
navigation.navigate(route, {data: item} ); This way will navigate to route with data object of item
}
I am currently trying to center the text from the FlatList.
By centering I mean I want it to be in the middle, right of each Icon.
Currently this is how is displaying, it's on the bottom. I just want it to be a little bit higher:
Here is how my component looks like:
I have tried to implement few styles, but still no success.
The thing that crossed my mind but did not try was to hard code each line and drop the loop, but I am not sure if this is right to do.
import SocialIcon from 'react-native-vector-icons/AntDesign';
import BookingIcon from 'react-native-vector-icons/FontAwesome';
import FeatherIcons from 'react-native-vector-icons/Feather';
export const bookIcon = (<BookingIcon name="pencil-square-o" size={40} color="purple" />);
export const calendarIcon = (<SocialIcon name="calendar" size={40} color="purple" />);
export const questionIcon = (<SocialIcon name="questioncircleo" size={40} color="purple" />);
export const externalLinkIcon = (<FeatherIcons name="external-link" size={40} color="purple" />);
class AboutMe extends Component {
static navigationOptions = {
title: "About Me",
}
render() {
return (
<View style={styles.container}>
<View style={styles.topBox}>
<View style={styles.circleOuter} />
<View style={styles.circle} />
</View>
<View style={styles.middleBox}>
</View>
<View style={styles.bottomBox}>
<FlatList
contentContainerStyle={styles.listItem}
data={[
{key: 'Book a free appointment', page:'Book', icon: bookIcon},
{key: 'Availability', page:'Availability', icon:calendarIcon},
{key: 'FAQ', page:'Faq', icon: questionIcon},
{key: 'Useful Links', page: 'Links', icon: externalLinkIcon},
]}
onPress={() => this.props.navigation.navigate('Book')}
renderItem={({item}) => {
return (
<TouchableHighlight onPress={() => this.props.navigation.navigate(`${item.page}`)}>
<Text >{item.icon}{item.key}</Text>
</TouchableHighlight>
)
}}
/>
</View>
</View>
);
};
};
const styles = StyleSheet.create({
container: {
flex: 1
},
topBox: {
flex:3,
backgroundColor: 'red',
justifyContent:'center',
alignItems: 'center'
},
middleBox: {
flex:1,
backgroundColor: 'yellow'
},
bottomBox: {
flex:4,
backgroundColor: 'orange',
padding: 20
},
circle: {
width: 160,
height: 160,
borderRadius: 160/2,
backgroundColor: 'green',
position: 'absolute'
},
circleOuter: {
width: 180,
height: 180,
borderRadius: 180/2,
backgroundColor: 'black'
},
listItem: {
flex:1,
justifyContent: 'center'
},
text: {
fontSize: 20,
}
});
You need to wrap the Text tag in a View/TouchableHighlight tag and then center the text tag vertically. Try this and let me know. It could be necessary that you wrap the icons in a separated image tag. if the code avode dont work means that a separeted tag is necessary so let me know!
<TouchableHighlight
style={styles.buttonsStyle}
onPress={() => this.props.navigation.navigate(`${item.page}`)}
>
<Text>{item.icon}{item.key}</Text>
</TouchableHighlight>
...
...
...
//in the styles add
buttonsStyle:{
justifyContent: 'center',
}
EDIT1
In order to wrap the icons it should be like following.. Note that you cannot use TouchableHighlight in this case. it seems to be a bug with react-native. aslo i used TouchableOpacity
renderItem={({item}) => {
return (
<TouchableOpacity
style={styles.buttonsStyle}
onPress={() => this.props.navigation.navigate(`${item.page}`)}
>
<Image style={styles.imgStyles} source={item.icon} />
<Text style={styles.mappedTextStyle}>{item.key}</Text>
</TouchableOpacity>
)
}}
styles to change/add
buttonsStyle:{
alignItems: 'center',
flexDirection:'row',
marginTop: 5,
},
imgStyles:{
width: 40,
height: 40,
marginRight: 10
},
mappedTextStyle: {
fontSize: 18,
color: 'black'
},
EDIT 2
In order to cover vector-icons lib, i have created a Expo snack for producing the desired behavior. Expo snack has also the expected solution for the problem Expo Snack