Advertisement
enkf

Untitled

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