Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- import {StyleSheet, View, Text, TextInput, ActivityIndicator, Image, ScrollView } from 'react-native';
- import AsyncStorage from '@react-native-community/async-storage';
- import { Button, CardItem, Card } from 'native-base'
- import Axios from 'axios';
- class Promotions extends Component {
- constructor(props) {
- super(props);
- this.state = {
- id:'',
- treatment_id: '',
- title: '',
- desc: '',
- image:'',
- status:'',
- token: '',
- promotionSource: []
- }
- }
- async componentDidMount(){
- const token = await AsyncStorage.getItem('token')
- // api profile
- const url = 'http://192.168.56.1/vzuu/public/api/promotions',
- headers = {'Authorization': 'Bearer ' + token,}
- fetch(url, headers, {method:'GET'})
- .then(data=>data.json())
- .then(res=> {
- console.log(res.results.promotions);
- // dari selesai fetching api profile
- const {id, title, image, desc} = res
- setTimeout(()=>{this.setState({loading:false})},2000)
- this.setState({id:id, title:title,desc:desc, image:image})
- })
- .catch(err=>console.warn({err}))
- }
- render() {
- return(
- <ScrollView>
- <View style={{ padding: 14, }}>
- <Card>
- <Image style={styles.img} source={{uri:this.state.image}} />
- <Text
- style={styles.text}>
- {`${this.state.title}`}
- </Text>
- <Text style={styles.text}>
- {`${this.state.desc}`}
- </Text>
- </Card>
- </View>
- </ScrollView>
- )
- }
- }
- export default Promotions;
- const styles = StyleSheet.create({
- container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
- img: {width: 370, height: 200},
- text: { fontSize: 18, fontWeight: 'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement