-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatListView.js
65 lines (58 loc) · 1.56 KB
/
ChatListView.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
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
ScrollView,
InteractionManager,
StatusBar
} from 'react-native';
var ChatEntry = require('./ChatEntry');
var styles = require('./Styles');
var getChats = require('./getChats')
class ChatListView extends Component {
constructor(props) {
super(props);
this.state = {
friends: [],
showLoading: true
}
}
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
getChats()
.then((response) => response.json())
.then((responseJson) => this.handleChats(responseJson))
.catch((error) => console.warn(error))
});
}
handleChats(json) {
this.setState({showLoading: false})
this.populateFriends(json)
}
populateFriends(json) {
for (var i = 1; i < json.length; i++) {
this.state.friends.push(
<ChatEntry name={json[i]} key={this.state.friends.length} navigator={this.props.navigator}/>)
}
this.setState({friends: this.state.friends})
}
render() {
var loading = !this.state.showLoading ? null :
<View ref="loading" style={styles.loadingContainer}>
<Text style={styles.loading}>Loading friends list...</Text>
</View>;
return (
<View style={styles.mainContainer}>
<StatusBar hidden={true} />
<Text style={styles.mainTitle}>Elegant Chat</Text>
<View style={styles.chatListSeparator}/>
{loading}
<ScrollView>
{this.state.friends}
</ScrollView>
</View>
)
};
}
module.exports = ChatListView;