Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrapping text around an image with React-Native

I try to create a View with an Image and a Text component that wraps around the Image component.

My styling:

  textContainer: {
    flexDirection: 'row',
  },
  text: {
    flex: 10,
  },
  image: {
    flex:1,
    height: 180,
    width: 150,    
    margin: 10,
    borderColor: '#ccc',
    borderWidth: 1,
  }

My component:

<ScrollView style={styles.contentContainer} >
   {this.props.content.title_1 ? <Text style={styles.title}>{this.props.content.title_1}</Text> : null}
   <View style={styles.textContainer}>
      {this.props.content.text_1 ? <Text style={styles.text}>{this.props.content.text_1}</Text> : null}
      {this.props.content.image_1 ? <Image width={null} height={null} style={styles.image} source={this.props.content.image_1} /> : null}
   </View>
</ScrollView>

This is what the result: (not wrapping at all haha)

enter image description here

In the image beneath here, I quickly hacked the little image into the text. But I can't get the text to be wrapped around..

example

I hope anyone can help me in the right direction!

like image 788
Timvp Avatar asked Jul 21 '16 15:07

Timvp


People also ask

How do I wrap text around an image?

Wrap text around a picture or drawing objectSelect the picture or object. Select Format and then under Arrange, select Wrap Text.

How do you handle long texts 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 wrap text around an image in CSS?

Enter . left { float: left; padding: 0 20px 20px 0;} to the stylesheet to use the CSS "float" property. (Use right to align the image to the right.) If you view your page in a browser, you'll see the image is aligned to the left side of the page and the text wraps around it.

How do you break text in react native?

You can use {'\n'} as line breaks.


1 Answers

On android you cannot place a View inside Text, but you can place an Image, here is an example:

<Text> 
  <Image source="" />
  <Text> Insert your text here </Text>
</Text>
like image 84
Andra Marin Avatar answered Oct 11 '22 09:10

Andra Marin