-
Notifications
You must be signed in to change notification settings - Fork 41
/
MovieScreen.js
102 lines (92 loc) · 2.98 KB
/
MovieScreen.js
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
95
96
97
98
99
100
101
102
import React from 'react';
import { Text, View, StyleSheet, StatusBar, Animated, Image, ScrollView } from 'react-native';
import Shimmer from '../components/Shimmer';
import axios from 'axios';
import AppConstant from '../constants/AppConstants';
const URL_DISCOVER = 'https://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&api_key=<YOUR_API_KEY>&page=1'
class MovieScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
isVisible: false,
movieData: []
}
}
getMovieDetails() {
return axios.get(URL_DISCOVER)
}
componentDidMount() {
this.getMovieDetails().then((result) => {
let results = result.data.results;
let movieArray = [];
results.forEach((value) => {
let movie = {
title: value.title,
rating: value.vote_average,
poster: 'https://image.tmdb.org/t/p/w185' + value.poster_path
}
movieArray.push(movie)
})
this.setState({
movieData: movieArray
})
})
}
componentWillMount() {
setTimeout(() => {
this.setState({
isVisible: true
})
}, 5000)
}
render() {
console.log('state', this.state.movieData)
const { navigate } = this.props.navigation;
return (
<ScrollView style={styles.container}>
{
this.state.movieData.map((value, index) => {
const uri = value.poster;
return (<View style={styles.imageContent} key={index}>
<Shimmer autoRun={true} style={styles.imagew} visible={this.state.isVisible}>
<Image style={styles.imagew}
source={{ uri: uri }}></Image>
</Shimmer>
<View style={styles.movieContent}>
<Shimmer autoRun={true} visible={this.state.isVisible}>
<Text>{value.title}</Text>
</Shimmer>
<Shimmer autoRun={true} visible={this.state.isVisible}>
<Text>{value.rating}</Text>
</Shimmer>
</View>
</View>)
})
}
</ScrollView>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1
},
imageContent: {
flexDirection: 'row',
margin: 16
},
movieContent: {
margin: 8,
justifyContent: 'space-between',
flexDirection: 'column'
},
imagew: {
width: 80,
height: 80
},
mcontent: {
marginTop: 8,
marginBottom: 8
}
})
export default MovieScreen;