react-native-gifted-chat 2.6.5 → 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 +7 -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} +47 -52
- 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} +27 -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 +21 -29
- package/src/Actions.tsx +3 -15
- package/src/Avatar.tsx +43 -52
- package/src/{Bubble.tsx → Bubble/index.tsx} +52 -269
- 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 +1 -24
- 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/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 -105
- 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 -689
- package/src/Message.tsx +0 -229
- package/src/MessageContainer.tsx +0 -361
|
@@ -1,258 +1,32 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
1
|
import React from 'react'
|
|
3
2
|
import {
|
|
4
3
|
Text,
|
|
5
|
-
StyleSheet,
|
|
6
4
|
TouchableWithoutFeedback,
|
|
7
5
|
View,
|
|
8
|
-
StyleProp,
|
|
9
|
-
ViewStyle,
|
|
10
|
-
TextStyle,
|
|
11
6
|
} from 'react-native'
|
|
12
7
|
|
|
13
|
-
import { GiftedChatContext } from '
|
|
14
|
-
import { QuickReplies
|
|
15
|
-
import { MessageText
|
|
16
|
-
import { MessageImage
|
|
17
|
-
import { MessageVideo } from '
|
|
18
|
-
import { MessageAudio } from '
|
|
19
|
-
import { Time
|
|
8
|
+
import { GiftedChatContext } from '../GiftedChatContext'
|
|
9
|
+
import { QuickReplies } from '../QuickReplies'
|
|
10
|
+
import { MessageText } from '../MessageText'
|
|
11
|
+
import { MessageImage } from '../MessageImage'
|
|
12
|
+
import { MessageVideo } from '../MessageVideo'
|
|
13
|
+
import { MessageAudio } from '../MessageAudio'
|
|
14
|
+
import { Time } from '../Time'
|
|
20
15
|
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
User,
|
|
25
|
-
IMessage,
|
|
26
|
-
LeftRightStyle,
|
|
27
|
-
Reply,
|
|
28
|
-
Omit,
|
|
29
|
-
MessageVideoProps,
|
|
30
|
-
MessageAudioProps,
|
|
31
|
-
} from './Models'
|
|
32
|
-
|
|
33
|
-
const styles = {
|
|
34
|
-
left: StyleSheet.create({
|
|
35
|
-
container: {
|
|
36
|
-
flex: 1,
|
|
37
|
-
alignItems: 'flex-start',
|
|
38
|
-
},
|
|
39
|
-
wrapper: {
|
|
40
|
-
borderRadius: 15,
|
|
41
|
-
backgroundColor: Color.leftBubbleBackground,
|
|
42
|
-
marginRight: 60,
|
|
43
|
-
minHeight: 20,
|
|
44
|
-
justifyContent: 'flex-end',
|
|
45
|
-
},
|
|
46
|
-
containerToNext: {
|
|
47
|
-
borderBottomLeftRadius: 3,
|
|
48
|
-
},
|
|
49
|
-
containerToPrevious: {
|
|
50
|
-
borderTopLeftRadius: 3,
|
|
51
|
-
},
|
|
52
|
-
bottom: {
|
|
53
|
-
flexDirection: 'row',
|
|
54
|
-
justifyContent: 'flex-start',
|
|
55
|
-
},
|
|
56
|
-
}),
|
|
57
|
-
right: StyleSheet.create({
|
|
58
|
-
container: {
|
|
59
|
-
flex: 1,
|
|
60
|
-
alignItems: 'flex-end',
|
|
61
|
-
},
|
|
62
|
-
wrapper: {
|
|
63
|
-
borderRadius: 15,
|
|
64
|
-
backgroundColor: Color.defaultBlue,
|
|
65
|
-
marginLeft: 60,
|
|
66
|
-
minHeight: 20,
|
|
67
|
-
justifyContent: 'flex-end',
|
|
68
|
-
},
|
|
69
|
-
containerToNext: {
|
|
70
|
-
borderBottomRightRadius: 3,
|
|
71
|
-
},
|
|
72
|
-
containerToPrevious: {
|
|
73
|
-
borderTopRightRadius: 3,
|
|
74
|
-
},
|
|
75
|
-
bottom: {
|
|
76
|
-
flexDirection: 'row',
|
|
77
|
-
justifyContent: 'flex-end',
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
content: StyleSheet.create({
|
|
81
|
-
tick: {
|
|
82
|
-
fontSize: 10,
|
|
83
|
-
backgroundColor: Color.backgroundTransparent,
|
|
84
|
-
color: Color.white,
|
|
85
|
-
},
|
|
86
|
-
tickView: {
|
|
87
|
-
flexDirection: 'row',
|
|
88
|
-
marginRight: 10,
|
|
89
|
-
},
|
|
90
|
-
username: {
|
|
91
|
-
top: -3,
|
|
92
|
-
left: 0,
|
|
93
|
-
fontSize: 12,
|
|
94
|
-
backgroundColor: 'transparent',
|
|
95
|
-
color: '#aaa',
|
|
96
|
-
},
|
|
97
|
-
usernameView: {
|
|
98
|
-
flexDirection: 'row',
|
|
99
|
-
marginHorizontal: 10,
|
|
100
|
-
},
|
|
101
|
-
}),
|
|
102
|
-
}
|
|
16
|
+
import { isSameUser, isSameDay } from '../utils'
|
|
17
|
+
import { IMessage } from '../types'
|
|
18
|
+
import { BubbleProps } from './types'
|
|
103
19
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
> &
|
|
109
|
-
MessageImageProps<TMessage>
|
|
110
|
-
|
|
111
|
-
export type RenderMessageVideoProps<TMessage extends IMessage> = Omit<
|
|
112
|
-
BubbleProps<TMessage>,
|
|
113
|
-
'containerStyle' | 'wrapperStyle'
|
|
114
|
-
> &
|
|
115
|
-
MessageVideoProps<TMessage>
|
|
116
|
-
|
|
117
|
-
export type RenderMessageAudioProps<TMessage extends IMessage> = Omit<
|
|
118
|
-
BubbleProps<TMessage>,
|
|
119
|
-
'containerStyle' | 'wrapperStyle'
|
|
120
|
-
> &
|
|
121
|
-
MessageAudioProps<TMessage>
|
|
122
|
-
|
|
123
|
-
export type RenderMessageTextProps<TMessage extends IMessage> = Omit<
|
|
124
|
-
BubbleProps<TMessage>,
|
|
125
|
-
'containerStyle' | 'wrapperStyle'
|
|
126
|
-
> &
|
|
127
|
-
MessageTextProps<TMessage>
|
|
128
|
-
/* eslint-enable no-use-before-define */
|
|
129
|
-
|
|
130
|
-
export interface BubbleProps<TMessage extends IMessage> {
|
|
131
|
-
user?: User
|
|
132
|
-
touchableProps?: object
|
|
133
|
-
renderUsernameOnMessage?: boolean
|
|
134
|
-
isCustomViewBottom?: boolean
|
|
135
|
-
inverted?: boolean
|
|
136
|
-
position: 'left' | 'right'
|
|
137
|
-
currentMessage: TMessage
|
|
138
|
-
nextMessage?: TMessage
|
|
139
|
-
previousMessage?: TMessage
|
|
140
|
-
optionTitles?: string[]
|
|
141
|
-
containerStyle?: LeftRightStyle<ViewStyle>
|
|
142
|
-
wrapperStyle?: LeftRightStyle<ViewStyle>
|
|
143
|
-
textStyle?: LeftRightStyle<TextStyle>
|
|
144
|
-
bottomContainerStyle?: LeftRightStyle<ViewStyle>
|
|
145
|
-
tickStyle?: StyleProp<TextStyle>
|
|
146
|
-
containerToNextStyle?: LeftRightStyle<ViewStyle>
|
|
147
|
-
containerToPreviousStyle?: LeftRightStyle<ViewStyle>
|
|
148
|
-
usernameStyle?: TextStyle
|
|
149
|
-
quickReplyStyle?: StyleProp<ViewStyle>
|
|
150
|
-
quickReplyTextStyle?: StyleProp<TextStyle>
|
|
151
|
-
quickReplyContainerStyle?: StyleProp<ViewStyle>
|
|
152
|
-
onPress?(context?: unknown, message?: unknown): void
|
|
153
|
-
onLongPress?(context?: unknown, message?: unknown): void
|
|
154
|
-
onQuickReply?(replies: Reply[]): void
|
|
155
|
-
renderMessageImage?(
|
|
156
|
-
props: RenderMessageImageProps<TMessage>,
|
|
157
|
-
): React.ReactNode
|
|
158
|
-
renderMessageVideo?(
|
|
159
|
-
props: RenderMessageVideoProps<TMessage>,
|
|
160
|
-
): React.ReactNode
|
|
161
|
-
renderMessageAudio?(
|
|
162
|
-
props: RenderMessageAudioProps<TMessage>,
|
|
163
|
-
): React.ReactNode
|
|
164
|
-
renderMessageText?(props: RenderMessageTextProps<TMessage>): React.ReactNode
|
|
165
|
-
renderCustomView?(bubbleProps: BubbleProps<TMessage>): React.ReactNode
|
|
166
|
-
renderTime?(timeProps: TimeProps<TMessage>): React.ReactNode
|
|
167
|
-
renderTicks?(currentMessage: TMessage): React.ReactNode
|
|
168
|
-
renderUsername?(user?: TMessage['user']): React.ReactNode
|
|
169
|
-
renderQuickReplySend?(): React.ReactNode
|
|
170
|
-
renderQuickReplies?(
|
|
171
|
-
quickReplies: QuickRepliesProps<TMessage>,
|
|
172
|
-
): React.ReactNode
|
|
173
|
-
}
|
|
20
|
+
import stylesCommon from '../styles'
|
|
21
|
+
import styles from './styles'
|
|
22
|
+
|
|
23
|
+
export * from './types'
|
|
174
24
|
|
|
175
25
|
export default class Bubble<
|
|
176
26
|
TMessage extends IMessage = IMessage,
|
|
177
27
|
> extends React.Component<BubbleProps<TMessage>> {
|
|
178
28
|
static contextType = GiftedChatContext
|
|
179
29
|
|
|
180
|
-
static defaultProps = {
|
|
181
|
-
touchableProps: {},
|
|
182
|
-
onPress: null,
|
|
183
|
-
onLongPress: null,
|
|
184
|
-
renderMessageImage: null,
|
|
185
|
-
renderMessageVideo: null,
|
|
186
|
-
renderMessageAudio: null,
|
|
187
|
-
renderMessageText: null,
|
|
188
|
-
renderCustomView: null,
|
|
189
|
-
renderUsername: null,
|
|
190
|
-
renderTicks: null,
|
|
191
|
-
renderTime: null,
|
|
192
|
-
renderQuickReplies: null,
|
|
193
|
-
onQuickReply: null,
|
|
194
|
-
position: 'left',
|
|
195
|
-
currentMessage: {
|
|
196
|
-
text: null,
|
|
197
|
-
createdAt: null,
|
|
198
|
-
image: null,
|
|
199
|
-
},
|
|
200
|
-
nextMessage: {},
|
|
201
|
-
previousMessage: {},
|
|
202
|
-
containerStyle: {},
|
|
203
|
-
wrapperStyle: {},
|
|
204
|
-
bottomContainerStyle: {},
|
|
205
|
-
tickStyle: {},
|
|
206
|
-
usernameStyle: {},
|
|
207
|
-
containerToNextStyle: {},
|
|
208
|
-
containerToPreviousStyle: {},
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
static propTypes = {
|
|
212
|
-
user: PropTypes.object.isRequired,
|
|
213
|
-
touchableProps: PropTypes.object,
|
|
214
|
-
onLongPress: PropTypes.func,
|
|
215
|
-
renderMessageImage: PropTypes.func,
|
|
216
|
-
renderMessageVideo: PropTypes.func,
|
|
217
|
-
renderMessageAudio: PropTypes.func,
|
|
218
|
-
renderMessageText: PropTypes.func,
|
|
219
|
-
renderCustomView: PropTypes.func,
|
|
220
|
-
isCustomViewBottom: PropTypes.bool,
|
|
221
|
-
renderUsernameOnMessage: PropTypes.bool,
|
|
222
|
-
renderUsername: PropTypes.func,
|
|
223
|
-
renderTime: PropTypes.func,
|
|
224
|
-
renderTicks: PropTypes.func,
|
|
225
|
-
renderQuickReplies: PropTypes.func,
|
|
226
|
-
onQuickReply: PropTypes.func,
|
|
227
|
-
position: PropTypes.oneOf(['left', 'right']),
|
|
228
|
-
optionTitles: PropTypes.arrayOf(PropTypes.string),
|
|
229
|
-
currentMessage: PropTypes.object,
|
|
230
|
-
nextMessage: PropTypes.object,
|
|
231
|
-
previousMessage: PropTypes.object,
|
|
232
|
-
containerStyle: PropTypes.shape({
|
|
233
|
-
left: StylePropType,
|
|
234
|
-
right: StylePropType,
|
|
235
|
-
}),
|
|
236
|
-
wrapperStyle: PropTypes.shape({
|
|
237
|
-
left: StylePropType,
|
|
238
|
-
right: StylePropType,
|
|
239
|
-
}),
|
|
240
|
-
bottomContainerStyle: PropTypes.shape({
|
|
241
|
-
left: StylePropType,
|
|
242
|
-
right: StylePropType,
|
|
243
|
-
}),
|
|
244
|
-
tickStyle: StylePropType,
|
|
245
|
-
usernameStyle: StylePropType,
|
|
246
|
-
containerToNextStyle: PropTypes.shape({
|
|
247
|
-
left: StylePropType,
|
|
248
|
-
right: StylePropType,
|
|
249
|
-
}),
|
|
250
|
-
containerToPreviousStyle: PropTypes.shape({
|
|
251
|
-
left: StylePropType,
|
|
252
|
-
right: StylePropType,
|
|
253
|
-
}),
|
|
254
|
-
}
|
|
255
|
-
|
|
256
30
|
onPress = () => {
|
|
257
31
|
if (this.props.onPress)
|
|
258
32
|
this.props.onPress(this.context, this.props.currentMessage)
|
|
@@ -338,7 +112,8 @@ export default class Bubble<
|
|
|
338
112
|
quickReplyTextStyle,
|
|
339
113
|
quickReplyContainerStyle,
|
|
340
114
|
} = this.props
|
|
341
|
-
|
|
115
|
+
|
|
116
|
+
if (currentMessage?.quickReplies) {
|
|
342
117
|
const {
|
|
343
118
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
344
119
|
containerStyle,
|
|
@@ -362,11 +137,12 @@ export default class Bubble<
|
|
|
362
137
|
/>
|
|
363
138
|
)
|
|
364
139
|
}
|
|
140
|
+
|
|
365
141
|
return null
|
|
366
142
|
}
|
|
367
143
|
|
|
368
144
|
renderMessageText () {
|
|
369
|
-
if (this.props.currentMessage
|
|
145
|
+
if (this.props.currentMessage?.text) {
|
|
370
146
|
const {
|
|
371
147
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
372
148
|
containerStyle,
|
|
@@ -384,7 +160,7 @@ export default class Bubble<
|
|
|
384
160
|
}
|
|
385
161
|
|
|
386
162
|
renderMessageImage () {
|
|
387
|
-
if (this.props.currentMessage
|
|
163
|
+
if (this.props.currentMessage?.image) {
|
|
388
164
|
const {
|
|
389
165
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
390
166
|
containerStyle,
|
|
@@ -438,14 +214,18 @@ export default class Bubble<
|
|
|
438
214
|
}
|
|
439
215
|
|
|
440
216
|
renderTicks () {
|
|
441
|
-
const {
|
|
217
|
+
const {
|
|
218
|
+
currentMessage,
|
|
219
|
+
renderTicks,
|
|
220
|
+
user,
|
|
221
|
+
} = this.props
|
|
222
|
+
|
|
442
223
|
if (renderTicks && currentMessage)
|
|
443
224
|
return renderTicks(currentMessage)
|
|
444
225
|
|
|
445
226
|
if (
|
|
446
|
-
currentMessage &&
|
|
447
227
|
user &&
|
|
448
|
-
currentMessage
|
|
228
|
+
currentMessage?.user &&
|
|
449
229
|
currentMessage.user._id !== user._id
|
|
450
230
|
)
|
|
451
231
|
return null
|
|
@@ -478,7 +258,7 @@ export default class Bubble<
|
|
|
478
258
|
}
|
|
479
259
|
|
|
480
260
|
renderTime () {
|
|
481
|
-
if (this.props.currentMessage
|
|
261
|
+
if (this.props.currentMessage?.createdAt) {
|
|
482
262
|
const {
|
|
483
263
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
484
264
|
containerStyle,
|
|
@@ -497,7 +277,12 @@ export default class Bubble<
|
|
|
497
277
|
}
|
|
498
278
|
|
|
499
279
|
renderUsername () {
|
|
500
|
-
const {
|
|
280
|
+
const {
|
|
281
|
+
currentMessage,
|
|
282
|
+
user,
|
|
283
|
+
renderUsername,
|
|
284
|
+
} = this.props
|
|
285
|
+
|
|
501
286
|
if (this.props.renderUsernameOnMessage && currentMessage) {
|
|
502
287
|
if (user && currentMessage.user._id === user._id)
|
|
503
288
|
return null
|
|
@@ -518,6 +303,7 @@ export default class Bubble<
|
|
|
518
303
|
</View>
|
|
519
304
|
)
|
|
520
305
|
}
|
|
306
|
+
|
|
521
307
|
return null
|
|
522
308
|
}
|
|
523
309
|
|
|
@@ -529,33 +315,30 @@ export default class Bubble<
|
|
|
529
315
|
}
|
|
530
316
|
|
|
531
317
|
renderBubbleContent () {
|
|
532
|
-
return
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
: (
|
|
543
|
-
<View>
|
|
544
|
-
{this.renderCustomView()}
|
|
545
|
-
{this.renderMessageImage()}
|
|
546
|
-
{this.renderMessageVideo()}
|
|
547
|
-
{this.renderMessageAudio()}
|
|
548
|
-
{this.renderMessageText()}
|
|
549
|
-
</View>
|
|
550
|
-
)
|
|
318
|
+
return (
|
|
319
|
+
<View>
|
|
320
|
+
{!this.props.isCustomViewBottom && this.renderCustomView()}
|
|
321
|
+
{this.renderMessageImage()}
|
|
322
|
+
{this.renderMessageVideo()}
|
|
323
|
+
{this.renderMessageAudio()}
|
|
324
|
+
{this.renderMessageText()}
|
|
325
|
+
{this.props.isCustomViewBottom && this.renderCustomView()}
|
|
326
|
+
</View>
|
|
327
|
+
)
|
|
551
328
|
}
|
|
552
329
|
|
|
553
330
|
render () {
|
|
554
|
-
const {
|
|
555
|
-
|
|
331
|
+
const {
|
|
332
|
+
position,
|
|
333
|
+
containerStyle,
|
|
334
|
+
wrapperStyle,
|
|
335
|
+
bottomContainerStyle,
|
|
336
|
+
} = this.props
|
|
337
|
+
|
|
556
338
|
return (
|
|
557
339
|
<View
|
|
558
340
|
style={[
|
|
341
|
+
stylesCommon.fill,
|
|
559
342
|
styles[position].container,
|
|
560
343
|
containerStyle && containerStyle[position],
|
|
561
344
|
]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native'
|
|
2
|
+
import Color from '../Color'
|
|
3
|
+
|
|
4
|
+
const styles = {
|
|
5
|
+
left: StyleSheet.create({
|
|
6
|
+
container: {
|
|
7
|
+
alignItems: 'flex-start',
|
|
8
|
+
},
|
|
9
|
+
wrapper: {
|
|
10
|
+
borderRadius: 15,
|
|
11
|
+
backgroundColor: Color.leftBubbleBackground,
|
|
12
|
+
marginRight: 60,
|
|
13
|
+
minHeight: 20,
|
|
14
|
+
justifyContent: 'flex-end',
|
|
15
|
+
},
|
|
16
|
+
containerToNext: {
|
|
17
|
+
borderBottomLeftRadius: 3,
|
|
18
|
+
},
|
|
19
|
+
containerToPrevious: {
|
|
20
|
+
borderTopLeftRadius: 3,
|
|
21
|
+
},
|
|
22
|
+
bottom: {
|
|
23
|
+
flexDirection: 'row',
|
|
24
|
+
justifyContent: 'flex-start',
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
right: StyleSheet.create({
|
|
28
|
+
container: {
|
|
29
|
+
alignItems: 'flex-end',
|
|
30
|
+
},
|
|
31
|
+
wrapper: {
|
|
32
|
+
borderRadius: 15,
|
|
33
|
+
backgroundColor: Color.defaultBlue,
|
|
34
|
+
marginLeft: 60,
|
|
35
|
+
minHeight: 20,
|
|
36
|
+
justifyContent: 'flex-end',
|
|
37
|
+
},
|
|
38
|
+
containerToNext: {
|
|
39
|
+
borderBottomRightRadius: 3,
|
|
40
|
+
},
|
|
41
|
+
containerToPrevious: {
|
|
42
|
+
borderTopRightRadius: 3,
|
|
43
|
+
},
|
|
44
|
+
bottom: {
|
|
45
|
+
flexDirection: 'row',
|
|
46
|
+
justifyContent: 'flex-end',
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
content: StyleSheet.create({
|
|
50
|
+
tick: {
|
|
51
|
+
fontSize: 10,
|
|
52
|
+
backgroundColor: Color.backgroundTransparent,
|
|
53
|
+
color: Color.white,
|
|
54
|
+
},
|
|
55
|
+
tickView: {
|
|
56
|
+
flexDirection: 'row',
|
|
57
|
+
marginRight: 10,
|
|
58
|
+
},
|
|
59
|
+
username: {
|
|
60
|
+
top: -3,
|
|
61
|
+
left: 0,
|
|
62
|
+
fontSize: 12,
|
|
63
|
+
backgroundColor: Color.backgroundTransparent,
|
|
64
|
+
color: '#aaa',
|
|
65
|
+
},
|
|
66
|
+
usernameView: {
|
|
67
|
+
flexDirection: 'row',
|
|
68
|
+
marginHorizontal: 10,
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default styles
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
StyleProp,
|
|
4
|
+
ViewStyle,
|
|
5
|
+
TextStyle,
|
|
6
|
+
} from 'react-native'
|
|
7
|
+
import { QuickRepliesProps } from '../QuickReplies'
|
|
8
|
+
import { MessageTextProps } from '../MessageText'
|
|
9
|
+
import { MessageImageProps } from '../MessageImage'
|
|
10
|
+
import { TimeProps } from '../Time'
|
|
11
|
+
import {
|
|
12
|
+
User,
|
|
13
|
+
IMessage,
|
|
14
|
+
LeftRightStyle,
|
|
15
|
+
Reply,
|
|
16
|
+
Omit,
|
|
17
|
+
MessageVideoProps,
|
|
18
|
+
MessageAudioProps,
|
|
19
|
+
} from '../types'
|
|
20
|
+
|
|
21
|
+
/* eslint-disable no-use-before-define */
|
|
22
|
+
export type RenderMessageImageProps<TMessage extends IMessage> = Omit<
|
|
23
|
+
BubbleProps<TMessage>,
|
|
24
|
+
'containerStyle' | 'wrapperStyle'
|
|
25
|
+
> &
|
|
26
|
+
MessageImageProps<TMessage>
|
|
27
|
+
|
|
28
|
+
export type RenderMessageVideoProps<TMessage extends IMessage> = Omit<
|
|
29
|
+
BubbleProps<TMessage>,
|
|
30
|
+
'containerStyle' | 'wrapperStyle'
|
|
31
|
+
> &
|
|
32
|
+
MessageVideoProps<TMessage>
|
|
33
|
+
|
|
34
|
+
export type RenderMessageAudioProps<TMessage extends IMessage> = Omit<
|
|
35
|
+
BubbleProps<TMessage>,
|
|
36
|
+
'containerStyle' | 'wrapperStyle'
|
|
37
|
+
> &
|
|
38
|
+
MessageAudioProps<TMessage>
|
|
39
|
+
|
|
40
|
+
export type RenderMessageTextProps<TMessage extends IMessage> = Omit<
|
|
41
|
+
BubbleProps<TMessage>,
|
|
42
|
+
'containerStyle' | 'wrapperStyle'
|
|
43
|
+
> &
|
|
44
|
+
MessageTextProps<TMessage>
|
|
45
|
+
/* eslint-enable no-use-before-define */
|
|
46
|
+
|
|
47
|
+
export interface BubbleProps<TMessage extends IMessage> {
|
|
48
|
+
user?: User
|
|
49
|
+
touchableProps?: object
|
|
50
|
+
renderUsernameOnMessage?: boolean
|
|
51
|
+
isCustomViewBottom?: boolean
|
|
52
|
+
inverted?: boolean
|
|
53
|
+
position: 'left' | 'right'
|
|
54
|
+
currentMessage: TMessage
|
|
55
|
+
nextMessage?: TMessage
|
|
56
|
+
previousMessage?: TMessage
|
|
57
|
+
optionTitles?: string[]
|
|
58
|
+
containerStyle?: LeftRightStyle<ViewStyle>
|
|
59
|
+
wrapperStyle?: LeftRightStyle<ViewStyle>
|
|
60
|
+
textStyle?: LeftRightStyle<TextStyle>
|
|
61
|
+
bottomContainerStyle?: LeftRightStyle<ViewStyle>
|
|
62
|
+
tickStyle?: StyleProp<TextStyle>
|
|
63
|
+
containerToNextStyle?: LeftRightStyle<ViewStyle>
|
|
64
|
+
containerToPreviousStyle?: LeftRightStyle<ViewStyle>
|
|
65
|
+
usernameStyle?: TextStyle
|
|
66
|
+
quickReplyStyle?: StyleProp<ViewStyle>
|
|
67
|
+
quickReplyTextStyle?: StyleProp<TextStyle>
|
|
68
|
+
quickReplyContainerStyle?: StyleProp<ViewStyle>
|
|
69
|
+
onPress?(context?: unknown, message?: unknown): void
|
|
70
|
+
onLongPress?(context?: unknown, message?: unknown): void
|
|
71
|
+
onQuickReply?(replies: Reply[]): void
|
|
72
|
+
renderMessageImage?(
|
|
73
|
+
props: RenderMessageImageProps<TMessage>,
|
|
74
|
+
): React.ReactNode
|
|
75
|
+
renderMessageVideo?(
|
|
76
|
+
props: RenderMessageVideoProps<TMessage>,
|
|
77
|
+
): React.ReactNode
|
|
78
|
+
renderMessageAudio?(
|
|
79
|
+
props: RenderMessageAudioProps<TMessage>,
|
|
80
|
+
): React.ReactNode
|
|
81
|
+
renderMessageText?(props: RenderMessageTextProps<TMessage>): React.ReactNode
|
|
82
|
+
renderCustomView?(bubbleProps: BubbleProps<TMessage>): React.ReactNode
|
|
83
|
+
renderTime?(timeProps: TimeProps<TMessage>): React.ReactNode
|
|
84
|
+
renderTicks?(currentMessage: TMessage): React.ReactNode
|
|
85
|
+
renderUsername?(user?: TMessage['user']): React.ReactNode
|
|
86
|
+
renderQuickReplySend?(): React.ReactNode
|
|
87
|
+
renderQuickReplies?(
|
|
88
|
+
quickReplies: QuickRepliesProps<TMessage>,
|
|
89
|
+
): React.ReactNode
|
|
90
|
+
}
|
package/src/Composer.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useCallback, useRef } from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
2
|
import {
|
|
4
3
|
Platform,
|
|
5
4
|
StyleSheet,
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
} from 'react-native'
|
|
11
10
|
import { MIN_COMPOSER_HEIGHT, DEFAULT_PLACEHOLDER } from './Constant'
|
|
12
11
|
import Color from './Color'
|
|
13
|
-
import
|
|
12
|
+
import stylesCommon from './styles'
|
|
14
13
|
|
|
15
14
|
export interface ComposerProps {
|
|
16
15
|
composerHeight?: number
|
|
@@ -41,7 +40,7 @@ export function Composer ({
|
|
|
41
40
|
textInputProps,
|
|
42
41
|
textInputStyle,
|
|
43
42
|
}: ComposerProps): React.ReactElement {
|
|
44
|
-
const dimensionsRef = useRef<{ width: number, height: number }>()
|
|
43
|
+
const dimensionsRef = useRef<{ width: number, height: number }>(null)
|
|
45
44
|
|
|
46
45
|
const determineInputSizeChange = useCallback(
|
|
47
46
|
(dimensions: { width: number, height: number }) => {
|
|
@@ -82,6 +81,7 @@ export function Composer ({
|
|
|
82
81
|
onContentSizeChange={handleContentSizeChange}
|
|
83
82
|
onChangeText={onTextChanged}
|
|
84
83
|
style={[
|
|
84
|
+
stylesCommon.fill,
|
|
85
85
|
styles.textInput,
|
|
86
86
|
textInputStyle,
|
|
87
87
|
{
|
|
@@ -105,24 +105,8 @@ export function Composer ({
|
|
|
105
105
|
)
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
Composer.propTypes = {
|
|
109
|
-
composerHeight: PropTypes.number,
|
|
110
|
-
text: PropTypes.string,
|
|
111
|
-
placeholder: PropTypes.string,
|
|
112
|
-
placeholderTextColor: PropTypes.string,
|
|
113
|
-
textInputProps: PropTypes.object,
|
|
114
|
-
onTextChanged: PropTypes.func,
|
|
115
|
-
onInputSizeChanged: PropTypes.func,
|
|
116
|
-
multiline: PropTypes.bool,
|
|
117
|
-
disableComposer: PropTypes.bool,
|
|
118
|
-
textInputStyle: StylePropType,
|
|
119
|
-
textInputAutoFocus: PropTypes.bool,
|
|
120
|
-
keyboardAppearance: PropTypes.string,
|
|
121
|
-
}
|
|
122
|
-
|
|
123
108
|
const styles = StyleSheet.create({
|
|
124
109
|
textInput: {
|
|
125
|
-
flex: 1,
|
|
126
110
|
marginLeft: 10,
|
|
127
111
|
fontSize: 16,
|
|
128
112
|
lineHeight: 22,
|
package/src/Constant.ts
CHANGED
|
@@ -8,7 +8,7 @@ export const MIN_COMPOSER_HEIGHT = Platform.select({
|
|
|
8
8
|
})
|
|
9
9
|
export const MAX_COMPOSER_HEIGHT = 200
|
|
10
10
|
export const DEFAULT_PLACEHOLDER = 'Type a message...'
|
|
11
|
-
export const DATE_FORMAT = '
|
|
11
|
+
export const DATE_FORMAT = 'D MMMM'
|
|
12
12
|
export const TIME_FORMAT = 'LT'
|
|
13
13
|
|
|
14
14
|
export const TEST_ID = {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Text,
|
|
4
|
+
View,
|
|
5
|
+
} from 'react-native'
|
|
6
|
+
import dayjs from 'dayjs'
|
|
7
|
+
import relativeTime from 'dayjs/plugin/relativeTime'
|
|
8
|
+
import calendar from 'dayjs/plugin/calendar'
|
|
9
|
+
|
|
10
|
+
import { DATE_FORMAT } from '../Constant'
|
|
11
|
+
import { DayProps } from './types'
|
|
12
|
+
|
|
13
|
+
import { useChatContext } from '../GiftedChatContext'
|
|
14
|
+
import stylesCommon from '../styles'
|
|
15
|
+
import styles from './styles'
|
|
16
|
+
|
|
17
|
+
export * from './types'
|
|
18
|
+
|
|
19
|
+
dayjs.extend(relativeTime)
|
|
20
|
+
dayjs.extend(calendar)
|
|
21
|
+
|
|
22
|
+
export function Day ({
|
|
23
|
+
dateFormat = DATE_FORMAT,
|
|
24
|
+
dateFormatCalendar,
|
|
25
|
+
createdAt,
|
|
26
|
+
containerStyle,
|
|
27
|
+
wrapperStyle,
|
|
28
|
+
textStyle,
|
|
29
|
+
}: DayProps) {
|
|
30
|
+
const { getLocale } = useChatContext()
|
|
31
|
+
|
|
32
|
+
const dateStr = React.useMemo(() => {
|
|
33
|
+
if (createdAt == null)
|
|
34
|
+
return null
|
|
35
|
+
|
|
36
|
+
const now = dayjs().startOf('day')
|
|
37
|
+
const date = dayjs(createdAt).locale(getLocale()).startOf('day')
|
|
38
|
+
|
|
39
|
+
if (!now.isSame(date, 'year'))
|
|
40
|
+
return date.format('D MMMM YYYY')
|
|
41
|
+
|
|
42
|
+
if (now.diff(date, 'days') <= 1)
|
|
43
|
+
return date.calendar(now, {
|
|
44
|
+
sameDay: '[Today]',
|
|
45
|
+
...dateFormatCalendar,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
return date.format(dateFormat)
|
|
49
|
+
}, [createdAt, dateFormat, getLocale, dateFormatCalendar])
|
|
50
|
+
|
|
51
|
+
if (!dateStr)
|
|
52
|
+
return null
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View style={[stylesCommon.centerItems, styles.container, containerStyle]}>
|
|
56
|
+
<View style={[styles.wrapper, wrapperStyle]}>
|
|
57
|
+
<Text style={[styles.text, textStyle]}>
|
|
58
|
+
{dateStr}
|
|
59
|
+
</Text>
|
|
60
|
+
</View>
|
|
61
|
+
</View>
|
|
62
|
+
)
|
|
63
|
+
}
|