Advertisement
enkf

Untitled

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