Advertisement
enkf

Untitled

Jan 17th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 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. }
  21. }
  22.  
  23. async componentDidMount(){
  24. const token = await AsyncStorage.getItem('token')
  25. // api profile
  26. const url = 'http://192.168.56.1/vzuu/public/api/promotions'
  27. headers = {'Authorization': 'Bearer ' + token,}
  28. fetch(url, headers, {method:'GET'})
  29. .then(data=>data.json())
  30. .then(res=> {
  31. // dari selesai fetching api profile
  32. const {id, treatment_id, title, desc, image, status} = res
  33. setTimeout(()=>{this.setState({loading:false})},2000)
  34. this.setState({id:id, treatment_id:treatment_id, title:title, desc:desc, image:image, status:status})
  35. })
  36. .catch(err=>console.warn({err}))
  37. }
  38.  
  39.  
  40. render() {
  41.  
  42. return(
  43. <ScrollView>
  44. <View style={{ padding: 14, }}>
  45. <Card>
  46. <Image style={styles.img} source={{uri:this.state.image}} />
  47. <Text
  48. style={styles.text}>
  49. {`Title : ${this.state.title}`}
  50. </Text>
  51. <Text style={styles.text}>
  52. {`Desc : ${this.state.desc}`}
  53. </Text>
  54. </Card>
  55. <Card>
  56. <Image style={styles.img} source={require('../../asset/images/diskon.png')} />
  57. <Text
  58. style={styles.text}>
  59. Get Promotion Discount Treatment Up 50%
  60. </Text>
  61. </Card>
  62. </View>
  63. </ScrollView>
  64. )
  65. }
  66. }
  67.  
  68. export default Promotions;
  69. const styles = StyleSheet.create({
  70. container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  71. img: {width: 370, height: 200},
  72. text: { fontSize: 18, fontWeight: 'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  73. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement