-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
96 lines (81 loc) · 2.05 KB
/
index.android.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
AppRegistry,
Text,
View,
ListView,
} from 'react-native';
import Header from './components/header';
import AvengerItem from './components/avenger-item';
import styles from './components/styles';
const REQUEST_URL = 'https://calm-spire-67121.herokuapp.com/api/v1/avengers.json';
export default class AvengersNative extends Component {
constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
filterText : ""
};
}
componentDidMount() {
this.fetchData();
}
fetchData() {
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData),
result: responseData,
loaded: true,
});
})
.done();
}
handleFilterTextInput(filterText) {
const filteredList = this.state.result.filter(avenger => avenger.name.toLowerCase().indexOf(filterText.toLowerCase()) !== -1);
this.setState({
filterText: filterText,
dataSource: this.state.dataSource.cloneWithRows(filteredList)
});
}
render() {
if (!this.state.loaded) {
return this.renderLoadingView();
}
return (
<View>
<Header filterText={this.state.filterText} onFilterTextInput={this.handleFilterTextInput.bind(this)} />
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderMovie}
style={styles.listView}
enableEmptySections={true}
/>
</View>
);
}
renderLoadingView() {
return (
<View style={styles.container}>
<Text>
Chargement...
</Text>
</View>
);
}
renderMovie(avenger) {
return (
<AvengerItem avenger={avenger} />
);
}
}
AppRegistry.registerComponent('AvengersNative', () => AvengersNative);