react-native-gifted-chat 2.8.2-alpha.6 → 3.0.0-alpha.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 +190 -269
- package/package.json +2 -1
- package/src/Actions.tsx +1 -1
- package/src/Avatar.tsx +12 -12
- package/src/Bubble/index.tsx +14 -16
- package/src/Bubble/styles.ts +1 -1
- package/src/Bubble/types.ts +26 -27
- package/src/Color.ts +1 -1
- package/src/Composer.tsx +1 -4
- package/src/Day/styles.ts +1 -1
- package/src/GiftedAvatar.tsx +2 -2
- package/src/GiftedChat/index.tsx +26 -61
- package/src/GiftedChat/types.ts +40 -49
- package/src/InputToolbar.tsx +28 -19
- package/src/LoadEarlierMessages.tsx +1 -1
- package/src/Message/index.tsx +11 -14
- package/src/Message/types.ts +8 -12
- package/src/MessageAudio.tsx +1 -1
- package/src/MessageContainer/components/DayAnimated/index.tsx +1 -3
- package/src/MessageContainer/components/DayAnimated/types.ts +1 -1
- package/src/MessageContainer/components/Item/index.tsx +9 -11
- package/src/MessageContainer/components/Item/types.ts +1 -1
- package/src/MessageContainer/index.tsx +32 -36
- package/src/MessageContainer/styles.ts +1 -1
- package/src/MessageContainer/types.ts +12 -16
- package/src/MessageImage.tsx +1 -1
- package/src/MessageText.tsx +1 -1
- package/src/MessageVideo.tsx +1 -1
- package/src/Models.ts +63 -0
- package/src/QuickReplies.tsx +2 -2
- package/src/Send.tsx +31 -32
- package/src/SystemMessage.tsx +2 -2
- package/src/Time.tsx +6 -6
- package/src/TypingIndicator/index.tsx +1 -3
- package/src/TypingIndicator/styles.ts +1 -1
- package/src/__tests__/Actions.test.tsx +1 -1
- package/src/__tests__/Avatar.test.tsx +7 -2
- package/src/__tests__/Bubble.test.tsx +3 -7
- package/src/__tests__/Color.test.tsx +1 -1
- package/src/__tests__/Composer.test.tsx +1 -1
- package/src/__tests__/Day.test.tsx +3 -3
- package/src/__tests__/DayAnimated.test.tsx +5 -11
- package/src/__tests__/GiftedAvatar.test.tsx +1 -1
- package/src/__tests__/GiftedChat.test.tsx +1 -1
- package/src/__tests__/InputToolbar.test.tsx +1 -1
- package/src/__tests__/LoadEarlier.test.tsx +2 -2
- package/src/__tests__/Message.test.tsx +7 -13
- package/src/__tests__/MessageContainer.test.tsx +4 -4
- package/src/__tests__/MessageImage.test.tsx +2 -2
- package/src/__tests__/MessageText.test.tsx +3 -2
- package/src/__tests__/Send.test.tsx +2 -2
- package/src/__tests__/SystemMessage.test.tsx +1 -1
- package/src/__tests__/Time.test.tsx +1 -1
- package/src/__tests__/__snapshots__/Actions.test.tsx.snap +2 -86
- package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/Day.test.tsx.snap +96 -2
- package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +3 -89
- package/src/__tests__/__snapshots__/Message.test.tsx.snap +43 -4
- package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +1 -1
- package/src/__tests__/__snapshots__/Send.test.tsx.snap +10 -142
- package/src/__tests__/data.ts +2 -2
- package/src/components/TouchableOpacity.tsx +19 -8
- package/src/index.ts +19 -1
- package/src/types.ts +1 -63
- package/src/utils.ts +23 -2
package/src/Bubble/index.tsx
CHANGED
|
@@ -10,19 +10,19 @@ import { MessageAudio } from '../MessageAudio'
|
|
|
10
10
|
import { MessageImage } from '../MessageImage'
|
|
11
11
|
import { MessageText } from '../MessageText'
|
|
12
12
|
import { MessageVideo } from '../MessageVideo'
|
|
13
|
+
import { IMessage } from '../Models'
|
|
13
14
|
import { QuickReplies } from '../QuickReplies'
|
|
14
15
|
import stylesCommon from '../styles'
|
|
15
16
|
|
|
16
17
|
import { Time } from '../Time'
|
|
17
|
-
import {
|
|
18
|
-
import { isSameUser, isSameDay } from '../utils'
|
|
18
|
+
import { isSameUser, isSameDay, renderComponentOrElement } from '../utils'
|
|
19
19
|
|
|
20
20
|
import styles from './styles'
|
|
21
21
|
import { BubbleProps, RenderMessageTextProps } from './types'
|
|
22
22
|
|
|
23
23
|
export * from './types'
|
|
24
24
|
|
|
25
|
-
const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessage>): JSX.Element => {
|
|
25
|
+
export const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessage>): JSX.Element => {
|
|
26
26
|
const {
|
|
27
27
|
currentMessage,
|
|
28
28
|
nextMessage,
|
|
@@ -109,7 +109,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
109
109
|
} = props
|
|
110
110
|
|
|
111
111
|
if (props.renderQuickReplies)
|
|
112
|
-
return props.renderQuickReplies
|
|
112
|
+
return renderComponentOrElement(props.renderQuickReplies, quickReplyProps)
|
|
113
113
|
|
|
114
114
|
return (
|
|
115
115
|
<QuickReplies
|
|
@@ -150,9 +150,9 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
150
150
|
const combinedProps = { ...messageTextPropsRest, ...messageTextProps } as RenderMessageTextProps<TMessage>
|
|
151
151
|
|
|
152
152
|
if (props.renderMessageText)
|
|
153
|
-
return props.renderMessageText
|
|
153
|
+
return renderComponentOrElement(props.renderMessageText, combinedProps)
|
|
154
154
|
|
|
155
|
-
return <MessageText {...combinedProps} />
|
|
155
|
+
return <MessageText {...combinedProps as any} />
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
return null
|
|
@@ -169,7 +169,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
169
169
|
} = props
|
|
170
170
|
|
|
171
171
|
if (props.renderMessageImage)
|
|
172
|
-
return props.renderMessageImage
|
|
172
|
+
return renderComponentOrElement(props.renderMessageImage, messageImageProps)
|
|
173
173
|
|
|
174
174
|
return <MessageImage {...messageImageProps} />
|
|
175
175
|
}
|
|
@@ -190,7 +190,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
190
190
|
} = props
|
|
191
191
|
|
|
192
192
|
if (props.renderMessageVideo)
|
|
193
|
-
return props.renderMessageVideo
|
|
193
|
+
return renderComponentOrElement(props.renderMessageVideo, messageVideoProps)
|
|
194
194
|
|
|
195
195
|
return <MessageVideo />
|
|
196
196
|
}, [props, currentMessage])
|
|
@@ -208,7 +208,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
208
208
|
} = props
|
|
209
209
|
|
|
210
210
|
if (props.renderMessageAudio)
|
|
211
|
-
return props.renderMessageAudio
|
|
211
|
+
return renderComponentOrElement(props.renderMessageAudio, messageAudioProps)
|
|
212
212
|
|
|
213
213
|
return <MessageAudio />
|
|
214
214
|
}, [props, currentMessage])
|
|
@@ -220,7 +220,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
220
220
|
} = props
|
|
221
221
|
|
|
222
222
|
if (renderTicks && currentMessage)
|
|
223
|
-
return renderTicks
|
|
223
|
+
return renderComponentOrElement(renderTicks, currentMessage)
|
|
224
224
|
|
|
225
225
|
if (
|
|
226
226
|
user &&
|
|
@@ -271,7 +271,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
271
271
|
} = props
|
|
272
272
|
|
|
273
273
|
if (props.renderTime)
|
|
274
|
-
return props.renderTime
|
|
274
|
+
return renderComponentOrElement(props.renderTime, timeProps)
|
|
275
275
|
|
|
276
276
|
return <Time {...timeProps} />
|
|
277
277
|
}
|
|
@@ -284,12 +284,12 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
284
284
|
renderUsername,
|
|
285
285
|
} = props
|
|
286
286
|
|
|
287
|
-
if (props.
|
|
287
|
+
if (props.isUsernameVisible && currentMessage) {
|
|
288
288
|
if (user && currentMessage.user._id === user._id)
|
|
289
289
|
return null
|
|
290
290
|
|
|
291
291
|
if (renderUsername)
|
|
292
|
-
return renderUsername
|
|
292
|
+
return renderComponentOrElement(renderUsername, currentMessage.user)
|
|
293
293
|
|
|
294
294
|
return (
|
|
295
295
|
<View style={styles.content.usernameView}>
|
|
@@ -313,7 +313,7 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
313
313
|
|
|
314
314
|
const renderCustomView = useCallback(() => {
|
|
315
315
|
if (props.renderCustomView)
|
|
316
|
-
return props.renderCustomView
|
|
316
|
+
return renderComponentOrElement(props.renderCustomView, props)
|
|
317
317
|
|
|
318
318
|
return null
|
|
319
319
|
}, [props])
|
|
@@ -378,5 +378,3 @@ const Bubble = <TMessage extends IMessage = IMessage>(props: BubbleProps<TMessag
|
|
|
378
378
|
</View>
|
|
379
379
|
)
|
|
380
380
|
}
|
|
381
|
-
|
|
382
|
-
export default Bubble
|
package/src/Bubble/styles.ts
CHANGED
package/src/Bubble/types.ts
CHANGED
|
@@ -5,9 +5,7 @@ import {
|
|
|
5
5
|
TextStyle,
|
|
6
6
|
} from 'react-native'
|
|
7
7
|
import { MessageImageProps } from '../MessageImage'
|
|
8
|
-
import { MessageTextProps
|
|
9
|
-
import { QuickRepliesProps } from '../QuickReplies'
|
|
10
|
-
import { TimeProps } from '../Time'
|
|
8
|
+
import { MessageTextProps } from '../MessageText'
|
|
11
9
|
import {
|
|
12
10
|
User,
|
|
13
11
|
IMessage,
|
|
@@ -16,9 +14,11 @@ import {
|
|
|
16
14
|
Omit,
|
|
17
15
|
MessageVideoProps,
|
|
18
16
|
MessageAudioProps,
|
|
19
|
-
} from '../
|
|
17
|
+
} from '../Models'
|
|
18
|
+
import { QuickRepliesProps } from '../QuickReplies'
|
|
19
|
+
import { TimeProps } from '../Time'
|
|
20
|
+
|
|
20
21
|
|
|
21
|
-
|
|
22
22
|
export type RenderMessageImageProps<TMessage extends IMessage> = Omit<
|
|
23
23
|
BubbleProps<TMessage>,
|
|
24
24
|
'containerStyle' | 'wrapperStyle'
|
|
@@ -39,22 +39,21 @@ export type RenderMessageAudioProps<TMessage extends IMessage> = Omit<
|
|
|
39
39
|
|
|
40
40
|
export type RenderMessageTextProps<TMessage extends IMessage> = Omit<
|
|
41
41
|
BubbleProps<TMessage>,
|
|
42
|
-
'containerStyle' | 'wrapperStyle'
|
|
42
|
+
'containerStyle' | 'wrapperStyle'
|
|
43
43
|
> &
|
|
44
44
|
MessageTextProps<TMessage>
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
|
|
47
47
|
export interface BubbleProps<TMessage extends IMessage> {
|
|
48
48
|
user?: User
|
|
49
49
|
touchableProps?: object
|
|
50
|
-
|
|
50
|
+
isUsernameVisible?: boolean
|
|
51
51
|
isCustomViewBottom?: boolean
|
|
52
|
-
|
|
52
|
+
isInverted?: boolean
|
|
53
53
|
position: 'left' | 'right'
|
|
54
54
|
currentMessage: TMessage
|
|
55
55
|
nextMessage?: TMessage
|
|
56
56
|
previousMessage?: TMessage
|
|
57
|
-
options?: MessageOption[]
|
|
58
57
|
containerStyle?: LeftRightStyle<ViewStyle>
|
|
59
58
|
wrapperStyle?: LeftRightStyle<ViewStyle>
|
|
60
59
|
textStyle?: LeftRightStyle<TextStyle>
|
|
@@ -67,25 +66,25 @@ export interface BubbleProps<TMessage extends IMessage> {
|
|
|
67
66
|
quickReplyTextStyle?: StyleProp<TextStyle>
|
|
68
67
|
quickReplyContainerStyle?: StyleProp<ViewStyle>
|
|
69
68
|
messageTextProps?: Partial<MessageTextProps<TMessage>>
|
|
70
|
-
onPressMessage
|
|
71
|
-
onLongPressMessage
|
|
72
|
-
onQuickReply
|
|
73
|
-
renderMessageImage
|
|
69
|
+
onPressMessage?: (context?: unknown, message?: unknown) => void
|
|
70
|
+
onLongPressMessage?: (context?: unknown, message?: unknown) => void
|
|
71
|
+
onQuickReply?: (replies: Reply[]) => void
|
|
72
|
+
renderMessageImage?: (
|
|
74
73
|
props: RenderMessageImageProps<TMessage>,
|
|
75
|
-
)
|
|
76
|
-
renderMessageVideo
|
|
74
|
+
) => React.ReactNode
|
|
75
|
+
renderMessageVideo?: (
|
|
77
76
|
props: RenderMessageVideoProps<TMessage>,
|
|
78
|
-
)
|
|
79
|
-
renderMessageAudio
|
|
77
|
+
) => React.ReactNode
|
|
78
|
+
renderMessageAudio?: (
|
|
80
79
|
props: RenderMessageAudioProps<TMessage>,
|
|
81
|
-
)
|
|
82
|
-
renderMessageText
|
|
83
|
-
renderCustomView
|
|
84
|
-
renderTime
|
|
85
|
-
renderTicks
|
|
86
|
-
renderUsername
|
|
87
|
-
renderQuickReplySend
|
|
88
|
-
renderQuickReplies
|
|
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?: (
|
|
89
88
|
quickReplies: QuickRepliesProps<TMessage>,
|
|
90
|
-
)
|
|
89
|
+
) => React.ReactNode
|
|
91
90
|
}
|
package/src/Color.ts
CHANGED
package/src/Composer.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
TextInputContentSizeChangeEventData,
|
|
9
9
|
useColorScheme,
|
|
10
10
|
} from 'react-native'
|
|
11
|
-
import Color from './Color'
|
|
11
|
+
import { Color } from './Color'
|
|
12
12
|
import { MIN_COMPOSER_HEIGHT } from './Constant'
|
|
13
13
|
import stylesCommon from './styles'
|
|
14
14
|
|
|
@@ -16,14 +16,12 @@ export interface ComposerProps {
|
|
|
16
16
|
composerHeight?: number
|
|
17
17
|
text?: string
|
|
18
18
|
textInputProps?: Partial<TextInputProps>
|
|
19
|
-
onTextChanged?(text: string): void
|
|
20
19
|
onInputSizeChanged?(layout: { width: number, height: number }): void
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export function Composer ({
|
|
24
23
|
composerHeight = MIN_COMPOSER_HEIGHT,
|
|
25
24
|
onInputSizeChanged,
|
|
26
|
-
onTextChanged,
|
|
27
25
|
text = '',
|
|
28
26
|
textInputProps,
|
|
29
27
|
}: ComposerProps): React.ReactElement {
|
|
@@ -67,7 +65,6 @@ export function Composer ({
|
|
|
67
65
|
accessibilityLabel={placeholder}
|
|
68
66
|
placeholderTextColor={textInputProps?.placeholderTextColor ?? (isDark ? '#888' : Color.defaultColor)}
|
|
69
67
|
onContentSizeChange={handleContentSizeChange}
|
|
70
|
-
onChangeText={onTextChanged}
|
|
71
68
|
value={text}
|
|
72
69
|
enablesReturnKeyAutomatically
|
|
73
70
|
underlineColorAndroid='transparent'
|
package/src/Day/styles.ts
CHANGED
package/src/GiftedAvatar.tsx
CHANGED
|
@@ -8,10 +8,10 @@ import {
|
|
|
8
8
|
ImageStyle,
|
|
9
9
|
TextStyle,
|
|
10
10
|
} from 'react-native'
|
|
11
|
-
import Color from './Color'
|
|
11
|
+
import { Color } from './Color'
|
|
12
12
|
import { TouchableOpacity } from './components/TouchableOpacity'
|
|
13
|
+
import { User } from './Models'
|
|
13
14
|
import stylesCommon from './styles'
|
|
14
|
-
import { User } from './types'
|
|
15
15
|
|
|
16
16
|
const {
|
|
17
17
|
carrot,
|
package/src/GiftedChat/index.tsx
CHANGED
|
@@ -28,29 +28,13 @@ import Animated, {
|
|
|
28
28
|
runOnJS,
|
|
29
29
|
} from 'react-native-reanimated'
|
|
30
30
|
import { SafeAreaProvider } from 'react-native-safe-area-context'
|
|
31
|
-
import { Actions } from '../Actions'
|
|
32
|
-
import { Avatar } from '../Avatar'
|
|
33
|
-
import Bubble from '../Bubble'
|
|
34
|
-
import { Composer } from '../Composer'
|
|
35
31
|
import { MAX_COMPOSER_HEIGHT, MIN_COMPOSER_HEIGHT, TEST_ID } from '../Constant'
|
|
36
|
-
import { Day } from '../Day'
|
|
37
|
-
import { GiftedAvatar } from '../GiftedAvatar'
|
|
38
32
|
import { GiftedChatContext } from '../GiftedChatContext'
|
|
39
33
|
import { InputToolbar } from '../InputToolbar'
|
|
40
|
-
import {
|
|
41
|
-
import
|
|
42
|
-
import MessageContainer, { AnimatedList } from '../MessageContainer'
|
|
43
|
-
import { MessageImage } from '../MessageImage'
|
|
44
|
-
import { MessageText } from '../MessageText'
|
|
45
|
-
import { Send } from '../Send'
|
|
34
|
+
import { MessageContainer, AnimatedList } from '../MessageContainer'
|
|
35
|
+
import { IMessage } from '../Models'
|
|
46
36
|
import stylesCommon from '../styles'
|
|
47
|
-
import {
|
|
48
|
-
import { Time } from '../Time'
|
|
49
|
-
|
|
50
|
-
import {
|
|
51
|
-
IMessage,
|
|
52
|
-
} from '../types'
|
|
53
|
-
import * as utils from '../utils'
|
|
37
|
+
import { renderComponentOrElement } from '../utils'
|
|
54
38
|
import styles from './styles'
|
|
55
39
|
import { GiftedChatProps } from './types'
|
|
56
40
|
|
|
@@ -78,9 +62,8 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
78
62
|
renderChatFooter,
|
|
79
63
|
renderInputToolbar,
|
|
80
64
|
keyboardBottomOffset = 0,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
inverted = true,
|
|
65
|
+
shouldFocusInputOnKeyboardOpen = true,
|
|
66
|
+
isInverted = true,
|
|
84
67
|
minComposerHeight = MIN_COMPOSER_HEIGHT,
|
|
85
68
|
maxComposerHeight = MAX_COMPOSER_HEIGHT,
|
|
86
69
|
isKeyboardInternallyHandled = true,
|
|
@@ -172,7 +155,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
172
155
|
if (!messageContainerRef?.current)
|
|
173
156
|
return
|
|
174
157
|
|
|
175
|
-
if (
|
|
158
|
+
if (isInverted) {
|
|
176
159
|
messageContainerRef.current.scrollToOffset({
|
|
177
160
|
offset: 0,
|
|
178
161
|
animated: isAnimated,
|
|
@@ -182,7 +165,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
182
165
|
|
|
183
166
|
messageContainerRef.current.scrollToEnd({ animated: isAnimated })
|
|
184
167
|
},
|
|
185
|
-
[
|
|
168
|
+
[isInverted, messageContainerRef]
|
|
186
169
|
)
|
|
187
170
|
|
|
188
171
|
const renderMessages = useMemo(() => {
|
|
@@ -195,12 +178,12 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
195
178
|
<View style={[stylesCommon.fill, messagesContainerStyle]}>
|
|
196
179
|
<MessageContainer<TMessage>
|
|
197
180
|
{...messagesContainerProps}
|
|
198
|
-
|
|
181
|
+
isInverted={isInverted}
|
|
199
182
|
messages={messages}
|
|
200
183
|
forwardRef={messageContainerRef}
|
|
201
184
|
isTyping={isTyping}
|
|
202
185
|
/>
|
|
203
|
-
{renderChatFooter
|
|
186
|
+
{renderComponentOrElement(renderChatFooter, {})}
|
|
204
187
|
</View>
|
|
205
188
|
)
|
|
206
189
|
}, [
|
|
@@ -208,14 +191,14 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
208
191
|
isTyping,
|
|
209
192
|
messages,
|
|
210
193
|
props,
|
|
211
|
-
|
|
194
|
+
isInverted,
|
|
212
195
|
messageContainerRef,
|
|
213
196
|
renderChatFooter,
|
|
214
197
|
])
|
|
215
198
|
|
|
216
199
|
const notifyInputTextReset = useCallback(() => {
|
|
217
|
-
|
|
218
|
-
}, [
|
|
200
|
+
props.textInputProps?.onChangeText?.('')
|
|
201
|
+
}, [props.textInputProps])
|
|
219
202
|
|
|
220
203
|
const resetInputToolbar = useCallback(() => {
|
|
221
204
|
textInputRef.current?.clear()
|
|
@@ -267,15 +250,15 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
267
250
|
[maxComposerHeight, minComposerHeight]
|
|
268
251
|
)
|
|
269
252
|
|
|
270
|
-
const
|
|
253
|
+
const _onChangeText = useCallback(
|
|
271
254
|
(text: string) => {
|
|
272
|
-
|
|
255
|
+
props.textInputProps?.onChangeText?.(text)
|
|
273
256
|
|
|
274
257
|
// Only set state if it's not being overridden by a prop.
|
|
275
258
|
if (props.text === undefined)
|
|
276
259
|
setText(text)
|
|
277
260
|
},
|
|
278
|
-
[
|
|
261
|
+
[props.text, props.textInputProps]
|
|
279
262
|
)
|
|
280
263
|
|
|
281
264
|
const onInitialLayoutViewLayout = useCallback(
|
|
@@ -307,15 +290,15 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
307
290
|
composerHeight: Math.max(minComposerHeight!, composerHeight),
|
|
308
291
|
onSend: _onSend,
|
|
309
292
|
onInputSizeChanged,
|
|
310
|
-
onTextChanged: _onInputTextChanged,
|
|
311
293
|
textInputProps: {
|
|
312
294
|
...textInputProps,
|
|
295
|
+
onChangeText: _onChangeText,
|
|
313
296
|
ref: textInputRef,
|
|
314
297
|
},
|
|
315
298
|
}
|
|
316
299
|
|
|
317
300
|
if (renderInputToolbar)
|
|
318
|
-
return renderInputToolbar
|
|
301
|
+
return renderComponentOrElement(renderInputToolbar, inputToolbarProps)
|
|
319
302
|
|
|
320
303
|
return <InputToolbar {...inputToolbarProps} />
|
|
321
304
|
}, [
|
|
@@ -330,7 +313,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
330
313
|
composerHeight,
|
|
331
314
|
textInputRef,
|
|
332
315
|
textInputProps,
|
|
333
|
-
|
|
316
|
+
_onChangeText,
|
|
334
317
|
])
|
|
335
318
|
|
|
336
319
|
const contextValues = useMemo(
|
|
@@ -371,7 +354,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
371
354
|
}
|
|
372
355
|
)
|
|
373
356
|
|
|
374
|
-
if (
|
|
357
|
+
if (shouldFocusInputOnKeyboardOpen)
|
|
375
358
|
if (isKeyboardMovingUp)
|
|
376
359
|
runOnJS(handleTextInputFocusWhenKeyboardShow)()
|
|
377
360
|
else
|
|
@@ -382,7 +365,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
382
365
|
[
|
|
383
366
|
keyboard,
|
|
384
367
|
trackingKeyboardMovement,
|
|
385
|
-
|
|
368
|
+
shouldFocusInputOnKeyboardOpen,
|
|
386
369
|
handleTextInputFocusWhenKeyboardHide,
|
|
387
370
|
handleTextInputFocusWhenKeyboardShow,
|
|
388
371
|
keyboardBottomOffset,
|
|
@@ -406,7 +389,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
|
|
|
406
389
|
</Animated.View>
|
|
407
390
|
)
|
|
408
391
|
: (
|
|
409
|
-
renderLoading
|
|
392
|
+
renderComponentOrElement(renderLoading, {})
|
|
410
393
|
)}
|
|
411
394
|
</View>
|
|
412
395
|
</ActionSheetProvider>
|
|
@@ -429,12 +412,12 @@ function GiftedChatWrapper<TMessage extends IMessage = IMessage> (props: GiftedC
|
|
|
429
412
|
GiftedChatWrapper.append = <TMessage extends IMessage>(
|
|
430
413
|
currentMessages: TMessage[] = [],
|
|
431
414
|
messages: TMessage[],
|
|
432
|
-
|
|
415
|
+
isInverted = true
|
|
433
416
|
) => {
|
|
434
417
|
if (!Array.isArray(messages))
|
|
435
418
|
messages = [messages]
|
|
436
419
|
|
|
437
|
-
return
|
|
420
|
+
return isInverted
|
|
438
421
|
? messages.concat(currentMessages)
|
|
439
422
|
: currentMessages.concat(messages)
|
|
440
423
|
}
|
|
@@ -442,34 +425,16 @@ GiftedChatWrapper.append = <TMessage extends IMessage>(
|
|
|
442
425
|
GiftedChatWrapper.prepend = <TMessage extends IMessage>(
|
|
443
426
|
currentMessages: TMessage[] = [],
|
|
444
427
|
messages: TMessage[],
|
|
445
|
-
|
|
428
|
+
isInverted = true
|
|
446
429
|
) => {
|
|
447
430
|
if (!Array.isArray(messages))
|
|
448
431
|
messages = [messages]
|
|
449
432
|
|
|
450
|
-
return
|
|
433
|
+
return isInverted
|
|
451
434
|
? currentMessages.concat(messages)
|
|
452
435
|
: messages.concat(currentMessages)
|
|
453
436
|
}
|
|
454
437
|
|
|
455
|
-
export * from '../types'
|
|
456
|
-
|
|
457
438
|
export {
|
|
458
|
-
GiftedChatWrapper as GiftedChat
|
|
459
|
-
Actions,
|
|
460
|
-
Avatar,
|
|
461
|
-
Bubble,
|
|
462
|
-
SystemMessage,
|
|
463
|
-
MessageImage,
|
|
464
|
-
MessageText,
|
|
465
|
-
Composer,
|
|
466
|
-
Day,
|
|
467
|
-
InputToolbar,
|
|
468
|
-
LoadEarlierMessages,
|
|
469
|
-
Message,
|
|
470
|
-
MessageContainer,
|
|
471
|
-
Send,
|
|
472
|
-
Time,
|
|
473
|
-
GiftedAvatar,
|
|
474
|
-
utils
|
|
439
|
+
GiftedChatWrapper as GiftedChat
|
|
475
440
|
}
|
package/src/GiftedChat/types.ts
CHANGED
|
@@ -13,21 +13,20 @@ import { AvatarProps } from '../Avatar'
|
|
|
13
13
|
import { BubbleProps } from '../Bubble'
|
|
14
14
|
import { ComposerProps } from '../Composer'
|
|
15
15
|
import { InputToolbarProps } from '../InputToolbar'
|
|
16
|
-
import { MessageProps } from '../Message'
|
|
17
16
|
import { AnimatedList, MessageContainerProps } from '../MessageContainer'
|
|
18
17
|
import { MessageImageProps } from '../MessageImage'
|
|
19
18
|
import { MessageTextProps } from '../MessageText'
|
|
20
|
-
import { QuickRepliesProps } from '../QuickReplies'
|
|
21
|
-
import { SendProps } from '../Send'
|
|
22
|
-
import { SystemMessageProps } from '../SystemMessage'
|
|
23
|
-
import { TimeProps } from '../Time'
|
|
24
19
|
import {
|
|
25
20
|
IMessage,
|
|
26
21
|
LeftRightStyle,
|
|
27
22
|
MessageAudioProps,
|
|
28
23
|
MessageVideoProps,
|
|
29
24
|
User,
|
|
30
|
-
} from '../
|
|
25
|
+
} from '../Models'
|
|
26
|
+
import { QuickRepliesProps } from '../QuickReplies'
|
|
27
|
+
import { SendProps } from '../Send'
|
|
28
|
+
import { SystemMessageProps } from '../SystemMessage'
|
|
29
|
+
import { TimeProps } from '../Time'
|
|
31
30
|
|
|
32
31
|
export interface GiftedChatProps<TMessage extends IMessage> extends Partial<MessageContainerProps<TMessage>> {
|
|
33
32
|
/* Message container ref */
|
|
@@ -35,7 +34,7 @@ export interface GiftedChatProps<TMessage extends IMessage> extends Partial<Mess
|
|
|
35
34
|
/* text input ref */
|
|
36
35
|
textInputRef?: RefObject<TextInput>
|
|
37
36
|
/* Controls whether or not to show user.name property in the message bubble */
|
|
38
|
-
|
|
37
|
+
isUsernameVisible?: boolean
|
|
39
38
|
/* Messages container style */
|
|
40
39
|
messagesContainerStyle?: StyleProp<ViewStyle>
|
|
41
40
|
/* Input text; default is undefined, but if specified, it will override GiftedChat's internal state */
|
|
@@ -54,23 +53,23 @@ export interface GiftedChatProps<TMessage extends IMessage> extends Partial<Mess
|
|
|
54
53
|
/* Determine whether to handle keyboard awareness inside the plugin. If you have your own keyboard handling outside the plugin set this to false; default is `true` */
|
|
55
54
|
isKeyboardInternallyHandled?: boolean
|
|
56
55
|
/* Whether to render an avatar for the current user; default is false, only show avatars for other users */
|
|
57
|
-
|
|
56
|
+
isUserAvatarVisible?: boolean
|
|
58
57
|
/* When false, avatars will only be displayed when a consecutive message is from the same user on the same day; default is false */
|
|
59
|
-
|
|
58
|
+
isAvatarVisibleForEveryMessage?: boolean
|
|
60
59
|
/* Render the message avatar at the top of consecutive messages, rather than the bottom; default is false */
|
|
61
|
-
|
|
60
|
+
isAvatarOnTop?: boolean
|
|
62
61
|
/* Extra props to be passed to the <Image> component created by the default renderMessageImage */
|
|
63
62
|
imageProps?: MessageImageProps<TMessage>
|
|
64
63
|
/* Distance of the chat from the bottom of the screen (e.g. useful if you display a tab bar); default is 0 */
|
|
65
64
|
keyboardBottomOffset?: number
|
|
66
65
|
/* Focus on <TextInput> automatically when opening the keyboard; default is true */
|
|
67
|
-
|
|
66
|
+
shouldFocusInputOnKeyboardOpen?: boolean
|
|
68
67
|
/* Minimum height of the input toolbar; default is 44 */
|
|
69
68
|
minInputToolbarHeight?: number
|
|
70
69
|
/* Extra props to be passed to the <TextInput>. See https://reactnative.dev/docs/textinput */
|
|
71
70
|
textInputProps?: Partial<React.ComponentProps<typeof TextInput>>
|
|
72
71
|
/* Force send button */
|
|
73
|
-
|
|
72
|
+
isSendButtonAlwaysVisible?: boolean
|
|
74
73
|
/* Image style */
|
|
75
74
|
imageStyle?: StyleProp<ViewStyle>
|
|
76
75
|
/* composer min Height */
|
|
@@ -86,73 +85,65 @@ export interface GiftedChatProps<TMessage extends IMessage> extends Partial<Mess
|
|
|
86
85
|
isCustomViewBottom?: boolean
|
|
87
86
|
timeTextStyle?: LeftRightStyle<TextStyle>
|
|
88
87
|
/* Custom action sheet */
|
|
89
|
-
actionSheet
|
|
88
|
+
actionSheet?: () => {
|
|
90
89
|
showActionSheetWithOptions: (
|
|
91
90
|
options: ActionSheetOptions,
|
|
92
91
|
callback: (buttonIndex: number) => void | Promise<void>,
|
|
93
92
|
) => void
|
|
94
93
|
}
|
|
95
94
|
/* Callback when a message avatar is tapped */
|
|
96
|
-
onPressAvatar
|
|
95
|
+
onPressAvatar?: (user: User) => void
|
|
97
96
|
/* Callback when a message avatar is tapped */
|
|
98
|
-
onLongPressAvatar
|
|
99
|
-
/* Generate an id for new messages. Defaults to
|
|
100
|
-
messageIdGenerator
|
|
97
|
+
onLongPressAvatar?: (user: User) => void
|
|
98
|
+
/* Generate an id for new messages. Defaults to a simple random string generator */
|
|
99
|
+
messageIdGenerator?: (message?: TMessage) => string
|
|
101
100
|
/* Callback when sending a message */
|
|
102
|
-
onSend
|
|
101
|
+
onSend?: (messages: TMessage[]) => void
|
|
103
102
|
/* Render a loading view when initializing */
|
|
104
|
-
renderLoading
|
|
103
|
+
renderLoading?: () => React.ReactNode
|
|
105
104
|
/* Custom message avatar; set to null to not render any avatar for the message */
|
|
106
105
|
renderAvatar?: null | ((props: AvatarProps<TMessage>) => React.ReactNode)
|
|
107
106
|
/* Custom message bubble */
|
|
108
|
-
renderBubble
|
|
107
|
+
renderBubble?: (props: BubbleProps<TMessage>) => React.ReactNode
|
|
109
108
|
/* Custom system message */
|
|
110
|
-
renderSystemMessage
|
|
109
|
+
renderSystemMessage?: (props: SystemMessageProps<TMessage>) => React.ReactNode
|
|
111
110
|
/* Callback when a message bubble is pressed; default is to do nothing */
|
|
112
|
-
onPressMessage
|
|
111
|
+
onPressMessage?: (context: unknown, message: TMessage) => void
|
|
113
112
|
/* Callback when a message bubble is long-pressed; default is to show an ActionSheet with "Copy Text" (see example using showActionSheetWithOptions()) */
|
|
114
|
-
onLongPressMessage
|
|
113
|
+
onLongPressMessage?: (context: unknown, message: TMessage) => void
|
|
115
114
|
/* Custom Username container */
|
|
116
|
-
renderUsername
|
|
115
|
+
renderUsername?: (user: User) => React.ReactNode
|
|
117
116
|
/* Reverses display order of messages; default is true */
|
|
118
117
|
/* Custom message text */
|
|
119
|
-
renderMessageText
|
|
118
|
+
renderMessageText?: (messageText: MessageTextProps<TMessage>) => React.ReactNode
|
|
120
119
|
/* Custom message image */
|
|
121
|
-
renderMessageImage
|
|
120
|
+
renderMessageImage?: (props: MessageImageProps<TMessage>) => React.ReactNode
|
|
122
121
|
/* Custom message video */
|
|
123
|
-
renderMessageVideo
|
|
122
|
+
renderMessageVideo?: (props: MessageVideoProps<TMessage>) => React.ReactNode
|
|
124
123
|
/* Custom message video */
|
|
125
|
-
renderMessageAudio
|
|
124
|
+
renderMessageAudio?: (props: MessageAudioProps<TMessage>) => React.ReactNode
|
|
126
125
|
/* Custom view inside the bubble */
|
|
127
|
-
renderCustomView
|
|
126
|
+
renderCustomView?: (props: BubbleProps<TMessage>) => React.ReactNode
|
|
128
127
|
/* Custom time inside a message */
|
|
129
|
-
renderTime
|
|
128
|
+
renderTime?: (props: TimeProps<TMessage>) => React.ReactNode
|
|
130
129
|
/* Custom component to render below the MessageContainer (separate from the ListView) */
|
|
131
|
-
renderChatFooter
|
|
132
|
-
/* Custom message composer container */
|
|
133
|
-
renderInputToolbar
|
|
130
|
+
renderChatFooter?: () => React.ReactNode
|
|
131
|
+
/* Custom message composer container. Can be a component, element, render function, or null */
|
|
132
|
+
renderInputToolbar?: React.ComponentType<InputToolbarProps<TMessage>> | React.ReactElement | ((props: InputToolbarProps<TMessage>) => React.ReactNode) | null
|
|
134
133
|
/* Custom text input message composer */
|
|
135
|
-
renderComposer
|
|
134
|
+
renderComposer?: (props: ComposerProps) => React.ReactNode
|
|
136
135
|
/* Custom action button on the left of the message composer */
|
|
137
|
-
renderActions
|
|
136
|
+
renderActions?: (props: ActionsProps) => React.ReactNode
|
|
138
137
|
/* Custom send button; you can pass children to the original Send component quite easily, for example to use a custom icon (example) */
|
|
139
|
-
renderSend
|
|
138
|
+
renderSend?: (props: SendProps<TMessage>) => React.ReactNode
|
|
140
139
|
/* Custom second line of actions below the message composer */
|
|
141
|
-
renderAccessory
|
|
140
|
+
renderAccessory?: (props: InputToolbarProps<TMessage>) => React.ReactNode
|
|
142
141
|
/* Callback when the Action button is pressed (if set, the default actionSheet will not be used) */
|
|
143
|
-
onPressActionButton
|
|
144
|
-
/* Callback when the input text changes */
|
|
145
|
-
onInputTextChanged?(text: string): void
|
|
142
|
+
onPressActionButton?: () => void
|
|
146
143
|
/* Extra props to be passed to the MessageText component */
|
|
147
144
|
messageTextProps?: Partial<MessageTextProps<TMessage>>
|
|
148
|
-
|
|
149
|
-
matchers?: MessageTextProps<TMessage>['matchers']
|
|
150
|
-
renderQuickReplies?(
|
|
145
|
+
renderQuickReplies?: (
|
|
151
146
|
quickReplies: QuickRepliesProps<TMessage>,
|
|
152
|
-
)
|
|
153
|
-
renderQuickReplySend
|
|
154
|
-
shouldUpdateMessage?(
|
|
155
|
-
props: MessageProps<TMessage>,
|
|
156
|
-
nextProps: MessageProps<TMessage>,
|
|
157
|
-
): boolean
|
|
147
|
+
) => React.ReactNode
|
|
148
|
+
renderQuickReplySend?: () => React.ReactNode
|
|
158
149
|
}
|