-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListaItens.js
More file actions
95 lines (78 loc) · 2.03 KB
/
Copy pathListaItens.js
File metadata and controls
95 lines (78 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, { Component } from 'react';
import {View, Text, ScrollView, StyleSheet, Image, Linking, Button} from 'react-native';
import axios from 'axios';
import Itens from './Itens';
export default class ListaItens extends Component {
constructor(props) {
super(props);
this.state = { listaItens: [] ,apiResponse:null, isLoading: true};
}
componentWillMount() {
fetch('http://portal.ema.net.br/api/configuracoes', { //com fetch
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}).then((response) => response.json())
.then((responseJson) => {
this.setState({
color: responseJson.COR,
});
}).catch((error) => {
console.warn(error);
});
axios.post('http://portal.ema.net.br/api/getprocedimentospublicos') //com axios :)
.then(response => {
let keys= Object.keys(response.data)
this.setState({ listaItens: keys,apiResponse:response.data });
//alert(JSON.stringify(response.data))
})
.catch(() => { console.log('Erro ao recuperar os dados'); });
}
render() {
return (
<View>
<ScrollView style={styles.scroll}>
<View style={[styles.barra, { backgroundColor: this.state.color}]}>
<Text style={styles.txt}>Portal Ema</Text>
</View>
<ScrollView style={{ backgroundColor: '#fff' }}>
{this.state.listaItens.map(item => (<Itens key={item} item={this.state.apiResponse[item]} />))}
</ScrollView>
</ScrollView>
</View>
);
}
}
const styles = StyleSheet.create({
barra: {
flex:1,
paddingTop:5,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
barend: {
flexDirection: 'row',
backgroundColor: 'blue',
marginLeft: 5,
marginRight: 5,
borderRadius: 10,
flex: 1,
justifyContent: 'flex-end',
marginBottom: 36
},
scroll:{
backgroundColor: '#fff',
paddingTop: 10,
paddingBottom: 400,
},
txt:{
marginTop: 5,
marginBottom: 5,
fontSize: 24,
color: '#fff',
textAlign: 'center'
}
});