Advertisement
enkf

Untitled

Jan 19th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {StyleSheet, View, Text, TextInput, ActivityIndicator, Image, ScrollView } from 'react-native';
  3. import AsyncStorage from '@react-native-community/async-storage';
  4. import { Button, CardItem, Card } from 'native-base'
  5. import Axios from 'axios';
  6.  
  7.  
  8.  
  9. class Promotions extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. id:'',
  14. treatment_id: '',
  15. title: '',
  16. desc: '',
  17. image:'',
  18. status:'',
  19. token: '',
  20. promotionSource: []
  21. }
  22. }
  23.  
  24.  
  25. async componentDidMount(){
  26. const token = await AsyncStorage.getItem('token')
  27. // api profile
  28. const url = 'http://192.168.56.1/vzuu/public/api/promotions',
  29. headers = {'Authorization': 'Bearer ' + token,}
  30. fetch(url, headers, {method:'GET'})
  31. .then(data=>data.json())
  32. .then(res=> {
  33. console.log(res.results.promotions);
  34. // dari selesai fetching api profile
  35. const {id, title, image, desc} = res
  36. setTimeout(()=>{this.setState({loading:false})},2000)
  37. this.setState({id:id, title:title,desc:desc, image:image})
  38. })
  39. .catch(err=>console.warn({err}))
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. render() {
  47. return(
  48. <ScrollView>
  49. <View style={{ padding: 14, }}>
  50. <Card>
  51. <Image style={styles.img} source={{uri:this.state.image}} />
  52. <Text
  53. style={styles.text}>
  54. {`${this.state.title}`}
  55. </Text>
  56. <Text style={styles.text}>
  57. {`${this.state.desc}`}
  58. </Text>
  59. </Card>
  60. </View>
  61. </ScrollView>
  62. )
  63. }
  64. }
  65.  
  66. export default Promotions;
  67. const styles = StyleSheet.create({
  68. container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  69. img: {width: 370, height: 200},
  70. text: { fontSize: 18, fontWeight: 'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  71. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement