-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageList.js
59 lines (58 loc) · 1.56 KB
/
MessageList.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
import React from 'react';
import { StyleSheet, Text, View, FlatList } from 'react-native';
const styles = StyleSheet.create({
main:{
flexDirection: 'row',
justifyContent: 'flex-start'
},
messageboxuser:{
flexDirection:'row',
justifyContent:'flex-end',
margin:5,
},
messageboxreceiver:{
flexDirection:'row',
justifyContent:'flex-start',
margin:5
},
receiverTextArea:{
backgroundColor:'#f0ffff',
padding:15,
borderRadius:10,
borderBottomRightRadius:-10
},
userTextArea:{
backgroundColor:'#C1F09B',
padding:15,
borderRadius:10,
borderBottomRightRadius:-10
}
})
export default class MessageList extends React.Component{
constructor(props){
super(props)
console.log("constructing messageList")
}
scrollToIndex = () => {
this.flatListRef.scrollToIndex({animated: true, index: 3});
}
render(){
return(
<View>
<FlatList
ref={(ref) => { this.flatListRef = ref; }}
inverted={true}
data={this.props.messages.reverse()}
renderItem={({ item }) =>
<View style={this.props.user==item.receiver?styles.messageboxreceiver:styles.messageboxuser}>
<View style={this.props.user==item.receiver?styles.receiverTextArea:styles.userTextArea}>
<Text>{item.message}</Text>
</View>
</View>
}
keyExtractor={item => item.id.toString()}
/>
</View>
)
}
}