Advertisement
enkf

Untitled

Jan 21st, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {StyleSheet, View, Text, TextInput, ActivityIndicator,FlatList, Image, ScrollView } from 'react-native';
  3. import AsyncStorage from '@react-native-community/async-storage';
  4. import { Button, CardItem, Card, Left } 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. data: [],
  14. renders: [],
  15. id:'',
  16. treatment_id: '',
  17. title: '',
  18. desc: '',
  19. image:'',
  20. status:'',
  21. token: '',
  22.  
  23. }
  24. }
  25.  
  26.  
  27. async componentDidMount(){
  28. const token = await AsyncStorage.getItem('token')
  29. headers = {'Authorization': 'Bearer ' + token }
  30. this.makeRemoteRequest();
  31. }
  32. makeRemoteRequest = () => {
  33.  
  34. // api profile
  35. const url = 'http://192.168.56.1/vzuu/public/api/promotions'
  36. // headers = {'Authorization': 'Bearer ' + token }
  37. fetch(url, headers, {method:'GET'})
  38. .then(data=>data.json())
  39. .then(res=> {
  40. console.log(res.results.promotions);
  41. // dari selesai fetching api profile
  42.  
  43. setTimeout(()=>{this.setState({loading:false})},1000)
  44. this.setState({
  45. data: res.results.promotions,
  46. renders: res.results.promotions.data,
  47. })
  48. console.log(this.state);
  49. })
  50. .catch(err=>console.warn({err}))
  51. }
  52.  
  53.  
  54. // componentDidMount(){
  55. // const url = \'https://gist.githubusercontent.com/mahardika404/a48b4a2da23e2da0ecfe15c5979c91e8/raw/d3ce69eed5aab573c49e44acc20f7278a3fbc63a/test.json\'
  56. // fetch(url, {method:\'GET\'})
  57. // .then(data=>data.json())
  58. // .then(res=> {
  59. // // dari selesai fetching api profile
  60. // const {id, name, profile, role} = res
  61. // setTimeout(()=>{this.setState({loading:false})},2000)
  62. // this.setState({id:id, name:name, profile:profile, role:role})
  63. // })
  64. // .catch(err=>console.warn({err}))
  65. // }
  66.  
  67.  
  68.  
  69. render() {
  70.  
  71. return(
  72. <ScrollView>
  73. <View style={{ padding: 14, }}>
  74. <Card>
  75. <FlatList
  76. data={this.state.renders}
  77. renderItem={({ item }) => (
  78. <Text>{item.image}</Text>
  79. // <Image style={styles.img} source={{uri:item.image}} />
  80.  
  81. )}
  82. />
  83. </Card>
  84. {/* <Card>
  85. <Image style={styles.img} source={{uri:this.state.profile}} />
  86. <Text
  87. style={styles.text}>
  88. {`${this.state.name}`}
  89. </Text>
  90. <Text style={styles.text}>
  91. {`${this.state.role}`}
  92. </Text>
  93. </Card> */}
  94. </View>
  95. </ScrollView>
  96. )
  97. }
  98. }
  99.  
  100. export default Promotions;
  101. const styles = StyleSheet.create({
  102. container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  103. img: {width: 370, height: 200},
  104. text: { fontSize: 18, fontWeight:'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  105. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement