two inputs in one line? - css

I have created a form in react-native which looks like:
Here is my code:
const Login = (props) => {
const { phoneContainerStyles, loginButtonStyle } = styles;
return (
<View>
<Field id="country" name="country" type="select" mode="dropdown" label="Country:" component={FormInput}>
{
props.countries && props.countries.map(country => <Picker.Item key={country.code} label={country.name} value={country.code} />)
}
</Field>
<Field id="phone" name="phone" type="phone" label="Phone Number:" component={FormInput} />
<Button type="submit" title="Login" buttonStyle={loginButtonStyle} onPress={props.handleSubmit(onLogin)} />
</View>
);
}
const styles = {
loginButtonStyle: {
backgroundColor: '#fc4482'
}
}
Here is the FormInput:
const FormInput = (props) => {
const { touched, error } = props.meta || {};
const { labelStyles, errorStyles } = styles;
return (
<View>
<Text style={[labelStyles, { display: props.label ? 'flex' : 'none', color: `${(touched && error) ? 'red' : 'black'}` }]}>{props.label}</Text>
<View style={{ padding: props.inputWrapperPadding }}>
{returnInput(props)}
<View>
<Text style={errorStyles}>{touched ? (error ? error : '') : ''}</Text>
</View>
</View>
</View>
);
};
const returnInput = (props) => {
const { touched, error } = props.meta || {};
switch (props.type) {
case 'select':
.....
case 'phone':
return (
<View>
<TextBox {...props.input} id={`sel-${props.id}`} value={props.sel} style={styles.phoneSelStyle} />
<TextBox {...props.input} id={props.id} placeholder={props.placeholder} disabled={props.disabled}
style={[ styles.textBoxStyle, { borderColor: `${(touched && error) ? 'red' : 'black'}` }]}
value={props.input.value} onChangeText={value => props.input.onChange(value)} />
</View>
);
default:
.....
}
};
const styles = {
labelStyles: {
paddingLeft: 16,
fontWeight: 'bold'
},
errorStyles: {
color: 'red',
marginLeft: 16,
marginRight: 16,
marginBottom: 8
},
pickerStyles: {
marginLeft: 16,
marginRight: 16
},
textBoxStyle: {
marginBottom: 4,
borderWidth: 1,
}
phoneSelStyle: {
width: 50
}
}
Now, I want the two TextInputs below Phone Number label in 1 line.
So, I added this style to View:
case 'select':
.......
case 'phone':
return (
<View style={styles.phoneContainerStyles}>
<TextBox {...props.input} id={`sel-${props.id}`} value={props.sel} style={styles.phoneSelStyle} />
<TextBox {...props.input} id={props.id} placeholder={props.placeholder} disabled={props.disabled}
style={[ styles.textBoxStyle, { borderColor: `${(touched && error) ? 'red' : 'black'}` }]}
value={props.input.value} onChangeText={value => props.input.onChange(value)} />
</View>
);
default:
.......
Here is the style:
phoneContainerStyles: {
flex: 1,
flexDirection: 'row'
}
Now, If I run my app, then output looks like below:
I don't know why my textbox gets width = 0. Also, why button comes over the textboxes.
After following the answer by #Himanshu

Update your style like this:
//Child view component (<TextBox>) style use flex property
textBoxStyle: {
flex:2
borderWidth: 1,
}
phoneSelStyle: {
//width: 50 don't apply width instead use flex
flex:8
}
//Parent view style
phoneContainerStyles: {
flex: 1,
flexDirection: 'row'
}

Related

react native. how to make the left side non scrollable at table below

so I have a question/answer table below and I want to make the left part of the table to stick there. Each row is mapped individually(1st row- title, than the radio buttons for that, 2nd row than the buttons and so on. in reactJs I would put a position sticky or fixed to solve the problem but i dont know how to solve it in native.
a snack environment if anyone needs it https://snack.expo.dev/Mz0nR6Fj5
Here is the code
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, ScrollView } from 'react-native';
import Constants from 'expo-constants';
import { Button, RadioButton } from 'react-native-paper';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
export default function App() {
const [res, setRes] = useState([]);
let answers = ['good', ' bad', 'ehh'];
let question = [
'how are you',
'how the weather',
'how was the day',
'what do you think about ....',
];
useEffect(() => {
setRes(
question.map((title) => ({
title,
...answers.reduce((p, c) => ((p[c] = 0), p), {}),
}))
);
}, []);
const handleClick = (i, x) => {
setRes(
res.map((data) => {
if (i.title === data.title && i[x] === 0) {
const title = i.title;
for (const property in i) {
i[property] = 0;
}
i[x] = 1;
i.title = title;
}
// else if (i.title === data.title && i[x] === 1) {
// i[x] = 0;
// }
return data;
})
);
const yy = [];
console.log(res);
res.map(({ title, ...i }) => {
yy.push(Object.values(i).flat());
});
console.log(yy);
};
const show = () => {
const yy = [];
console.log(res);
res.map(({ title, ...i }) => {
yy.push(Object.values(i).flat());
});
console.log(yy);
// console.log(result);
// console.log('njeDheZero___ ', njeDheZero);
};
// console.table(players);
return (
<View>
<ScrollView horizontal={true} style={styles.container}>
<View
style={{
backgroundColor: 'white',
flexDirection: 'column',
borderTopWidth: 1,
borderLeftWidth: 1,
borderColor: '#ccc',
marginRight: 30,
}}>
<View style={{ flexDirection: 'row' }}>
<View
style={{
borderBottomWidth: 1,
borderRightWidth: 1,
borderColor: '#ccc',
width: 200,
}}>
<Text style={{ padding: 10 }}>-</Text>
</View>
{answers.map((subq) => (
<View
key={subq}
style={{
borderBottomWidth: 1,
borderRightWidth: 1,
borderColor: '#ccc',
width: 120,
}}>
<Text style={{ padding: 10 }}>{subq}</Text>
</View>
))}
</View>
{res.length > 0 ? (
<>
{res.map((i, inda) => {
// console.log("render",i.title)
return (
<View key={inda} style={{ flexDirection: 'row' }}>
<View
style={{
borderBottomWidth: 1,
borderRightWidth: 1,
borderColor: '#ccc',
width: 200,
}}>
<Text style={{ padding: 10 }}>{i?.title}</Text>
</View>
{answers.map((x, indq) => {
return (
<View
style={{
borderBottomWidth: 1,
borderRightWidth: 1,
borderColor: '#ccc',
width: 120,
justifyContent: 'center',
alignItems: 'center',
}}>
<RadioButton.Group>
<RadioButton
// value={i[x]}
status={i[x] === 1 ? 'checked' : 'unchecked'}
onPress={() => {
handleClick(i, x);
}}
/>
</RadioButton.Group>
</View>
);
})}
</View>
);
})}
</>
) : (
<Text>LOADING</Text>
)}
</View>
</ScrollView>
<Button onPress={show}>
<Text>SHOW</Text>
</Button>
</View>
);
}
const styles = StyleSheet.create({
// container: {
// flex: 1,
// justifyContent: 'center',
// paddingTop: Constants.statusBarHeight,
// backgroundColor: '#ecf0f1',
// padding: 8,
// },
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});

borderTopColor not working for React-Native "View"

I am developing my first React Native app and I am trying to design a footer for the main screen. To do that I created a view and placed it under the scrollView. Then I tried making a borderTopColor to separate the footer from the rest of the page but it did not work.
home.js
import { StatusBar } from 'expo-status-bar'
import { StyleSheet, Text, View, FlatList, Image, Button, Pressable, ScrollView } from 'react-native';
import React, {useState, useEffect} from 'react'
import { TextInput } from 'react-native-gesture-handler';
import AsyncStorage from '#react-native-async-storage/async-storage';
import { FontAwesomeIcon } from '#fortawesome/react-native-fontawesome';
import { faUser } from '#fortawesome/free-regular-svg-icons';
import { faAlignJustify, faUser as solidUser} from '#fortawesome/free-solid-svg-icons'
import { faComments as solidComment } from '#fortawesome/free-solid-svg-icons';
import { faComments } from '#fortawesome/free-regular-svg-icons';
export default function Home(props) {
const [ current, setCurrent ] = useState("profile")
const [ user, setUser ] = useState("")
const curr = (cur) => {
setCurrent(cur)
}
const getData = async () => {
try {
const value = await AsyncStorage.getItem('#userauthkey')
if (value !== null) {
return value
} else {
return false
}
} catch (e) {
console.log(e)
}
}
useEffect(() => {
const ch = async () => {
const c = await getData();
if (c) {
setUser(c)
}
};
ch();
}, []);
const gprof = (user) => {
fetch(`http://192.168.5.223:8000/home/checkprofile/`,{
method: 'POST',
headers: {
"Content-Type": 'application/json',
},
body: JSON.stringify({'user':user}),
} )
.then( res => res.json())
.then( res => {
console.log(res.profile)
console.log(res.sets)
if (res.sets === false){
props.navigation.navigate('Profile')
}
})
.catch( error => console.log(error))
}
const logout = async () => {
try {
await AsyncStorage.removeItem('#userauthkey')
props.navigation.navigate('Login')
} catch(e){
console.log(e)
}
}
if(current === "profile"){
return (
<View style={styles.container}>
<ScrollView style={styles.scroll} >
<Text> profile {user} </Text>
<Pressable onPress={ () => logout()}>
<Text>Logout</Text>
</Pressable>
</ScrollView>
<View style={styles.footer}>
<Pressable onPress={() => curr('messanger')}>
<View style={{ borderWidth: 2, borderStyle: 'solid', borderColor: "white", borderRadius: 20, padding: 3, }}>
<FontAwesomeIcon icon={faComments} style={{color: 'white',}} size={25} />
</View>
</Pressable>
<Pressable onPress={() => curr('profile')}>
<View style={{ borderWidth: 2, borderStyle: 'solid', borderColor: "white", backgroundColor: 'white', borderRadius: 20, padding: 3, }}>
<FontAwesomeIcon icon={solidUser} style={{color: 'black', alignContent:"center", } } size={25} />
</View>
</Pressable>
</View>
<StatusBar style="auto"/>
</View>
)
} else if(current === "posts"){
return (
<View style={styles.container}>
<ScrollView style={styles.scroll} >
<Text> posts {user} </Text>
</ScrollView>
<View style={styles.footer}>
</View>
<StatusBar style="auto"/>
</View>
)
} else if (current === "messanger"){
return (
<View style={styles.container}>
<ScrollView style={styles.scroll} >
<Text> messanger {user} </Text>
</ScrollView>
<View style={styles.footer}>
<Pressable onPress={() => curr('messanger')}>
<View style={{ borderWidth: 2, borderStyle: 'solid', borderColor: "white", backgroundColor:"white", borderRadius: 20, padding: 3}}>
<FontAwesomeIcon icon={solidComment} style={{color: 'black',}} size={25} />
</View>
</Pressable>
<Pressable onPress={() => curr('profile')}>
<View style={{ borderWidth: 2, borderStyle: 'solid', borderColor: "white", borderRadius: 20, padding: 3}}>
<FontAwesomeIcon icon={faUser} style={{color: 'white', borderStyle: 'solid', borderColor: "white", borderRadius: 20}} size={25} />
</View>
</Pressable>
</View>
<StatusBar style="auto"/>
</View>
)
}
}
Home.navigationOptions = screenProps => ({
headerLeft: () => null,
gestureEnabled: false,
headerStyle: {
backgroundColor: 'black'
},
headerTintColor: 'white',
})
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black',
},
scroll: {
backgroundColor:'#'
},
footer: {
backgroundColor: 'black',
borderTopColor: 'dark-gray',
borderTopWidth: .5 ,
borderStyle: 'solid',
padding:50,
paddingTop:18,
paddingLeft: 18,
paddingRight: 18,
flexDirection: 'row',
alignContent: "space-between",
alignItems: "space-between",
justifyContent: "space-between",
},
label: {
fontSize: 24,
color: "white",
padding: 10,
},
input: {
fontSize: 24,
backgroundColor: "white",
padding: 10,
margin: 10,
borderRadius: 5,
},
});
How can I solve the issue?
dark-gray is not a recognized color keyword in React Native. You may be thinking of darkgray. You can find the full list of supported color keywords here: https://reactnative.dev/docs/colors#color-keywords

sum items of Flatlist on react native

I'm making an app that makes a bill of items and the user can identify the quantity of every item
and at least there is a text tag which it shows the total price after hitting " get bill " button
it works fine , but the issue is after hitting the button the items are repeated again
[here a screenshot of the app after hitting a 'get bill' button]: https://i.stack.imgur.com/slOWN.jpg
this is the code :
import React, { Component } from "react";
import { View, FlatList, Dimensions, Text } from "react-native";
import * as SQLite from "expo-sqlite";
import { Button } from "react-native-elements";
import NumericInput from "react-native-numeric-input";
const db = SQLite.openDatabase("db.db");
class CreateBill extends Component {
constructor() {
super();
this.state = {
items: [],
itemsList: [],
products: [],
totalPrice: 0,
};
}
async componentDidMount() {
console.log("did mount");
db.transaction((tx) => {
tx.executeSql("SELECT * FROM products2", [], (tx, results) => {
var temp = [];
for (let i = 0; i < results.rows.length; ++i) {
temp.push(results.rows.item(i));
}
this.setState({
products: temp,
});
});
});
}
checkItems = () => {
this.state.items.forEach((item) => {
this.state.products.forEach((product) => {
if (item === product.code) {
console.log("equals", item, product.code);
this.state.itemsList.push({ product, number: 0 });
} else {
console.log("doesnt equal", item.item, product.code);
}
});
});
};
getPrice = () => {
let price = 0;
this.state.itemsList.forEach((element) => {
price = element.number * element.product.price;
});
this.setState({ totalPrice: price });
};
render() {
this.state.items = this.props.route.params.items;
this.checkItems();
return (
<View style={{ flex: 1 }}>
<FlatList
data={this.state.itemsList}
extraData={this.state}
style={{ marginTop: 50, flex: 1, width: Dimensions.width }}
keyExtractor={(item) => item.product.id}
renderSeparator={() => (
<View
style={{
backgroundColor: "#1B73B4",
height: 0.6,
}}
/>
)}
renderItem={({ item, index }) => {
console.log("item", item);
return (
<View
style={{
flexDirection: "row",
width: Dimensions.width,
paddingStart: 20,
alignItems: "center",
}}
key={item}
>
<View style={{ flex: 0.5, alignItems: "center" }}>
<Text style={{ fontSize: 24 }}>{item.product.name}</Text>
</View>
<View style={{ flex: 0.5, justifyContent: "center" }}>
<NumericInput
value={this.state.itemsList[index].number}
onChange={(value) => {
let item1 = this.state.itemsList[index];
item1.number = value;
console.log(
this.state.itemsList[index].product.name,
this.state.itemsList[index].number
);
}}
totalWidth={140}
totalHeight={45}
iconSize={25}
maxValue={this.state.itemsList[index].product.units}
minValue={0}
valueType="integer"
rounded
textColor="#1B73B4"
iconStyle={{ color: "white" }}
rightButtonBackgroundColor="#1B73B4"
leftButtonBackgroundColor="#1B73B4"
/>
</View>
</View>
);
}}
/>
<Text>{this.state.totalPrice}</Text>
<Button title="get bill" onPress={() => this.getPrice()} />
</View>
);
}
}
export { CreateBill };
In your case reduce is the best option:
Documentation here
Example:
const totalPrice = this.state.itemsList.reduce((total, element) =>
total += element.number * element.product.price
,0);
this.setState({ totalPrice });

How to align View component to left and right equally in react-native

I am building a cross platform mobile application using react-native. I am implementing a functionality where I am displaying the data in Accordion. I want the data to be aligned to the left and right in the Accordion Header and Accordion Body but I am not able to achieve that.
Here is my code-
import React, { Component } from 'react';
import {
Switch,
ScrollView,
StyleSheet,
Text,
Image,
View,
TouchableOpacity,
} from 'react-native';
import * as Animatable from 'react-native-animatable';
import Collapsible from 'react-native-collapsible';
import Accordion from 'react-native-collapsible/Accordion';
const axios = require('axios');
import moment from 'moment'
import Dialog, { SlideAnimation, DialogContent } from 'react-native-popup-dialog';
export default class AccordionScreen extends Component {
constructor (){
super();
this.state = {
activeSections: [],
collapsed: true,
multipleSelect: false,
newData:[],
visible: false
};
}
componentDidMount(){
this.fetchData();
}
fetchData() {
axios({
method: "POST",
url: "URL",
headers: {
"Content-Type": "application/json",
"Authorization": this.props.navigation.getParam('authorizationToken', undefined)
},
data: {}
})
.then (response => {
if (response.status === 200 ){
if (response.data.newData.length > 0 ){
this.setState({
newData: response.data.newData
});
//console.log(activeSections);
}
else {
return <h1>No Data!</h1>
}
}
else{
throw "Request resulted in NOT 200";
}
})
.catch(error => {
console.log(error);
});
}
_renderSectionTitle = section => {
return (
<View style={styles.titleHeader}>
<Text>{moment(section.eventDate).format('ll')}</Text>
</View>
);
};
toggleExpanded = () => {
this.setState({ collapsed: !this.state.collapsed });
};
setSections = sections => {
this.setState({
activeSections: sections.includes(undefined) ? [] : sections,
});
};
_renderHeader(section, index, isActive, sections) {
return (
<Animatable.View
duration={400}
style={[styles.header, isActive ? styles.active : styles.inactive]}
transition="backgroundColor">
{
isActive ?
<Image source={require('../assets/images/upArrow.png')}
style={{width: 15, height: 15, alignSelf: 'flex-end'}}
/>
:
<Image source={require('../assets/images/downArrow.png')}
style={{width: 15, height: 15 , alignSelf: 'flex-end'}}
/>
}
<Animatable.View style={styles.leftContainer}>
<Animatable.Text style={styles.headerCont}>Name </Animatable.Text>
<Animatable.Text>{section.name} </Animatable.Text>
</Animatable.View>
<Animatable.View style={styles.rightContainer} >
<Animatable.Text style={styles.headerCont}>City</Animatable.Text>
<Animatable.Text>{section.firstName} {section.lastName} </Animatable.Text>
</Animatable.View>
</Animatable.View>
);
}
_renderContent(section, i, isActive, sections) {
return (
<Animatable.View
duration={300}
transition="backgroundColor"
style={[styles.accordionCont, isActive ? styles.active : styles.inactive]}
transition="backgroundColor"
>
<Animatable.Text
style={styles.headerCont}
duration={300}
easing="ease-out"
animation={isActive ? 'zoomIn' : false}>
Insurer Address
</Animatable.Text>
<Animatable.Text
duration={300}
easing="ease-out"
animation={isActive ? 'zoomIn' : false}>
{section.addressStreet}
</Animatable.Text>
<Animatable.Text
style={styles.headerCont}
duration={300}
easing="ease-out"
animation={isActive ? 'zoomIn' : false}>
Policy Number
</Animatable.Text>
<Animatable.Text
duration={300}
easing="ease-out"
animation={isActive ? 'zoomIn' : false}>
{section.policyNumber}
</Animatable.Text>
<Animatable.Text
style={styles.headerCont}
duration={300}
easing="ease-out"
animation={isActive ? 'zoomIn' : false}>
Additional Details
</Animatable.Text>
</Animatable.View>
);
}
_updateSections = activeSections => {
this.setState({ activeSections });
};
render() {
const { multipleSelect, activeSections, poiHistoryData } = this.state;
return (
<View style={styles.container}>
<ScrollView contentContainerStyle={{ paddingTop: 30 }}>
<TouchableOpacity onPress={this.toggleExpanded}>
<View style={styles.header}>
<Text style={styles.headerText}>View Data</Text>
</View>
</TouchableOpacity>
<Accordion
sections={newData}
activeSections={activeSections}
touchableComponent={TouchableOpacity}
expandMultiple={multipleSelect}
renderSectionTitle={this._renderSectionTitle}
renderHeader={this._renderHeader}
renderContent={this._renderContent}
duration={400}
onChange={this._updateSections}
/>
</ScrollView>
</View>
) }
}
If you see the Heading 'Name' and 'City', these are the headings and I am displaying the value just below it. But right now everything is stacked and aligned to the left. I want 'Other Insurer' and its value to be appear on the left of the screen and 'Other Insured' and its value to be aligned to the right of the screen.
CSS that I am using-
headerCont: {
fontWeight:'bold'
},
leftContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-start'
},
rightContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
alignItems: 'center'
},
header: {
backgroundColor: '#24abc1',
padding: 5,
marginLeft:5,
marginRight:5,
flex: 1,
flexDirection: 'row'
}
Screenshot-
Can someone please suggest me how can I handle this gracefully. Thanks in advance.
hopefully this is work for you
import React, { Component } from 'react';
import { AppRegistry, View,Text } from 'react-native';
export default class FlexDirectionBasics extends Component {
render() {
return (
// Try setting `flexDirection` to `column`.
<View style={{flex: 1, flexDirection: 'row'}}>
<View style={{flex:1, alignItems:'center', backgroundColor: 'steelblue'}} >
<Text>Name</Text>
<Text>ABC</Text>
</View>
<View style={{flex:1, alignItems:'center', backgroundColor: 'red'}} >
<Text>Name</Text>
<Text>ABC</Text>
</View>
</View>
);
}
};
// skip this line if using Create React Native App
AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics);
Replace your Animatable view this
<Animatable.View
duration={400}
style={[styles.header, isActive ? styles.active : styles.inactive]}
transition="backgroundColor">
{
isActive ?
<Image source={require('../assets/images/upArrow.png')}
style={{width: 15, height: 15, alignSelf: 'flex-end'}}
/>
:
<Image source={require('../assets/images/downArrow.png')}
style={{width: 15, height: 15 , alignSelf: 'flex-end'}}
/>
}
<View style={styles.viewContainer}>
<Animatable.View style={styles.leftContainer}>
<Animatable.Text style={styles.headerCont}>Name </Animatable.Text>
<Animatable.Text>{section.name} </Animatable.Text>
</Animatable.View>
<Animatable.View style={styles.rightContainer} >
<Animatable.Text style={styles.headerCont}>City</Animatable.Text>
<Animatable.Text>{section.firstName} {section.lastName} </Animatable.Text>
</Animatable.View>
</View>
</Animatable.View>
And your css
headerCont: {
fontWeight:'bold',
},
leftContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems:'flex-start'
},
rightContainer: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'flex-end'
},
viewContainer:{
flex: 1,
flexDirection: 'row'
},
header: {
backgroundColor: '#24abc1',
padding: 5,
marginLeft:5,
marginRight:5,
}

How to set maxWidth in mobile screen?

I am trying to render few buttons in a row, but having some problem with css style. how can i set maxwidth in mobile screen? this is screen short of my problem
I want to set a css style when maxwidth are over then rest of the button are show in a new row automatically is its possible to render in react-native???
My source code::
import React from 'react';
import { View, Text, StyleSheet, TouchableHighlight } from 'react-native';
import { Header, Icon } from 'react-native-elements';
class Extras extends React.Component {
constructor(props){
super(props);
this.state = { selectFurnish: '', selectVeg: '', selectOtherFecility: '' };
this.onButtonPress = this.onButtonPress.bind(this);
}
leftComponent = () => {
return <Icon name='angle-left' color='#fff' type='font-awesome' onPress={() => {this.props.navigation.navigate('pricing')}} />
}
onButtonPress = (stateName, selected) =>{
const obj = Object.assign({},this.state);
obj[stateName] = selected;
this.setState( obj );
}
render() {
const furnish_button_props = [
{ id: 0, value: 'Full'},
{ id: 1, value: 'Semi'},
{ id: 2, value: 'None'}
];
const veg_button_props = [
{ id: 0, value: 'Yes'},
{ id: 1, value: 'No'}
];
const otherFacilities_button_props = [
{ id: 0, value: 'Parking'},
{ id: 1, value: 'Lift'},
{ id: 2, value: 'Gas Pipeline'},
{ id: 3, value: 'Pool'}
];
return(
<View style={styles.container}>
<Header
leftComponent={this.leftComponent()}
centerComponent={{text: 'NEW LISTING', style: {color: '#FFF', fontSize: 16}}}
outerContainerStyles={{backgroundColor: '#3498db'}}
/>
<View style={styles.block}>
<View>
<Text style={styles.textType}>Furnishing</Text>
<View style={{flexDirection: 'row'}}>
{furnish_button_props.map(i => {
return(
<TouchableHighlight
activeOpacity={1}
onPress={() => this.onButtonPress('selectFurnish',i.value)}
key={i.id}
style={ this.state.selectFurnish === i.value ? styles.buttonOnPress : styles.button }
>
<Text style={ this.state.selectFurnish === i.value ? styles.textOnPress : styles.text }>{i.value}</Text>
</TouchableHighlight>
)
})}
</View>
</View>
<View style={{marginTop: 50}}>
<Text style={styles.textType}>Vegetarian</Text>
<View style={{flexDirection: 'row'}}>
{veg_button_props.map(i => {
return(
<TouchableHighlight
activeOpacity={1}
onPress={() => this.onButtonPress('selectVeg', i.value)}
key={i.id}
style={ this.state.selectVeg === i.value ? styles.buttonOnPress : styles.button }
>
<Text style={ this.state.selectVeg === i.value ? styles.textOnPress : styles.text }>{i.value}</Text>
</TouchableHighlight>
)
})}
</View>
</View>
<View style={{marginTop: 50}}>
<Text style={styles.textType}>Other Facilities</Text>
<View style={{flexDirection: 'row'}}>
{otherFacilities_button_props.map(i => {
return(
<TouchableHighlight
activeOpacity={1}
onPress={() => this.onButtonPress('selectOtherFecility', i.value)}
key={i.id}
style={ this.state.selectOtherFecility === i.value ? styles.buttonOnPress : styles.button }
>
<Text style={ this.state.selectOtherFecility === i.value ? styles.textOnPress : styles.text }>{i.value}</Text>
</TouchableHighlight>
)
})}
</View>
</View>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
maxWidth: '100%'
},
block: {
marginTop: 120,
marginLeft: 10
},
textType: {
fontSize: 16,
fontWeight: 'bold',
marginBottom: 5,
marginLeft: 5
},
button: {
borderColor: '#3498db',
borderWidth: 1,
borderRadius: 25,
width: 100,
height: 50,
marginLeft: 5,
marginRight: 5,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
},
buttonOnPress: {
borderColor: '#3498db',
backgroundColor: '#3498db',
borderWidth: 1,
borderRadius: 25,
width: 100,
height: 35,
marginLeft: 5,
marginRight: 5
},
text: {
fontSize: 14,
color: '#3498db'
},
textOnPress: {
fontSize: 14,
fontWeight: 'bold',
color: '#ffffff'
},
});
export default Extras;
You can add: flexWrap: 'wrap' to your view (<View style={{flexDirection: 'row'}}>)
More about flex

Resources