enkf

Untitled

Jan 20th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 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:1,
  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})},1000)
  37. this.setState({id:id, title:title, desc:desc, image:image})
  38. })
  39. .catch(err=>console.warn({err}))
  40. }
  41.  
  42.  
  43. // componentDidMount(){
  44. // const url = 'https://gist.githubusercontent.com/mahardika404/a48b4a2da23e2da0ecfe15c5979c91e8/raw/d3ce69eed5aab573c49e44acc20f7278a3fbc63a/test.json'
  45. // fetch(url, {method:'GET'})
  46. // .then(data=>data.json())
  47. // .then(res=> {
  48. // // dari selesai fetching api profile
  49. // const {id, name, profile, role} = res
  50. // setTimeout(()=>{this.setState({loading:false})},2000)
  51. // this.setState({id:id, name:name, profile:profile, role:role})
  52. // })
  53. // .catch(err=>console.warn({err}))
  54. // }
  55.  
  56.  
  57.  
  58. render() {
  59.  
  60. return(
  61. <ScrollView>
  62. <View style={{ padding: 14, }}>
  63. <Card>
  64. <Image style={styles.img} source={{uri:this.state.image}} />
  65. <Text
  66. style={styles.text}>
  67. {`${this.state.title}`}
  68. </Text>
  69. <Text style={styles.text}>
  70. {`${this.state.desc}`}
  71. </Text>
  72. </Card>
  73. {/* <Card>
  74. <Image style={styles.img} source={{uri:this.state.profile}} />
  75. <Text
  76. style={styles.text}>
  77. {`${this.state.name}`}
  78. </Text>
  79. <Text style={styles.text}>
  80. {`${this.state.role}`}
  81. </Text>
  82. </Card> */}
  83. </View>
  84. </ScrollView>
  85. )
  86. }
  87. }
  88.  
  89. export default Promotions;
  90. const styles = StyleSheet.create({
  91. container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  92. img: {width: 370, height: 200},
  93. text: { fontSize: 18, fontWeight: 'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  94. })
Add Comment
Please, Sign In to add comment