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);
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? 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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With