react-native-gifted-chat 2.6.4 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -16
- package/lib/Actions.d.ts +0 -11
- package/lib/Actions.js +2 -14
- package/lib/Actions.js.map +1 -1
- package/lib/Avatar.d.ts +1 -23
- package/lib/Avatar.js +32 -40
- package/lib/Avatar.js.map +1 -1
- package/lib/Bubble/index.d.ts +30 -0
- package/lib/{Bubble.js → Bubble/index.js} +31 -181
- package/lib/Bubble/index.js.map +1 -0
- package/lib/Bubble/styles.d.ts +69 -0
- package/lib/Bubble/styles.js +72 -0
- package/lib/Bubble/styles.js.map +1 -0
- package/lib/Bubble/types.d.ts +47 -0
- package/lib/Bubble/types.js +2 -0
- package/lib/Bubble/types.js.map +1 -0
- package/lib/Composer.d.ts +0 -17
- package/lib/Composer.js +3 -18
- package/lib/Composer.js.map +1 -1
- package/lib/Constant.d.ts +1 -1
- package/lib/Constant.js +1 -1
- package/lib/Constant.js.map +1 -1
- package/lib/Day/index.d.ts +4 -0
- package/lib/Day/index.js +39 -0
- package/lib/Day/index.js.map +1 -0
- package/lib/Day/styles.d.ts +20 -0
- package/lib/Day/styles.js +22 -0
- package/lib/Day/styles.js.map +1 -0
- package/lib/Day/types.d.ts +9 -0
- package/lib/Day/types.js +2 -0
- package/lib/Day/types.js.map +1 -0
- package/lib/GiftedAvatar.d.ts +1 -11
- package/lib/GiftedAvatar.js +26 -33
- package/lib/GiftedAvatar.js.map +1 -1
- package/lib/GiftedChat/index.d.ts +26 -0
- package/lib/{GiftedChat.js → GiftedChat/index.js} +58 -59
- package/lib/GiftedChat/index.js.map +1 -0
- package/lib/GiftedChat/styles.d.ts +6 -0
- package/lib/GiftedChat/styles.js +7 -0
- package/lib/GiftedChat/styles.js.map +1 -0
- package/lib/{GiftedChat.d.ts → GiftedChat/types.d.ts} +29 -37
- package/lib/GiftedChat/types.js +2 -0
- package/lib/GiftedChat/types.js.map +1 -0
- package/lib/InputToolbar.d.ts +1 -14
- package/lib/InputToolbar.js +0 -12
- package/lib/InputToolbar.js.map +1 -1
- package/lib/LoadEarlier.d.ts +0 -14
- package/lib/LoadEarlier.js +2 -16
- package/lib/LoadEarlier.js.map +1 -1
- package/lib/Message/index.d.ts +6 -0
- package/lib/Message/index.js +85 -0
- package/lib/Message/index.js.map +1 -0
- package/lib/Message/styles.d.ts +21 -0
- package/lib/Message/styles.js +22 -0
- package/lib/Message/styles.js.map +1 -0
- package/lib/Message/types.d.ts +22 -0
- package/lib/Message/types.js +2 -0
- package/lib/Message/types.js.map +1 -0
- package/lib/MessageAudio.js +1 -2
- package/lib/MessageAudio.js.map +1 -1
- package/lib/MessageContainer/components/DayAnimated/index.d.ts +5 -0
- package/lib/MessageContainer/components/DayAnimated/index.js +85 -0
- package/lib/MessageContainer/components/DayAnimated/index.js.map +1 -0
- package/lib/MessageContainer/components/DayAnimated/styles.d.ts +11 -0
- package/lib/MessageContainer/components/DayAnimated/styles.js +12 -0
- package/lib/MessageContainer/components/DayAnimated/styles.js.map +1 -0
- package/lib/MessageContainer/components/DayAnimated/types.d.ts +17 -0
- package/lib/MessageContainer/components/DayAnimated/types.js +2 -0
- package/lib/MessageContainer/components/DayAnimated/types.js.map +1 -0
- package/lib/MessageContainer/components/Item/index.d.ts +22 -0
- package/lib/MessageContainer/components/Item/index.js +69 -0
- package/lib/MessageContainer/components/Item/index.js.map +1 -0
- package/lib/MessageContainer/components/Item/types.d.ts +18 -0
- package/lib/MessageContainer/components/Item/types.js +2 -0
- package/lib/MessageContainer/components/Item/types.js.map +1 -0
- package/lib/MessageContainer/index.d.ts +6 -0
- package/lib/MessageContainer/index.js +175 -0
- package/lib/MessageContainer/index.js.map +1 -0
- package/lib/MessageContainer/styles.d.ts +34 -0
- package/lib/MessageContainer/styles.js +31 -0
- package/lib/MessageContainer/styles.js.map +1 -0
- package/lib/MessageContainer/types.d.ts +54 -0
- package/lib/MessageContainer/types.js +2 -0
- package/lib/MessageContainer/types.js.map +1 -0
- package/lib/MessageImage.d.ts +1 -12
- package/lib/MessageImage.js +2 -12
- package/lib/MessageImage.js.map +1 -1
- package/lib/MessageText.d.ts +1 -24
- package/lib/MessageText.js +0 -22
- package/lib/MessageText.js.map +1 -1
- package/lib/MessageVideo.js +1 -2
- package/lib/MessageVideo.js.map +1 -1
- package/lib/QuickReplies.d.ts +1 -12
- package/lib/QuickReplies.js +10 -20
- package/lib/QuickReplies.js.map +1 -1
- package/lib/Send.d.ts +2 -16
- package/lib/Send.js +0 -13
- package/lib/Send.js.map +1 -1
- package/lib/SystemMessage.d.ts +1 -10
- package/lib/SystemMessage.js +2 -12
- package/lib/SystemMessage.js.map +1 -1
- package/lib/Time.d.ts +1 -17
- package/lib/Time.js +0 -15
- package/lib/Time.js.map +1 -1
- package/lib/TypingIndicator/index.d.ts +5 -0
- package/lib/{TypingIndicator.js → TypingIndicator/index.js} +9 -30
- package/lib/TypingIndicator/index.js.map +1 -0
- package/lib/TypingIndicator/styles.d.ts +20 -0
- package/lib/TypingIndicator/styles.js +22 -0
- package/lib/TypingIndicator/styles.js.map +1 -0
- package/lib/TypingIndicator/types.d.ts +3 -0
- package/lib/TypingIndicator/types.js +2 -0
- package/lib/TypingIndicator/types.js.map +1 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/styles.d.ts +10 -0
- package/lib/styles.js +11 -0
- package/lib/styles.js.map +1 -0
- package/lib/{Models.d.ts → types.d.ts} +1 -1
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +1 -3
- package/lib/utils.js +0 -7
- package/lib/utils.js.map +1 -1
- package/package.json +30 -34
- package/src/Actions.tsx +3 -15
- package/src/Avatar.tsx +43 -52
- package/src/{Bubble.tsx → Bubble/index.tsx} +53 -270
- package/src/Bubble/styles.ts +73 -0
- package/src/Bubble/types.ts +90 -0
- package/src/Composer.tsx +3 -19
- package/src/Constant.ts +1 -1
- package/src/Day/index.tsx +63 -0
- package/src/Day/styles.ts +22 -0
- package/src/Day/types.ts +14 -0
- package/src/GiftedAvatar.tsx +31 -38
- package/src/GiftedChat/index.tsx +503 -0
- package/src/GiftedChat/styles.ts +7 -0
- package/src/GiftedChat/types.ts +206 -0
- package/src/InputToolbar.tsx +1 -14
- package/src/LoadEarlier.tsx +2 -17
- package/src/Message/index.tsx +135 -0
- package/src/Message/styles.ts +22 -0
- package/src/Message/types.ts +26 -0
- package/src/MessageAudio.tsx +1 -4
- package/src/MessageContainer/components/DayAnimated/index.tsx +143 -0
- package/src/MessageContainer/components/DayAnimated/styles.ts +12 -0
- package/src/MessageContainer/components/DayAnimated/types.ts +12 -0
- package/src/MessageContainer/components/Item/index.tsx +136 -0
- package/src/MessageContainer/components/Item/types.ts +13 -0
- package/src/MessageContainer/index.tsx +316 -0
- package/src/MessageContainer/styles.ts +31 -0
- package/src/MessageContainer/types.ts +60 -0
- package/src/MessageImage.tsx +3 -14
- package/src/MessageText.tsx +2 -25
- package/src/MessageVideo.tsx +1 -4
- package/src/QuickReplies.tsx +14 -25
- package/src/Send.tsx +1 -15
- package/src/SystemMessage.tsx +3 -14
- package/src/Time.tsx +1 -17
- package/src/{TypingIndicator.tsx → TypingIndicator/index.tsx} +12 -35
- package/src/TypingIndicator/styles.ts +22 -0
- package/src/TypingIndicator/types.ts +3 -0
- package/src/__tests__/Bubble.test.tsx +7 -4
- package/src/__tests__/GiftedAvatar.test.tsx +6 -2
- package/src/__tests__/GiftedChat.test.tsx +20 -14
- package/src/__tests__/Message.test.tsx +4 -1
- package/src/__tests__/__snapshots__/Actions.test.tsx.snap +6 -2
- package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +3 -1
- package/src/__tests__/__snapshots__/Composer.test.tsx.snap +2 -0
- package/src/__tests__/__snapshots__/Constant.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/Day.test.tsx.snap +1 -33
- package/src/__tests__/__snapshots__/GiftedAvatar.test.tsx.snap +4 -2
- package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +22 -9
- package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +2 -0
- package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +3 -1
- package/src/__tests__/__snapshots__/Message.test.tsx.snap +21 -100
- package/src/__tests__/__snapshots__/MessageContainer.test.tsx.snap +282 -82
- package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +8 -4
- package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +5 -1
- package/src/__tests__/data.ts +1 -1
- package/src/index.ts +0 -2
- package/src/styles.ts +11 -0
- package/src/{Models.ts → types.ts} +1 -1
- package/src/utils.ts +1 -9
- package/example_bare/vendor/bundle/ruby/2.7.0/gems/ffi-1.17.0/ext/ffi_c/libffi/.ci/compile +0 -351
- package/example_bare/vendor/bundle/ruby/2.7.0/gems/ffi-1.17.0/ext/ffi_c/libffi/testsuite/libffi.bhaible/Makefile +0 -28
- package/lib/Actions.js.flow +0 -21
- package/lib/Avatar.js.flow +0 -27
- package/lib/Bubble.d.ts +0 -148
- package/lib/Bubble.js.flow +0 -69
- package/lib/Bubble.js.map +0 -1
- package/lib/Composer.js.flow +0 -24
- package/lib/Day.d.ts +0 -15
- package/lib/Day.js +0 -36
- package/lib/Day.js.flow +0 -23
- package/lib/Day.js.map +0 -1
- package/lib/GiftedAvatar.js.flow +0 -17
- package/lib/GiftedChat.js.flow +0 -163
- package/lib/GiftedChat.js.map +0 -1
- package/lib/InputToolbar.js.flow +0 -31
- package/lib/LoadEarlier.js.flow +0 -20
- package/lib/Message.d.ts +0 -67
- package/lib/Message.js +0 -157
- package/lib/Message.js.flow +0 -32
- package/lib/Message.js.map +0 -1
- package/lib/MessageAudio.js.flow +0 -15
- package/lib/MessageContainer.d.ts +0 -103
- package/lib/MessageContainer.js +0 -224
- package/lib/MessageContainer.js.flow +0 -39
- package/lib/MessageContainer.js.map +0 -1
- package/lib/MessageImage.js.flow +0 -20
- package/lib/MessageText.js.flow +0 -23
- package/lib/MessageVideo.js.flow +0 -16
- package/lib/Models.js +0 -2
- package/lib/Models.js.map +0 -1
- package/lib/QuickReplies.js.flow +0 -25
- package/lib/Send.js.flow +0 -19
- package/lib/SystemMessage.js.flow +0 -18
- package/lib/Time.js.flow +0 -19
- package/lib/TypingIndicator.d.ts +0 -6
- package/lib/TypingIndicator.js.map +0 -1
- package/lib/index.js.flow +0 -2
- package/lib/types.js.flow +0 -43
- package/lib/utils.js.flow +0 -16
- package/src/Day.tsx +0 -71
- package/src/GiftedChat.tsx +0 -678
- package/src/Message.tsx +0 -229
- package/src/MessageContainer.tsx +0 -359
package/src/Message.tsx
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import { View, StyleSheet, ViewStyle, LayoutChangeEvent } from 'react-native'
|
|
4
|
-
import isEqual from 'lodash.isequal'
|
|
5
|
-
|
|
6
|
-
import { Avatar, AvatarProps } from './Avatar'
|
|
7
|
-
import Bubble from './Bubble'
|
|
8
|
-
import { SystemMessage, SystemMessageProps } from './SystemMessage'
|
|
9
|
-
import { Day, DayProps } from './Day'
|
|
10
|
-
|
|
11
|
-
import { StylePropType, isSameUser } from './utils'
|
|
12
|
-
import { IMessage, User, LeftRightStyle } from './Models'
|
|
13
|
-
|
|
14
|
-
const styles = {
|
|
15
|
-
left: StyleSheet.create({
|
|
16
|
-
container: {
|
|
17
|
-
flexDirection: 'row',
|
|
18
|
-
alignItems: 'flex-end',
|
|
19
|
-
justifyContent: 'flex-start',
|
|
20
|
-
marginLeft: 8,
|
|
21
|
-
marginRight: 0,
|
|
22
|
-
},
|
|
23
|
-
}),
|
|
24
|
-
right: StyleSheet.create({
|
|
25
|
-
container: {
|
|
26
|
-
flexDirection: 'row',
|
|
27
|
-
alignItems: 'flex-end',
|
|
28
|
-
justifyContent: 'flex-end',
|
|
29
|
-
marginLeft: 0,
|
|
30
|
-
marginRight: 8,
|
|
31
|
-
},
|
|
32
|
-
}),
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface MessageProps<TMessage extends IMessage> {
|
|
36
|
-
showUserAvatar?: boolean
|
|
37
|
-
position: 'left' | 'right'
|
|
38
|
-
currentMessage: TMessage
|
|
39
|
-
nextMessage?: TMessage
|
|
40
|
-
previousMessage?: TMessage
|
|
41
|
-
user: User
|
|
42
|
-
inverted?: boolean
|
|
43
|
-
containerStyle?: LeftRightStyle<ViewStyle>
|
|
44
|
-
renderBubble?(props: Bubble['props']): React.ReactNode
|
|
45
|
-
renderDay?(props: DayProps<TMessage>): React.ReactNode
|
|
46
|
-
renderSystemMessage?(props: SystemMessageProps<TMessage>): React.ReactNode
|
|
47
|
-
renderAvatar?(props: AvatarProps<TMessage>): React.ReactNode
|
|
48
|
-
shouldUpdateMessage?(
|
|
49
|
-
props: MessageProps<IMessage>,
|
|
50
|
-
nextProps: MessageProps<IMessage>,
|
|
51
|
-
): boolean
|
|
52
|
-
onMessageLayout?(event: LayoutChangeEvent): void
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default class Message<
|
|
56
|
-
TMessage extends IMessage = IMessage,
|
|
57
|
-
> extends React.Component<MessageProps<TMessage>> {
|
|
58
|
-
static defaultProps = {
|
|
59
|
-
renderAvatar: undefined,
|
|
60
|
-
renderBubble: null,
|
|
61
|
-
renderDay: null,
|
|
62
|
-
renderSystemMessage: null,
|
|
63
|
-
position: 'left',
|
|
64
|
-
currentMessage: {},
|
|
65
|
-
nextMessage: {},
|
|
66
|
-
previousMessage: {},
|
|
67
|
-
user: {},
|
|
68
|
-
containerStyle: {},
|
|
69
|
-
showUserAvatar: false,
|
|
70
|
-
inverted: true,
|
|
71
|
-
shouldUpdateMessage: undefined,
|
|
72
|
-
onMessageLayout: undefined,
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
static propTypes = {
|
|
76
|
-
renderAvatar: PropTypes.func,
|
|
77
|
-
showUserAvatar: PropTypes.bool,
|
|
78
|
-
renderBubble: PropTypes.func,
|
|
79
|
-
renderDay: PropTypes.func,
|
|
80
|
-
renderSystemMessage: PropTypes.func,
|
|
81
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
82
|
-
currentMessage: PropTypes.object,
|
|
83
|
-
nextMessage: PropTypes.object,
|
|
84
|
-
previousMessage: PropTypes.object,
|
|
85
|
-
user: PropTypes.object,
|
|
86
|
-
inverted: PropTypes.bool,
|
|
87
|
-
containerStyle: PropTypes.shape({
|
|
88
|
-
left: StylePropType,
|
|
89
|
-
right: StylePropType,
|
|
90
|
-
}),
|
|
91
|
-
shouldUpdateMessage: PropTypes.func,
|
|
92
|
-
onMessageLayout: PropTypes.func,
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
shouldComponentUpdate (nextProps: MessageProps<TMessage>) {
|
|
96
|
-
const next = nextProps.currentMessage!
|
|
97
|
-
const current = this.props.currentMessage!
|
|
98
|
-
const { previousMessage, nextMessage } = this.props
|
|
99
|
-
const nextPropsMessage = nextProps.nextMessage
|
|
100
|
-
const nextPropsPreviousMessage = nextProps.previousMessage
|
|
101
|
-
|
|
102
|
-
let shouldUpdate =
|
|
103
|
-
this.props.shouldUpdateMessage?.(this.props, nextProps) || false
|
|
104
|
-
|
|
105
|
-
shouldUpdate =
|
|
106
|
-
shouldUpdate ||
|
|
107
|
-
!isEqual(current, next) ||
|
|
108
|
-
!isEqual(previousMessage, nextPropsPreviousMessage) ||
|
|
109
|
-
!isEqual(nextMessage, nextPropsMessage)
|
|
110
|
-
|
|
111
|
-
return shouldUpdate
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
renderDay () {
|
|
115
|
-
if (this.props.currentMessage && this.props.currentMessage.createdAt) {
|
|
116
|
-
const {
|
|
117
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
118
|
-
containerStyle,
|
|
119
|
-
onMessageLayout,
|
|
120
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
121
|
-
...props
|
|
122
|
-
} = this.props
|
|
123
|
-
|
|
124
|
-
if (this.props.renderDay)
|
|
125
|
-
return this.props.renderDay(props)
|
|
126
|
-
|
|
127
|
-
return <Day {...props} />
|
|
128
|
-
}
|
|
129
|
-
return null
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
renderBubble () {
|
|
133
|
-
const {
|
|
134
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
135
|
-
containerStyle,
|
|
136
|
-
onMessageLayout,
|
|
137
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
138
|
-
...props
|
|
139
|
-
} = this.props
|
|
140
|
-
|
|
141
|
-
if (this.props.renderBubble)
|
|
142
|
-
return this.props.renderBubble(props)
|
|
143
|
-
|
|
144
|
-
return <Bubble {...props} />
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
renderSystemMessage () {
|
|
148
|
-
const {
|
|
149
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
150
|
-
containerStyle,
|
|
151
|
-
onMessageLayout,
|
|
152
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
153
|
-
...props
|
|
154
|
-
} = this.props
|
|
155
|
-
|
|
156
|
-
if (this.props.renderSystemMessage)
|
|
157
|
-
return this.props.renderSystemMessage(props)
|
|
158
|
-
|
|
159
|
-
return <SystemMessage {...props} />
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
renderAvatar () {
|
|
163
|
-
const { user, currentMessage, showUserAvatar } = this.props
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
user &&
|
|
167
|
-
user._id &&
|
|
168
|
-
currentMessage &&
|
|
169
|
-
currentMessage.user &&
|
|
170
|
-
user._id === currentMessage.user._id &&
|
|
171
|
-
!showUserAvatar
|
|
172
|
-
)
|
|
173
|
-
return null
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
currentMessage &&
|
|
177
|
-
currentMessage.user &&
|
|
178
|
-
currentMessage.user.avatar === null
|
|
179
|
-
)
|
|
180
|
-
return null
|
|
181
|
-
|
|
182
|
-
const {
|
|
183
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
184
|
-
containerStyle,
|
|
185
|
-
onMessageLayout,
|
|
186
|
-
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
187
|
-
...props
|
|
188
|
-
} = this.props
|
|
189
|
-
|
|
190
|
-
return <Avatar {...props} />
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
render () {
|
|
194
|
-
const {
|
|
195
|
-
currentMessage,
|
|
196
|
-
onMessageLayout,
|
|
197
|
-
nextMessage,
|
|
198
|
-
position,
|
|
199
|
-
containerStyle,
|
|
200
|
-
} = this.props
|
|
201
|
-
if (currentMessage) {
|
|
202
|
-
const sameUser = isSameUser(currentMessage, nextMessage!)
|
|
203
|
-
return (
|
|
204
|
-
<View onLayout={onMessageLayout}>
|
|
205
|
-
{this.renderDay()}
|
|
206
|
-
{currentMessage.system
|
|
207
|
-
? (
|
|
208
|
-
this.renderSystemMessage()
|
|
209
|
-
)
|
|
210
|
-
: (
|
|
211
|
-
<View
|
|
212
|
-
style={[
|
|
213
|
-
styles[position].container,
|
|
214
|
-
{ marginBottom: sameUser ? 2 : 10 },
|
|
215
|
-
!this.props.inverted && { marginBottom: 2 },
|
|
216
|
-
containerStyle && containerStyle[position],
|
|
217
|
-
]}
|
|
218
|
-
>
|
|
219
|
-
{this.props.position === 'left' ? this.renderAvatar() : null}
|
|
220
|
-
{this.renderBubble()}
|
|
221
|
-
{this.props.position === 'right' ? this.renderAvatar() : null}
|
|
222
|
-
</View>
|
|
223
|
-
)}
|
|
224
|
-
</View>
|
|
225
|
-
)
|
|
226
|
-
}
|
|
227
|
-
return null
|
|
228
|
-
}
|
|
229
|
-
}
|
package/src/MessageContainer.tsx
DELETED
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
import React, { RefObject } from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
FlatList,
|
|
6
|
-
View,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
TouchableOpacity,
|
|
9
|
-
Text,
|
|
10
|
-
ListRenderItemInfo,
|
|
11
|
-
NativeSyntheticEvent,
|
|
12
|
-
NativeScrollEvent,
|
|
13
|
-
StyleProp,
|
|
14
|
-
ViewStyle,
|
|
15
|
-
Platform,
|
|
16
|
-
} from 'react-native'
|
|
17
|
-
|
|
18
|
-
import { LoadEarlier, LoadEarlierProps } from './LoadEarlier'
|
|
19
|
-
import Message from './Message'
|
|
20
|
-
import Color from './Color'
|
|
21
|
-
import { User, IMessage, Reply } from './Models'
|
|
22
|
-
import TypingIndicator from './TypingIndicator'
|
|
23
|
-
|
|
24
|
-
import { StylePropType } from './utils'
|
|
25
|
-
import { warning } from './logging'
|
|
26
|
-
|
|
27
|
-
const styles = StyleSheet.create({
|
|
28
|
-
container: {
|
|
29
|
-
flex: 1,
|
|
30
|
-
},
|
|
31
|
-
containerAlignTop: {
|
|
32
|
-
flexDirection: 'row',
|
|
33
|
-
alignItems: 'flex-start',
|
|
34
|
-
},
|
|
35
|
-
contentContainerStyle: {
|
|
36
|
-
flexGrow: 1,
|
|
37
|
-
justifyContent: 'flex-start',
|
|
38
|
-
},
|
|
39
|
-
emptyChatContainer: {
|
|
40
|
-
flex: 1,
|
|
41
|
-
transform: [{ scaleY: -1 }],
|
|
42
|
-
},
|
|
43
|
-
headerWrapper: {
|
|
44
|
-
flex: 1,
|
|
45
|
-
},
|
|
46
|
-
listStyle: {
|
|
47
|
-
flex: 1,
|
|
48
|
-
},
|
|
49
|
-
scrollToBottomStyle: {
|
|
50
|
-
opacity: 0.8,
|
|
51
|
-
position: 'absolute',
|
|
52
|
-
right: 10,
|
|
53
|
-
bottom: 30,
|
|
54
|
-
zIndex: 999,
|
|
55
|
-
height: 40,
|
|
56
|
-
width: 40,
|
|
57
|
-
borderRadius: 20,
|
|
58
|
-
backgroundColor: Color.white,
|
|
59
|
-
alignItems: 'center',
|
|
60
|
-
justifyContent: 'center',
|
|
61
|
-
shadowColor: Color.black,
|
|
62
|
-
shadowOpacity: 0.5,
|
|
63
|
-
shadowOffset: { width: 0, height: 0 },
|
|
64
|
-
shadowRadius: 1,
|
|
65
|
-
},
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
export interface MessageContainerProps<TMessage extends IMessage> {
|
|
69
|
-
messages?: TMessage[]
|
|
70
|
-
isTyping?: boolean
|
|
71
|
-
user?: User
|
|
72
|
-
listViewProps: object
|
|
73
|
-
inverted?: boolean
|
|
74
|
-
loadEarlier?: boolean
|
|
75
|
-
alignTop?: boolean
|
|
76
|
-
scrollToBottom?: boolean
|
|
77
|
-
scrollToBottomStyle?: StyleProp<ViewStyle>
|
|
78
|
-
invertibleScrollViewProps?: object
|
|
79
|
-
extraData?: object
|
|
80
|
-
scrollToBottomOffset?: number
|
|
81
|
-
forwardRef?: RefObject<FlatList<TMessage>>
|
|
82
|
-
renderChatEmpty?(): React.ReactNode
|
|
83
|
-
renderFooter?(props: MessageContainerProps<TMessage>): React.ReactNode
|
|
84
|
-
renderMessage?(props: Message['props']): React.ReactElement
|
|
85
|
-
renderLoadEarlier?(props: LoadEarlierProps): React.ReactNode
|
|
86
|
-
scrollToBottomComponent?(): React.ReactNode
|
|
87
|
-
onLoadEarlier?(): void
|
|
88
|
-
onQuickReply?(replies: Reply[]): void
|
|
89
|
-
infiniteScroll?: boolean
|
|
90
|
-
isLoadingEarlier?: boolean
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
interface State {
|
|
94
|
-
showScrollBottom: boolean
|
|
95
|
-
hasScrolled: boolean
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export default class MessageContainer<
|
|
99
|
-
TMessage extends IMessage = IMessage,
|
|
100
|
-
> extends React.PureComponent<MessageContainerProps<TMessage>, State> {
|
|
101
|
-
static defaultProps = {
|
|
102
|
-
messages: [],
|
|
103
|
-
user: {},
|
|
104
|
-
isTyping: false,
|
|
105
|
-
renderChatEmpty: null,
|
|
106
|
-
renderFooter: null,
|
|
107
|
-
renderMessage: null,
|
|
108
|
-
onLoadEarlier: () => {},
|
|
109
|
-
onQuickReply: () => {},
|
|
110
|
-
inverted: true,
|
|
111
|
-
loadEarlier: false,
|
|
112
|
-
listViewProps: {},
|
|
113
|
-
invertibleScrollViewProps: {},
|
|
114
|
-
extraData: null,
|
|
115
|
-
scrollToBottom: false,
|
|
116
|
-
scrollToBottomOffset: 200,
|
|
117
|
-
alignTop: false,
|
|
118
|
-
scrollToBottomStyle: {},
|
|
119
|
-
infiniteScroll: false,
|
|
120
|
-
isLoadingEarlier: false,
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
static propTypes = {
|
|
124
|
-
messages: PropTypes.arrayOf(PropTypes.object),
|
|
125
|
-
isTyping: PropTypes.bool,
|
|
126
|
-
user: PropTypes.object,
|
|
127
|
-
renderChatEmpty: PropTypes.func,
|
|
128
|
-
renderFooter: PropTypes.func,
|
|
129
|
-
renderMessage: PropTypes.func,
|
|
130
|
-
renderLoadEarlier: PropTypes.func,
|
|
131
|
-
onLoadEarlier: PropTypes.func,
|
|
132
|
-
listViewProps: PropTypes.object,
|
|
133
|
-
inverted: PropTypes.bool,
|
|
134
|
-
loadEarlier: PropTypes.bool,
|
|
135
|
-
invertibleScrollViewProps: PropTypes.object,
|
|
136
|
-
extraData: PropTypes.object,
|
|
137
|
-
scrollToBottom: PropTypes.bool,
|
|
138
|
-
scrollToBottomOffset: PropTypes.number,
|
|
139
|
-
scrollToBottomComponent: PropTypes.func,
|
|
140
|
-
alignTop: PropTypes.bool,
|
|
141
|
-
scrollToBottomStyle: StylePropType,
|
|
142
|
-
infiniteScroll: PropTypes.bool,
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
state = {
|
|
146
|
-
showScrollBottom: false,
|
|
147
|
-
hasScrolled: false,
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
renderTypingIndicator = () => {
|
|
151
|
-
return <TypingIndicator isTyping={this.props.isTyping || false} />
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
renderFooter = () => {
|
|
155
|
-
if (this.props.renderFooter)
|
|
156
|
-
return this.props.renderFooter(this.props)
|
|
157
|
-
|
|
158
|
-
return this.renderTypingIndicator()
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
renderLoadEarlier = () => {
|
|
162
|
-
if (this.props.loadEarlier === true) {
|
|
163
|
-
const loadEarlierProps = {
|
|
164
|
-
...this.props,
|
|
165
|
-
}
|
|
166
|
-
if (this.props.renderLoadEarlier)
|
|
167
|
-
return this.props.renderLoadEarlier(loadEarlierProps)
|
|
168
|
-
|
|
169
|
-
return <LoadEarlier {...loadEarlierProps} />
|
|
170
|
-
}
|
|
171
|
-
return null
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
scrollTo (options: { animated?: boolean, offset: number }) {
|
|
175
|
-
if (this.props.forwardRef?.current && options)
|
|
176
|
-
this.props.forwardRef.current.scrollToOffset(options)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
scrollToBottom = (animated: boolean = true) => {
|
|
180
|
-
const { inverted } = this.props
|
|
181
|
-
if (inverted)
|
|
182
|
-
this.scrollTo({ offset: 0, animated })
|
|
183
|
-
else if (this.props.forwardRef?.current)
|
|
184
|
-
this.props.forwardRef.current.scrollToEnd({ animated })
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
handleOnScroll = (event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
188
|
-
const {
|
|
189
|
-
nativeEvent: {
|
|
190
|
-
contentOffset: { y: contentOffsetY },
|
|
191
|
-
contentSize: { height: contentSizeHeight },
|
|
192
|
-
layoutMeasurement: { height: layoutMeasurementHeight },
|
|
193
|
-
},
|
|
194
|
-
} = event
|
|
195
|
-
const { scrollToBottomOffset } = this.props
|
|
196
|
-
if (this.props.inverted)
|
|
197
|
-
if (contentOffsetY > scrollToBottomOffset!)
|
|
198
|
-
this.setState({ showScrollBottom: true, hasScrolled: true })
|
|
199
|
-
else
|
|
200
|
-
this.setState({ showScrollBottom: false, hasScrolled: true })
|
|
201
|
-
else if (
|
|
202
|
-
contentOffsetY < scrollToBottomOffset! &&
|
|
203
|
-
contentSizeHeight - layoutMeasurementHeight > scrollToBottomOffset!
|
|
204
|
-
)
|
|
205
|
-
this.setState({ showScrollBottom: true, hasScrolled: true })
|
|
206
|
-
else
|
|
207
|
-
this.setState({ showScrollBottom: false, hasScrolled: true })
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
renderRow = ({ item, index }: ListRenderItemInfo<TMessage>): React.ReactElement | null => {
|
|
211
|
-
if (!item._id && item._id !== 0)
|
|
212
|
-
warning('GiftedChat: `_id` is missing for message', JSON.stringify(item))
|
|
213
|
-
|
|
214
|
-
if (!item.user) {
|
|
215
|
-
if (!item.system)
|
|
216
|
-
warning(
|
|
217
|
-
'GiftedChat: `user` is missing for message',
|
|
218
|
-
JSON.stringify(item)
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
item.user = { _id: 0 }
|
|
222
|
-
}
|
|
223
|
-
const { messages, user, inverted, ...restProps } = this.props
|
|
224
|
-
if (messages && user) {
|
|
225
|
-
const previousMessage =
|
|
226
|
-
(inverted ? messages[index + 1] : messages[index - 1]) || {}
|
|
227
|
-
const nextMessage =
|
|
228
|
-
(inverted ? messages[index - 1] : messages[index + 1]) || {}
|
|
229
|
-
|
|
230
|
-
const messageProps: Message['props'] = {
|
|
231
|
-
...restProps,
|
|
232
|
-
user,
|
|
233
|
-
currentMessage: item,
|
|
234
|
-
previousMessage,
|
|
235
|
-
inverted,
|
|
236
|
-
nextMessage,
|
|
237
|
-
position: item.user._id === user._id ? 'right' : 'left',
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (this.props.renderMessage)
|
|
241
|
-
return this.props.renderMessage(messageProps)
|
|
242
|
-
|
|
243
|
-
return <Message key={item._id.toString()} {...messageProps} />
|
|
244
|
-
}
|
|
245
|
-
return null
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
renderChatEmpty = () => {
|
|
249
|
-
if (this.props.renderChatEmpty)
|
|
250
|
-
return this.props.inverted
|
|
251
|
-
? (
|
|
252
|
-
this.props.renderChatEmpty()
|
|
253
|
-
)
|
|
254
|
-
: (
|
|
255
|
-
<View style={styles.emptyChatContainer}>
|
|
256
|
-
{this.props.renderChatEmpty()}
|
|
257
|
-
</View>
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
return <View style={styles.container} />
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
renderHeaderWrapper = () => (
|
|
264
|
-
<View style={styles.headerWrapper}>{this.renderLoadEarlier()}</View>
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
renderScrollBottomComponent () {
|
|
268
|
-
const { scrollToBottomComponent } = this.props
|
|
269
|
-
|
|
270
|
-
if (scrollToBottomComponent)
|
|
271
|
-
return scrollToBottomComponent()
|
|
272
|
-
|
|
273
|
-
return <Text>{'V'}</Text>
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
renderScrollToBottomWrapper () {
|
|
277
|
-
const propsStyle = this.props.scrollToBottomStyle || {}
|
|
278
|
-
return (
|
|
279
|
-
<View style={[styles.scrollToBottomStyle, propsStyle]}>
|
|
280
|
-
<TouchableOpacity
|
|
281
|
-
onPress={() => this.scrollToBottom()}
|
|
282
|
-
hitSlop={{ top: 5, left: 5, right: 5, bottom: 5 }}
|
|
283
|
-
>
|
|
284
|
-
{this.renderScrollBottomComponent()}
|
|
285
|
-
</TouchableOpacity>
|
|
286
|
-
</View>
|
|
287
|
-
)
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
onLayoutList = () => {
|
|
291
|
-
if (
|
|
292
|
-
!this.props.inverted &&
|
|
293
|
-
!!this.props.messages &&
|
|
294
|
-
this.props.messages!.length
|
|
295
|
-
)
|
|
296
|
-
setTimeout(
|
|
297
|
-
() => this.scrollToBottom && this.scrollToBottom(false),
|
|
298
|
-
15 * this.props.messages!.length
|
|
299
|
-
)
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
onEndReached = ({ distanceFromEnd }: { distanceFromEnd: number }) => {
|
|
303
|
-
const { loadEarlier, onLoadEarlier, infiniteScroll, isLoadingEarlier } =
|
|
304
|
-
this.props
|
|
305
|
-
if (
|
|
306
|
-
infiniteScroll &&
|
|
307
|
-
(this.state.hasScrolled || distanceFromEnd > 0) &&
|
|
308
|
-
distanceFromEnd <= 100 &&
|
|
309
|
-
loadEarlier &&
|
|
310
|
-
onLoadEarlier &&
|
|
311
|
-
!isLoadingEarlier &&
|
|
312
|
-
Platform.OS !== 'web'
|
|
313
|
-
)
|
|
314
|
-
onLoadEarlier()
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
keyExtractor = (item: TMessage) => `${item._id}`
|
|
318
|
-
|
|
319
|
-
render () {
|
|
320
|
-
const { inverted } = this.props
|
|
321
|
-
|
|
322
|
-
return (
|
|
323
|
-
<View
|
|
324
|
-
style={
|
|
325
|
-
this.props.alignTop ? styles.containerAlignTop : styles.container
|
|
326
|
-
}
|
|
327
|
-
>
|
|
328
|
-
<FlatList
|
|
329
|
-
ref={this.props.forwardRef}
|
|
330
|
-
extraData={[this.props.extraData, this.props.isTyping]}
|
|
331
|
-
keyExtractor={this.keyExtractor}
|
|
332
|
-
automaticallyAdjustContentInsets={false}
|
|
333
|
-
inverted={inverted}
|
|
334
|
-
data={this.props.messages}
|
|
335
|
-
style={styles.listStyle}
|
|
336
|
-
contentContainerStyle={styles.contentContainerStyle}
|
|
337
|
-
renderItem={this.renderRow}
|
|
338
|
-
{...this.props.invertibleScrollViewProps}
|
|
339
|
-
ListEmptyComponent={this.renderChatEmpty}
|
|
340
|
-
ListFooterComponent={
|
|
341
|
-
inverted ? this.renderHeaderWrapper : this.renderFooter
|
|
342
|
-
}
|
|
343
|
-
ListHeaderComponent={
|
|
344
|
-
inverted ? this.renderFooter : this.renderHeaderWrapper
|
|
345
|
-
}
|
|
346
|
-
onScroll={this.handleOnScroll}
|
|
347
|
-
scrollEventThrottle={100}
|
|
348
|
-
onLayout={this.onLayoutList}
|
|
349
|
-
onEndReached={this.onEndReached}
|
|
350
|
-
onEndReachedThreshold={0.1}
|
|
351
|
-
{...this.props.listViewProps}
|
|
352
|
-
/>
|
|
353
|
-
{this.state.showScrollBottom && this.props.scrollToBottom
|
|
354
|
-
? this.renderScrollToBottomWrapper()
|
|
355
|
-
: null}
|
|
356
|
-
</View>
|
|
357
|
-
)
|
|
358
|
-
}
|
|
359
|
-
}
|