-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
64 lines (58 loc) · 1.8 KB
/
App.js
File metadata and controls
64 lines (58 loc) · 1.8 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
import React, {useEffect, useState} from "react";
import {View, Text, FlatList, Image, StyleSheet, ActivityIndicator} from "react-native";
import api from "./src/services/api";
export default function App() {
const [movies, setMovies] = useState(null);
async function getMovies() {
try {
const response = await api.get(`r-api/?api=filmes`);
setMovies(response.data);
} catch (error) {
alert(`Não foi possível conectar-se ao servidor! ${error}`);
}
}
useEffect(
() => {
getMovies();
}
);
return(
<View style={styles.container}>
{ movies ?
<FlatList
data={movies}
keyExtractor={(item)=>item.id.toString()}
renderItem={({item}) => ComponentMovie(item)}
/>
:
<View style={styles.loading}>
<ActivityIndicator
size={40}
color={'#aaa'}
/>
</View>
}
</View>
)
}
function ComponentMovie(movie) {
return(
<View style={styles.movie}>
<Text style={styles.movie__title}>{movie.nome}</Text>
<Image
style={styles.movie__image}
source={{uri: movie.foto}}
/>
<Text style={styles.movie__sinopse}> {movie.sinopse}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {flex: 1, backgroundColor: '#322924'},
loading: {flex: 1, justifyContent: 'center', alignItems: 'center'},
loading__indicator: {},
movie: {backgroundColor: '#251e1a', marginTop: 5, marginHorizontal: 10, marginBottom: 5, padding: 10, borderRadius: 10},
movie__title: {fontSize: 18, fontWeight: '800', color: '#aaa', textTransform: 'uppercase', marginBottom: 10},
movie__image: { width: '100%', height: 300, borderRadius: 10},
movie__sinopse: {fontSize: 12, color: '#aaa', textAlign: 'justify', marginTop: 10}
});