Guest User

Untitled

a guest
Jan 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. Image,
  4. StyleSheet,
  5. Text,
  6. View,
  7. } from 'react-native';
  8.  
  9. export default class App extends Component {
  10. constructor(props){
  11. super(props);
  12. this.state = {
  13. photos: '',
  14. titles: ''
  15. };
  16. }
  17.  
  18. componentWillMount(){
  19. this.fetchData();
  20. }
  21.  
  22. fetchData = async () => {
  23. let response = await fetch('http://jsonplaceholder.typicode.com/photos/1');
  24. let json = await response.json();
  25. this.setState({titles: json.title, photos: json.url.replace('http','https')});
  26. };
  27.  
  28. render() {
  29. console.log(this.state.photos)
  30. return (
  31. <View style={styles.container}>
  32. <Image
  33. source={{uri: this.state.photos}}
  34. style={{height: 600, width: 600}}
  35. resizeMode= 'cover'
  36. />
  37. <Text>
  38. Title: {this.state.titles}
  39. </Text>
  40. </View>
  41. );
  42. }
  43. }
  44.  
  45. const styles = StyleSheet.create({
  46. container: {
  47. flex: 1,
  48. alignItems: 'center',
  49. justifyContent: 'center',
  50. backgroundColor: '#ecf0f1',
  51. }
  52. });
Add Comment
Please, Sign In to add comment