Apps.js
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Image,
Dimensions,
FlatList,
AppRegistry
} from 'react-native';
import Post from './components/Post';
const width = Dimensions.get('screen').width;
class App extends Component {
constructor() {
super();
this.state = {
fotos: []
}
}
componentDidMount() {
fetch('https://instalura-api.herokuapp.com/api/public/fotos/rafael')
.then(resposta => resposta.json())
.then(json => this.setState({fotos: json}));
}
render() {
return (
<FlatList style={styles.container}
keyExtractor={item => String(item.id)}
data={this.state.fotos}
renderItem={ ({item}) =>
<Post foto={item}/>
}
/>
);
}
}
const styles = StyleSheet.create({
constainer:{
marginTop: 20
}
});
export default () => {
AppRegistry.registerComponent('InstaluraMobile', () => App);
}
Post.js
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
Image,
Dimensions,
FlatList
} from 'react-native';
const width = Dimensions.get('screen').width;
export default class Post extends Component<{}> {
render() {
return(
<View>
<View style={styles.cabecalho}>
<Image source={{uri: this.props.foto.urlPerfil}} style={styles.fotoDePerfil} />
<Text>{this.props.foto.loginUsuario}</Text>
</View>
<Image source={{uri: this.props.foto.urlFoto}} style={styles.foto} />
</View>
);
}
}
const styles = StyleSheet.create({
cabecalho: {
margin:10,
flexDirection: 'row',
alignItems: 'center'
},
fotoDePerfil: {
margin: 10,
borderRadius: 20,
width:40, height:40
},
foto: {
width:width,
height:width
}
})
Nao apresenta erro no app. Mas se chamar a API direto do browser e tentar acessar a url da foto, retorna msg de acesso negado. Como proceder?