-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathindex.ios.js
74 lines (64 loc) · 1.45 KB
/
index.ios.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var SearchInput = require('./app/components/SearchInput');
var Container = require('./app/components/layout/Container');
var Button = require('./app/components/buttons/Button');
var MovieItem = require('./app/components/movie/MovieItem');
var Store = require('./app/store/Store');
var {
fetchMovies
} = require('./app/actions/index');
var {
AppRegistry,
StyleSheet,
Text,
TextInput,
View,
Image,
Animated,
ScrollView,
Navigator
} = React;
class MoviesBox extends React.Component {
constructor(props) {
super(props);
this.state = {
movies: []
};
}
onChangeText(text) {
if (text.length >= 2) {
Store.dispatch(fetchMovies(text));
} else {
this.setState({
movies: []
});
}
}
componentDidMount() {
Store.subscribe(() => {
this.setState({
movies: Store.getState().movies.items
});
});
}
render() {
return (
<Container>
<SearchInput onChangeText={this.onChangeText.bind(this)}/>
<ScrollView>
{
this.state.movies.map(movie => {
return <MovieItem title={movie.Title} year={movie.Year} poster={movie.Poster} type={movie.Type} />
})
}
</ScrollView>
</Container>
);
}
}
AppRegistry.registerComponent('AwesomeProject', () => MoviesBox);