Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Native flexDirection: 'row' with multiple lines

Tags:

react-native

I would like to know if there is a way to have flexDirection: 'row' with multiple lines. Because now if I have 10 objects in row non will go on a second line. This is the example from documentation where I've added another two <View> elements

import React, { Component } from 'react'; import { AppRegistry, View } from 'react-native';  export default class FlexDirectionBasics extends Component {   render() {     return (       // Try setting `flexDirection` to `column`.       <View style={{flex: 1, flexDirection: 'row'}}>         <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />       </View>     );   } };  // skip this line if using Create React Native App AppRegistry.registerComponent('AwesomeProject', () => FlexDirectionBasics); 
like image 448
Markus Hayner Avatar asked Jun 22 '18 19:06

Markus Hayner


People also ask

How do you use Flexdirection row in React Native?

Flex DirectionBy default, React Native lays out with LTR layout direction. In this mode start refers to left and end refers to right. LTR (default value) Text and children are laid out from left to right. Margin and padding applied to the start of an element are applied on the left side.

How do you set two inputs on the same row in React Native?

How do you set two inputs on the same row in react native? You want to do something like this: import React, { Component } from "react"; import { Text, View, StyleSheet, TextInput } from "react-native"; export default class App extends Component { render() { return ( <View style={styles. row}> <View style={styles.

What does flex 1 mean in React Native?

Flex Dimensions​ Normally you will use flex: 1 , which tells a component to fill all available space, shared evenly amongst other components with the same parent. The larger the flex given, the higher the ratio of space a component will take compared to its siblings.

How do I add text side by side in React Native?

import React, {Component} from 'react'; import {View, Text, StyleSheet, TextInput, TouchableHighlight} from 'react-native'; export default class AddItems extends Component { onAdd() { alert('Hello'); } render() { return ( <View style={addItemStyles.


1 Answers

You can use flex-wrap: wrap so the content will break to a new line when it reaches the max width allowed for this component.

      <View style={{flex: 1, flexDirection: 'row', flexWrap: 'wrap'}}>         <View style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />         <View style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />       </View> 

https://developer.mozilla.org/en-US/docs/Web/CSS/flex-wrap

Hope it helps

like image 149
soutot Avatar answered Oct 09 '22 22:10

soutot