react-native-gifted-chat 2.8.2-alpha.4 → 2.9.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.
Files changed (62) hide show
  1. package/CHANGELOG_2.8.1_to_2.8.2-alpha.5.md +374 -0
  2. package/README.md +26 -26
  3. package/package.json +2 -1
  4. package/src/Actions.tsx +1 -1
  5. package/src/Bubble/index.tsx +12 -14
  6. package/src/Bubble/styles.ts +1 -1
  7. package/src/Bubble/types.ts +4 -5
  8. package/src/Color.ts +1 -1
  9. package/src/Composer.tsx +1 -1
  10. package/src/Day/styles.ts +1 -1
  11. package/src/GiftedAvatar.tsx +1 -1
  12. package/src/GiftedChat/index.tsx +12 -49
  13. package/src/GiftedChat/types.ts +2 -2
  14. package/src/InputToolbar.tsx +22 -13
  15. package/src/LoadEarlierMessages.tsx +48 -51
  16. package/src/Message/index.tsx +6 -8
  17. package/src/MessageAudio.tsx +1 -1
  18. package/src/MessageContainer/components/DayAnimated/index.tsx +2 -3
  19. package/src/MessageContainer/components/Item/index.tsx +8 -10
  20. package/src/MessageContainer/index.tsx +9 -11
  21. package/src/MessageContainer/styles.ts +1 -1
  22. package/src/MessageText.tsx +2 -1
  23. package/src/MessageVideo.tsx +1 -1
  24. package/src/QuickReplies.tsx +1 -1
  25. package/src/Send.tsx +1 -1
  26. package/src/SystemMessage.tsx +30 -24
  27. package/src/Time.tsx +5 -5
  28. package/src/TypingIndicator/index.tsx +1 -3
  29. package/src/TypingIndicator/styles.ts +1 -1
  30. package/src/__tests__/Actions.test.tsx +1 -1
  31. package/src/__tests__/Avatar.test.tsx +7 -2
  32. package/src/__tests__/Bubble.test.tsx +3 -7
  33. package/src/__tests__/Color.test.tsx +1 -1
  34. package/src/__tests__/Composer.test.tsx +1 -1
  35. package/src/__tests__/Day.test.tsx +3 -3
  36. package/src/__tests__/DayAnimated.test.tsx +5 -11
  37. package/src/__tests__/GiftedAvatar.test.tsx +1 -1
  38. package/src/__tests__/GiftedChat.test.tsx +1 -1
  39. package/src/__tests__/InputToolbar.test.tsx +1 -1
  40. package/src/__tests__/LoadEarlier.test.tsx +2 -2
  41. package/src/__tests__/Message.test.tsx +5 -11
  42. package/src/__tests__/MessageContainer.test.tsx +4 -4
  43. package/src/__tests__/MessageImage.test.tsx +2 -2
  44. package/src/__tests__/MessageText.test.tsx +3 -2
  45. package/src/__tests__/Send.test.tsx +1 -1
  46. package/src/__tests__/SystemMessage.test.tsx +1 -1
  47. package/src/__tests__/Time.test.tsx +1 -1
  48. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +61 -57
  49. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +1 -2
  50. package/src/__tests__/__snapshots__/Day.test.tsx.snap +96 -2
  51. package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +56 -36
  52. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +1 -1
  53. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +64 -52
  54. package/src/__tests__/__snapshots__/Message.test.tsx.snap +41 -5
  55. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +1 -2
  56. package/src/__tests__/__snapshots__/Send.test.tsx.snap +120 -108
  57. package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +38 -8
  58. package/src/__tests__/data.ts +1 -1
  59. package/src/components/TouchableOpacity.tsx +26 -15
  60. package/src/index.ts +19 -1
  61. package/src/utils.ts +22 -1
  62. package/src/LoadEarlier.tsx +0 -95
@@ -28,29 +28,15 @@ 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 { LoadEarlierMessages } from '../LoadEarlierMessages'
41
- import Message from '../Message'
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'
46
35
  import stylesCommon from '../styles'
47
- import { SystemMessage } from '../SystemMessage'
48
- import { Time } from '../Time'
49
-
50
36
  import {
51
37
  IMessage,
52
38
  } from '../types'
53
- import * as utils from '../utils'
39
+ import { renderComponentOrElement } from '../utils'
54
40
  import styles from './styles'
55
41
  import { GiftedChatProps } from './types'
56
42
 
@@ -200,7 +186,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
200
186
  forwardRef={messageContainerRef}
201
187
  isTyping={isTyping}
202
188
  />
203
- {renderChatFooter?.()}
189
+ {renderComponentOrElement(renderChatFooter, {})}
204
190
  </View>
205
191
  )
206
192
  }, [
@@ -280,7 +266,6 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
280
266
 
281
267
  const onInitialLayoutViewLayout = useCallback(
282
268
  (e: LayoutChangeEvent) => {
283
- console.log('onInitialLayoutViewLayout', e.nativeEvent.layout.height)
284
269
  if (isInitialized)
285
270
  return
286
271
 
@@ -316,7 +301,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
316
301
  }
317
302
 
318
303
  if (renderInputToolbar)
319
- return renderInputToolbar(inputToolbarProps)
304
+ return renderComponentOrElement(renderInputToolbar, inputToolbarProps)
320
305
 
321
306
  return <InputToolbar {...inputToolbarProps} />
322
307
  }, [
@@ -407,7 +392,7 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
407
392
  </Animated.View>
408
393
  )
409
394
  : (
410
- renderLoading?.()
395
+ renderComponentOrElement(renderLoading, {})
411
396
  )}
412
397
  </View>
413
398
  </ActionSheetProvider>
@@ -416,18 +401,14 @@ function GiftedChat<TMessage extends IMessage = IMessage> (
416
401
  }
417
402
 
418
403
  function GiftedChatWrapper<TMessage extends IMessage = IMessage> (props: GiftedChatProps<TMessage>) {
419
- // Don't use KeyboardProvider when keyboard is not internally handled
420
- if (!props.isKeyboardInternallyHandled)
421
- return <GiftedChat<TMessage> {...props} />
422
-
423
404
  return (
424
- <GestureHandlerRootView style={styles.fill}>
425
- <SafeAreaProvider>
426
- <KeyboardProvider>
405
+ <KeyboardProvider>
406
+ <GestureHandlerRootView style={styles.fill}>
407
+ <SafeAreaProvider>
427
408
  <GiftedChat<TMessage> {...props} />
428
- </KeyboardProvider>
429
- </SafeAreaProvider>
430
- </GestureHandlerRootView>
409
+ </SafeAreaProvider>
410
+ </GestureHandlerRootView>
411
+ </KeyboardProvider>
431
412
  )
432
413
  }
433
414
 
@@ -457,24 +438,6 @@ GiftedChatWrapper.prepend = <TMessage extends IMessage>(
457
438
  : messages.concat(currentMessages)
458
439
  }
459
440
 
460
- export * from '../types'
461
-
462
441
  export {
463
- GiftedChatWrapper as GiftedChat,
464
- Actions,
465
- Avatar,
466
- Bubble,
467
- SystemMessage,
468
- MessageImage,
469
- MessageText,
470
- Composer,
471
- Day,
472
- InputToolbar,
473
- LoadEarlierMessages,
474
- Message,
475
- MessageContainer,
476
- Send,
477
- Time,
478
- GiftedAvatar,
479
- utils
442
+ GiftedChatWrapper as GiftedChat
480
443
  }
@@ -129,8 +129,8 @@ export interface GiftedChatProps<TMessage extends IMessage> extends Partial<Mess
129
129
  renderTime?(props: TimeProps<TMessage>): React.ReactNode
130
130
  /* Custom component to render below the MessageContainer (separate from the ListView) */
131
131
  renderChatFooter?(): React.ReactNode
132
- /* Custom message composer container */
133
- renderInputToolbar?(props: InputToolbarProps<TMessage>): React.ReactNode
132
+ /* Custom message composer container. Can be a component, element, render function, or null */
133
+ renderInputToolbar?: React.ComponentType<InputToolbarProps<TMessage>> | React.ReactElement | ((props: InputToolbarProps<TMessage>) => React.ReactNode) | null
134
134
  /* Custom text input message composer */
135
135
  renderComposer?(props: ComposerProps): React.ReactNode
136
136
  /* Custom action button on the left of the message composer */
@@ -2,10 +2,11 @@ import React, { useMemo } from 'react'
2
2
  import { StyleSheet, View, StyleProp, ViewStyle, useColorScheme } from 'react-native'
3
3
 
4
4
  import { Actions, ActionsProps } from './Actions'
5
- import Color from './Color'
5
+ import { Color } from './Color'
6
6
  import { Composer, ComposerProps } from './Composer'
7
7
  import { Send, SendProps } from './Send'
8
8
  import { IMessage } from './types'
9
+ import { renderComponentOrElement } from './utils'
9
10
 
10
11
  export interface InputToolbarProps<TMessage extends IMessage> {
11
12
  actions?: Array<{ title: string, action: () => void }>
@@ -41,7 +42,7 @@ export function InputToolbar<TMessage extends IMessage = IMessage> (
41
42
  const colorScheme = useColorScheme()
42
43
 
43
44
  const actionsFragment = useMemo(() => {
44
- const props = {
45
+ const actionsProps = {
45
46
  onPressActionButton,
46
47
  actions,
47
48
  actionSheetOptionTintColor,
@@ -50,9 +51,13 @@ export function InputToolbar<TMessage extends IMessage = IMessage> (
50
51
  containerStyle,
51
52
  }
52
53
 
53
- return (
54
- renderActions?.(props) || (onPressActionButton && <Actions {...props} />)
55
- )
54
+ if (renderActions)
55
+ return renderComponentOrElement(renderActions, actionsProps)
56
+
57
+ if (onPressActionButton)
58
+ return <Actions {...actionsProps} />
59
+
60
+ return null
56
61
  }, [
57
62
  renderActions,
58
63
  onPressActionButton,
@@ -64,15 +69,19 @@ export function InputToolbar<TMessage extends IMessage = IMessage> (
64
69
  ])
65
70
 
66
71
  const composerFragment = useMemo(() => {
67
- return (
68
- renderComposer?.(props as ComposerProps) || (
69
- <Composer {...(props as ComposerProps)} />
70
- )
71
- )
72
+ const composerProps = props as ComposerProps
73
+
74
+ if (renderComposer)
75
+ return renderComponentOrElement(renderComposer, composerProps)
76
+
77
+ return <Composer {...composerProps} />
72
78
  }, [renderComposer, props])
73
79
 
74
80
  const sendFragment = useMemo(() => {
75
- return renderSend?.(props) || <Send {...props} />
81
+ if (renderSend)
82
+ return renderComponentOrElement(renderSend, props)
83
+
84
+ return <Send {...props} />
76
85
  }, [renderSend, props])
77
86
 
78
87
  const accessoryFragment = useMemo(() => {
@@ -81,13 +90,13 @@ export function InputToolbar<TMessage extends IMessage = IMessage> (
81
90
 
82
91
  return (
83
92
  <View style={[styles.accessory, props.accessoryStyle]}>
84
- {renderAccessory(props)}
93
+ {renderComponentOrElement(renderAccessory, props)}
85
94
  </View>
86
95
  )
87
96
  }, [renderAccessory, props])
88
97
 
89
98
  return (
90
- <View style={[styles.container, styles[`container_${colorScheme}`], containerStyle]}>
99
+ <View style={[styles.container, colorScheme === 'dark' && styles.container_dark, containerStyle]}>
91
100
  <View style={[styles.primary, props.primaryStyle]}>
92
101
  {actionsFragment}
93
102
  {composerFragment}
@@ -1,7 +1,6 @@
1
- import React, { useMemo } from 'react'
1
+ import React from 'react'
2
2
  import {
3
3
  ActivityIndicator,
4
- Platform,
5
4
  StyleSheet,
6
5
  Text,
7
6
  View,
@@ -9,40 +8,14 @@ import {
9
8
  ViewStyle,
10
9
  TextStyle,
11
10
  } from 'react-native'
12
- import Color from './Color'
11
+ import { Color } from './Color'
13
12
  import { TouchableOpacity } from './components/TouchableOpacity'
14
13
  import stylesCommon from './styles'
15
14
 
16
- const styles = StyleSheet.create({
17
- container: {
18
- alignItems: 'center',
19
- marginTop: 5,
20
- marginBottom: 10,
21
- },
22
- wrapper: {
23
- backgroundColor: Color.defaultColor,
24
- borderRadius: 15,
25
- height: 30,
26
- paddingLeft: 10,
27
- paddingRight: 10,
28
- },
29
- text: {
30
- backgroundColor: Color.backgroundTransparent,
31
- color: Color.white,
32
- fontSize: 12,
33
- },
34
- activityIndicator: {
35
- marginTop: Platform.select({
36
- ios: -14,
37
- android: -16,
38
- default: -15,
39
- }),
40
- },
41
- })
42
-
43
15
  export interface LoadEarlierMessagesProps {
44
- isAvailable?: boolean
45
- isLoading?: boolean
16
+ isAvailable: boolean
17
+ isLoading: boolean
18
+ onPress: () => void
46
19
  isInfiniteScrollEnabled?: boolean
47
20
  label?: string
48
21
  containerStyle?: StyleProp<ViewStyle>
@@ -51,7 +24,6 @@ export interface LoadEarlierMessagesProps {
51
24
  activityIndicatorStyle?: StyleProp<ViewStyle>
52
25
  activityIndicatorColor?: string
53
26
  activityIndicatorSize?: number | 'small' | 'large'
54
- onPress: () => void
55
27
  }
56
28
 
57
29
  export const LoadEarlierMessages: React.FC<LoadEarlierMessagesProps> = ({
@@ -65,23 +37,6 @@ export const LoadEarlierMessages: React.FC<LoadEarlierMessagesProps> = ({
65
37
  activityIndicatorSize = 'small',
66
38
  activityIndicatorStyle,
67
39
  }) => {
68
- const loadingContent = useMemo(() => (
69
- <View>
70
- <Text style={[styles.text, textStyle, { opacity: 0 }]}>
71
- {label}
72
- </Text>
73
- <ActivityIndicator
74
- color={activityIndicatorColor!}
75
- size={activityIndicatorSize!}
76
- style={[styles.activityIndicator, activityIndicatorStyle]}
77
- />
78
- </View>
79
- ), [label, textStyle, activityIndicatorColor, activityIndicatorSize, activityIndicatorStyle])
80
-
81
- const labelContent = useMemo(() => (
82
- <Text style={[styles.text, textStyle]}>{label}</Text>
83
- ), [label, textStyle])
84
-
85
40
  return (
86
41
  <TouchableOpacity
87
42
  style={[styles.container, containerStyle]}
@@ -90,8 +45,50 @@ export const LoadEarlierMessages: React.FC<LoadEarlierMessagesProps> = ({
90
45
  accessibilityRole='button'
91
46
  >
92
47
  <View style={[stylesCommon.centerItems, styles.wrapper, wrapperStyle]}>
93
- {isLoading ? loadingContent : labelContent}
48
+ {
49
+ isLoading
50
+ ? (
51
+ <ActivityIndicator
52
+ color={activityIndicatorColor}
53
+ size={activityIndicatorSize}
54
+ style={[styles.activityIndicator, activityIndicatorStyle]}
55
+ />
56
+ )
57
+ : (
58
+ <View style={styles.textContainer}>
59
+ <Text style={[styles.text, textStyle]}>
60
+ {label}
61
+ </Text>
62
+ </View>
63
+ )
64
+ }
94
65
  </View>
95
66
  </TouchableOpacity>
96
67
  )
97
68
  }
69
+
70
+ const styles = StyleSheet.create({
71
+ container: {
72
+ alignItems: 'center',
73
+ marginVertical: 10,
74
+ },
75
+ wrapper: {
76
+ backgroundColor: Color.defaultColor,
77
+ borderRadius: 15,
78
+ paddingHorizontal: 10,
79
+ paddingVertical: 5,
80
+ },
81
+ textContainer: {
82
+ paddingTop: 3,
83
+ paddingBottom: 4,
84
+ },
85
+ text: {
86
+ backgroundColor: Color.backgroundTransparent,
87
+ color: Color.white,
88
+ fontSize: 12,
89
+ lineHeight: 13,
90
+ },
91
+ activityIndicator: {
92
+ paddingHorizontal: 20,
93
+ },
94
+ })
@@ -1,18 +1,18 @@
1
- import React, { memo, useCallback } from 'react'
1
+ import React, { useCallback } from 'react'
2
2
  import { View } from 'react-native'
3
3
 
4
4
  import { Avatar } from '../Avatar'
5
- import Bubble from '../Bubble'
5
+ import { Bubble } from '../Bubble'
6
6
  import { SystemMessage } from '../SystemMessage'
7
7
 
8
8
  import { IMessage } from '../types'
9
- import { isSameUser } from '../utils'
9
+ import { isSameUser, renderComponentOrElement } from '../utils'
10
10
  import styles from './styles'
11
11
  import { MessageProps } from './types'
12
12
 
13
13
  export * from './types'
14
14
 
15
- const Message: React.FC<MessageProps<IMessage>> = (props: MessageProps<IMessage>) => {
15
+ export const Message = <TMessage extends IMessage = IMessage>(props: MessageProps<TMessage>) => {
16
16
  const {
17
17
  currentMessage,
18
18
  renderBubble: renderBubbleProp,
@@ -35,7 +35,7 @@ const Message: React.FC<MessageProps<IMessage>> = (props: MessageProps<IMessage>
35
35
  } = props
36
36
 
37
37
  if (renderBubbleProp)
38
- return renderBubbleProp(rest)
38
+ return renderComponentOrElement(renderBubbleProp, rest)
39
39
 
40
40
  return <Bubble {...rest} />
41
41
  }, [props, renderBubbleProp])
@@ -50,7 +50,7 @@ const Message: React.FC<MessageProps<IMessage>> = (props: MessageProps<IMessage>
50
50
  } = props
51
51
 
52
52
  if (renderSystemMessageProp)
53
- return renderSystemMessageProp(rest)
53
+ return renderComponentOrElement(renderSystemMessageProp, rest)
54
54
 
55
55
  return <SystemMessage {...rest} />
56
56
  }, [props, renderSystemMessageProp])
@@ -111,5 +111,3 @@ const Message: React.FC<MessageProps<IMessage>> = (props: MessageProps<IMessage>
111
111
  </View>
112
112
  )
113
113
  }
114
-
115
- export default memo(Message)
@@ -1,6 +1,6 @@
1
1
  import React, { useMemo } from 'react'
2
2
  import { View, Text, StyleSheet } from 'react-native'
3
- import Color from './Color'
3
+ import { Color } from './Color'
4
4
 
5
5
  const styles = StyleSheet.create({
6
6
  container: {
@@ -11,7 +11,7 @@ import { DayAnimatedProps } from './types'
11
11
 
12
12
  export * from './types'
13
13
 
14
- const DayAnimated = ({ scrolledY, daysPositions, listHeight, renderDay, messages, isLoading, ...rest }: DayAnimatedProps) => {
14
+ export const DayAnimated = ({ scrolledY, daysPositions, listHeight, renderDay, messages, isLoading, ...rest }: DayAnimatedProps) => {
15
15
  const opacity = useSharedValue(0)
16
16
  const fadeOutOpacityTimeoutId = useSharedValue<ReturnType<typeof setTimeout> | undefined>(undefined)
17
17
  const containerHeight = useSharedValue(0)
@@ -134,6 +134,7 @@ const DayAnimated = ({ scrolledY, daysPositions, listHeight, renderDay, messages
134
134
  <Animated.View
135
135
  style={[stylesCommon.centerItems, styles.dayAnimated, style]}
136
136
  onLayout={handleLayout}
137
+ pointerEvents='none'
137
138
  >
138
139
  <Animated.View
139
140
  style={contentStyle}
@@ -144,5 +145,3 @@ const DayAnimated = ({ scrolledY, daysPositions, listHeight, renderDay, messages
144
145
  </Animated.View>
145
146
  )
146
147
  }
147
-
148
- export default DayAnimated
@@ -1,8 +1,8 @@
1
- import React, { forwardRef, useCallback, useMemo } from 'react'
1
+ import React, { useCallback, useMemo } from 'react'
2
2
  import { LayoutChangeEvent, View } from 'react-native'
3
3
  import Animated, { interpolate, useAnimatedStyle, useDerivedValue, useSharedValue } from 'react-native-reanimated'
4
4
  import { Day } from '../../../Day'
5
- import Message, { MessageProps } from '../../../Message'
5
+ import { Message,MessageProps } from '../../../Message'
6
6
  import { IMessage } from '../../../types'
7
7
  import { isSameDay } from '../../../utils'
8
8
  import { DaysPositions } from '../../types'
@@ -68,7 +68,7 @@ export const useRelativeScrolledPositionToBottomOfDay = (
68
68
  return relativeScrolledPositionToBottomOfDay
69
69
  }
70
70
 
71
- const DayWrapper = forwardRef<View, MessageProps<IMessage>>((props, ref) => {
71
+ const DayWrapper = <TMessage extends IMessage>(props: MessageProps<TMessage>) => {
72
72
  const {
73
73
  renderDay: renderDayProp,
74
74
  currentMessage,
@@ -87,7 +87,7 @@ const DayWrapper = forwardRef<View, MessageProps<IMessage>>((props, ref) => {
87
87
  } = props
88
88
 
89
89
  return (
90
- <View ref={ref}>
90
+ <View>
91
91
  {
92
92
  renderDayProp
93
93
  ? renderDayProp({ ...rest, createdAt: currentMessage.createdAt })
@@ -95,9 +95,9 @@ const DayWrapper = forwardRef<View, MessageProps<IMessage>>((props, ref) => {
95
95
  }
96
96
  </View>
97
97
  )
98
- })
98
+ }
99
99
 
100
- const Item = <TMessage extends IMessage>(props: ItemProps<TMessage>) => {
100
+ export const Item = <TMessage extends IMessage>(props: ItemProps<TMessage>) => {
101
101
  const {
102
102
  renderMessage: renderMessageProp,
103
103
  scrolledY,
@@ -146,15 +146,13 @@ const Item = <TMessage extends IMessage>(props: ItemProps<TMessage>) => {
146
146
  style={style}
147
147
  onLayout={handleLayoutDayContainer}
148
148
  >
149
- <DayWrapper {...rest as MessageProps<TMessage>} />
149
+ <DayWrapper<TMessage> {...rest as MessageProps<TMessage>} />
150
150
  </Animated.View>
151
151
  {
152
152
  renderMessageProp
153
153
  ? renderMessageProp(rest as MessageProps<TMessage>)
154
- : <Message {...rest as MessageProps<TMessage>} />
154
+ : <Message<TMessage> {...rest as MessageProps<TMessage>} />
155
155
  }
156
156
  </View>
157
157
  )
158
158
  }
159
-
160
- export default Item
@@ -15,11 +15,11 @@ import { ReanimatedScrollEvent } from '../reanimatedCompat'
15
15
 
16
16
  import stylesCommon from '../styles'
17
17
  import { IMessage } from '../types'
18
- import TypingIndicator from '../TypingIndicator'
18
+ import { TypingIndicator } from '../TypingIndicator'
19
19
  import { isSameDay, useCallbackThrottled } from '../utils'
20
- import DayAnimated from './components/DayAnimated'
20
+ import { DayAnimated } from './components/DayAnimated'
21
21
 
22
- import Item from './components/Item'
22
+ import { Item } from './components/Item'
23
23
  import { ItemProps } from './components/Item/types'
24
24
  import styles from './styles'
25
25
  import { MessageContainerProps, DaysPositions } from './types'
@@ -29,7 +29,7 @@ export * from './types'
29
29
 
30
30
  const AnimatedFlatList = Animated.createAnimatedComponent(FlatList) as React.ComponentType<any>
31
31
 
32
- function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageContainerProps<TMessage>) {
32
+ export const MessageContainer = <TMessage extends IMessage>(props: MessageContainerProps<TMessage>) => {
33
33
  const {
34
34
  messages = [],
35
35
  user,
@@ -79,7 +79,7 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
79
79
  }, [renderFooterProp, renderTypingIndicator, props])
80
80
 
81
81
  const renderLoadEarlier = useCallback(() => {
82
- if (loadEarlierMessagesProps?.onPress && loadEarlierMessagesProps?.isAvailable) {
82
+ if (loadEarlierMessagesProps?.isAvailable) {
83
83
  if (renderLoadEarlierProp)
84
84
  return renderLoadEarlierProp(loadEarlierMessagesProps)
85
85
 
@@ -286,10 +286,10 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
286
286
 
287
287
  const onEndReached = useCallback(() => {
288
288
  if (
289
- loadEarlierMessagesProps?.isInfiniteScrollEnabled &&
290
- loadEarlierMessagesProps?.onPress &&
291
- loadEarlierMessagesProps?.isAvailable &&
292
- !loadEarlierMessagesProps?.isLoading
289
+ loadEarlierMessagesProps &&
290
+ loadEarlierMessagesProps.isAvailable &&
291
+ loadEarlierMessagesProps.isInfiniteScrollEnabled &&
292
+ !loadEarlierMessagesProps.isLoading
293
293
  )
294
294
  loadEarlierMessagesProps.onPress()
295
295
  }, [loadEarlierMessagesProps])
@@ -420,5 +420,3 @@ function MessageContainer<TMessage extends IMessage = IMessage> (props: MessageC
420
420
  </View>
421
421
  )
422
422
  }
423
-
424
- export default MessageContainer
@@ -1,5 +1,5 @@
1
1
  import { StyleSheet } from 'react-native'
2
- import Color from '../Color'
2
+ import { Color } from '../Color'
3
3
 
4
4
  export default StyleSheet.create({
5
5
  containerAlignTop: {
@@ -55,7 +55,8 @@ export const MessageText: React.FC<MessageTextProps<IMessage>> = ({
55
55
  <Autolink
56
56
  email
57
57
  phone
58
- link
58
+ url
59
+ stripPrefix={false}
59
60
  {...rest}
60
61
  onPress={onPressProp ? handlePress : undefined}
61
62
  linkStyle={linkStyle}
@@ -1,6 +1,6 @@
1
1
  import React, { useMemo } from 'react'
2
2
  import { View, Text, StyleSheet } from 'react-native'
3
- import Color from './Color'
3
+ import { Color } from './Color'
4
4
 
5
5
  const styles = StyleSheet.create({
6
6
  container: {
@@ -7,7 +7,7 @@ import {
7
7
  ViewStyle,
8
8
  TextStyle,
9
9
  } from 'react-native'
10
- import Color from './Color'
10
+ import { Color } from './Color'
11
11
  import { TouchableOpacity } from './components/TouchableOpacity'
12
12
  import { warning } from './logging'
13
13
  import stylesCommon from './styles'
package/src/Send.tsx CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  TextStyle,
9
9
  useColorScheme,
10
10
  } from 'react-native'
11
- import Color from './Color'
11
+ import { Color } from './Color'
12
12
 
13
13
  import { TouchableOpacity, TouchableOpacityProps } from './components/TouchableOpacity'
14
14
  import { TEST_ID } from './Constant'
@@ -1,29 +1,16 @@
1
- import React, { useMemo } from 'react'
1
+ import React from 'react'
2
2
  import {
3
3
  StyleSheet,
4
- Text,
5
4
  View,
6
5
  ViewStyle,
7
6
  StyleProp,
8
7
  TextStyle,
9
8
  } from 'react-native'
10
- import Color from './Color'
9
+ import { Color } from './Color'
10
+ import { MessageText } from './MessageText'
11
11
  import stylesCommon from './styles'
12
12
  import { IMessage } from './types'
13
13
 
14
- const styles = StyleSheet.create({
15
- container: {
16
- marginTop: 5,
17
- marginBottom: 10,
18
- },
19
- text: {
20
- backgroundColor: Color.backgroundTransparent,
21
- color: Color.defaultColor,
22
- fontSize: 12,
23
- fontWeight: '300',
24
- },
25
- })
26
-
27
14
  export interface SystemMessageProps<TMessage extends IMessage> {
28
15
  currentMessage: TMessage
29
16
  containerStyle?: StyleProp<ViewStyle>
@@ -39,22 +26,41 @@ export function SystemMessage<TMessage extends IMessage = IMessage> ({
39
26
  textStyle,
40
27
  children,
41
28
  }: SystemMessageProps<TMessage>) {
42
- const textContent = useMemo(() => {
43
- if (!currentMessage?.text)
44
- return null
45
-
46
- return <Text style={[styles.text, textStyle]}>{currentMessage.text}</Text>
47
- }, [currentMessage?.text, textStyle])
48
-
49
29
  if (currentMessage == null || currentMessage.system === false)
50
30
  return null
51
31
 
52
32
  return (
53
33
  <View style={[stylesCommon.fill, stylesCommon.centerItems, styles.container, containerStyle]}>
54
34
  <View style={wrapperStyle}>
55
- {textContent}
35
+ <MessageText
36
+ currentMessage={currentMessage}
37
+ customTextStyle={[styles.text, textStyle]}
38
+ containerStyle={{ left: styles.messageContainer, right: styles.messageContainer }}
39
+ />
56
40
  {children}
57
41
  </View>
58
42
  </View>
59
43
  )
60
44
  }
45
+
46
+ const styles = StyleSheet.create({
47
+ container: {
48
+ marginTop: 5,
49
+ marginBottom: 10,
50
+ marginHorizontal: 20,
51
+ },
52
+ messageContainer: {
53
+ borderRadius: 20,
54
+ borderWidth: 1,
55
+ borderColor: 'rgba(0,0,0,0.1)',
56
+ paddingHorizontal: 10,
57
+ paddingVertical: 10,
58
+ backgroundColor: 'rgba(0,0,0,0.05)',
59
+ },
60
+ text: {
61
+ backgroundColor: Color.backgroundTransparent,
62
+ fontStyle: 'italic',
63
+ fontSize: 12,
64
+ fontWeight: '300',
65
+ },
66
+ })