-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
App.js
96 lines (93 loc) · 2.17 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
import React, { Component } from 'react';
// import {
// View,
// Image,
// } from 'react-native';
import { GiftedChat, Actions } from 'react-native-gifted-chat';
export default class Example extends Component {
constructor(props) {
super(props);
this.state = {
messages: [],
};
this.onSend = this.onSend.bind(this);
this.onReceive = this.onReceive.bind(this);
this.renderActions = this.renderActions.bind(this);
}
componentWillMount() {
this.setState({
messages: require('./data/messages.js'),
});
}
onSend(messages = []) {
this.setState((previousState) => {
return {
...previousState,
messages: GiftedChat.append(previousState.messages, messages),
};
});
// this.onReceive(); // for demo purpose
// this.onReceive(); // for demo purpose
}
onReceive() {
this.setState((previousState) => {
return {
...previousState,
messages: GiftedChat.append(previousState.messages, {
_id: Math.round(Math.random() * 1000000),
text: 'Hodor',
createdAt: new Date(),
user: {
_id: 2,
name: 'Bot',
avatar: 'https://facebook.github.io/react/img/logo_og.png',
},
}),
};
});
}
renderActions(props) {
const options = {
'Take Photo': (props) => {
console.log('option 1');
},
'Choose From Library': (props) => {
console.log('option 2');
},
'Send Location': (props) => {
console.log('option 3');
},
'Cancel': () => {},
};
// icon={() => {
// return (
// <Image
// style={{
// width: 20,
// height: 20,
// }}
// source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
// />
// );
// }}
return (
<Actions
{...props}
options={options}
/>
);
}
render() {
return (
<GiftedChat
messages={this.state.messages}
onSend={this.onSend}
loadEarlier={true}
user={{
_id: 1,
}}
renderActions={this.renderActions}
/>
);
}
}