Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flexWrap not working for <Text> element in React Native

Here is my sceanario

var FlexWrap = React.createClass({
  render:function(){
    return(<View style={{flexDirection:'row'}}>
      <Image source={{uri:profileImage}}
             style={{width:100,height:100}}>
      </Image>
      <View style={{marginLeft:5}}>
        <Text style={{marginTop:5,
          marginBottom:5,
          flexWrap:'wrap'}}>
          This sample text
          should be wrap
          wrap wrap ....
        </Text>
        <Text style={{marginTop:5,
          marginBottom:5,
          flexWrap:'wrap'}}>
          This sample text
          should be wrap
          wrap wrap ....
        </Text>
      </View>
    </View>)
  }
})

Here

'This sample text should be wrap wrap wrap ....'

is in single line, but in my scenario based on the window width automatically the text should be wrap. Here i am using flexWrap: 'wrap' to wrap the text, but what is the correct way to wrap the text?

Please find the screenshot

enter image description here

Here is the working code for text wrap with flexDirection:'row'

var FlexWrap = React.createClass({
  render:function(){
    return(<View style={{flexDirection:'row'}}>
      <Image source={{uri:profileImage}}
             style={{width:100,height:100}}>
      </Image>
      <View style={{marginLeft:5,flex:1}}>//using flex:1
        <Text style={{marginTop:5,
          marginBottom:5
        }}>
          This sample text
          should be wrap
          wrap wrap ....
        </Text>
        <Text style={{marginTop:5,
          marginBottom:5
        }}>
          This sample text
          should be wrap
          wrap wrap ....
        </Text>
      </View>
    </View>)
  }
})
like image 401
vasavi Avatar asked Feb 03 '16 09:02

vasavi


People also ask

How do I wrap text in React Native?

To wrap React Native text on the screen, we can set flexWrap to 'wrap' .

How do you flexWrap in React Native?

Below, we set a container's flexWrap property to wrap to wrap the boxes inside it into multiple lines: import React, { useState } from "react"; import { StyleSheet, View } from "react-native"; export default function App() { return ( <> <View style={styles.

How do I truncate text in React Native?

React Native allows you to automatically truncate text that will not fit within its <View> container. In most cases this is enough for the device to truncate the text, automatically adding ellipsis to the end of the string (…) after however many lines of text you have specified (In this case, we only want 1 line).

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

set flex: 1 to wrapper view of text

Help link

like image 53
I.dev Avatar answered Oct 17 '22 07:10

I.dev