Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native How to Wrap the content of Text and Image in a View

Tags:

I have a problem wrapping the content of text and image in a View..

What I want:

--Image-Text line 1

--Image-Text line 2

Basically I have tried to code in this structure with flex style configured to 'wrap'.

-Code syle 1:

<Image>
</Image>
<Text>
    Text 1
</Text>
<Text>
    Text 2
</Text>

-Code syle 2:

<Text> 
    <Image>
    </Image>
    Text 1
    Text 2
</Text>

Both did not achieve the goal I wish. What goes wrong here?

like image 326
Josh Loo Avatar asked Jun 29 '16 01:06

Josh Loo


People also ask

How do you wrap text within a view in React Native?

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

How do I put text over an image in React?

Positioning Text Over the Image Element In order to write text over the img element, we need to: Have a container element that will hold the image and the text. Use img tag to display the background. Use any HTML element to display text over the image.

How do I display an image in a response in React?

To fetch image from API with React, we can use the fetch function. We call fetch with the imageUrl to make a GET request to it. Then we call res. blob to convert the response object to a blob.


1 Answers

Here's one way of doing it:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
} from 'react-native';

var SampleApp = React.createClass({
  render: function() {
    return (
      <View style={styles.container}>
        <Text>
          <Image style={styles.image} source={{uri: 'http://loremflickr.com/g/50/50/paris'}}/>
          Line 1
        </Text>
        <Text>
          <Image style={styles.image} source={{uri: 'http://loremflickr.com/g/50/50/paris'}}/>
          Line 2
        </Text>
      </View>
    );
  }
});

var styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#F5FCFF',
    marginTop: 40,
    marginHorizontal: 10,
  },
  image: {
    width: 50,
    height: 50,
  }
});

AppRegistry.registerComponent('SampleApp', () => SampleApp);

Here's how it looks:

sample output

like image 51
Jean Regisser Avatar answered Sep 28 '22 03:09

Jean Regisser