-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
116 lines (106 loc) · 2.29 KB
/
App.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
TouchableOpacity,
Image,
} from 'react-native';
import { GiftedChat, Bubble, Send } from 'react-native-gifted-chat';
import randomColor from 'randomcolor';
import Backend from './Backend';
export default class App extends Component<{}> {
state = {
messages: [],
}
constructor(props) {
super(props);
this.renderBubble = this.renderBubble.bind(this);
this.renderSend = this.renderSend.bind(this);
}
onSend(messages = []) {
this.setState(previousState => ({
messages: GiftedChat.append(previousState.messages, messages),
}))
}
renderSend(props) {
return (
<Send
{...props}
>
<View style={{marginRight: 50, marginBottom: 50}} style={{}}>
<Image source={require('./src/images/send.png')} style={{height: 30, width: 30, bottom: 8, marginRight: 10}}/>
</View>
</Send>
);
}
renderBubble (props) {
return (
<Bubble
{...props}
wrapperStyle={{
right: {
backgroundColor: 'coral'
},
left: {
backgroundColor: randomColor()
}
}}
/>
)
}
componentDidMount() {
Backend.loadMessages((message) => {
this.setState((previousState) => {
return {
messages: GiftedChat.append(previousState.messages, message),
}
})
})
}
render() {
return (
<GiftedChat
placeholder="Type your beautiful message"
isLoadingEarlier
loadEarlier
isAnimated
showUserAvatar
messages={this.state.messages}
renderBubble={this.renderBubble}
renderSend={this.renderSend}
onSend={(message) => {
Backend.sendMessage(message);
}}
user={{
_id: Backend.getUid(),
name: `vijay${Backend.getUid()}`,
}}
/>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});