I have a problem wrapping the content of text and image in a View..
--Image-Text line 1
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?
To wrap React Native text on the screen, we can set flexWrap to 'wrap' .
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.
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.
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:
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