Advertisement
enkf

Untitled

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