react-native-gifted-chat 2.4.0 → 2.5.1

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 (159) hide show
  1. package/README.md +16 -6
  2. package/lib/Actions.d.ts +5 -6
  3. package/lib/Actions.js +16 -13
  4. package/lib/Actions.js.map +1 -1
  5. package/lib/Avatar.d.ts +10 -24
  6. package/lib/Avatar.js +24 -35
  7. package/lib/Avatar.js.flow +1 -1
  8. package/lib/Avatar.js.map +1 -1
  9. package/lib/Bubble.d.ts +30 -29
  10. package/lib/Bubble.js +90 -72
  11. package/lib/Bubble.js.flow +3 -1
  12. package/lib/Bubble.js.map +1 -1
  13. package/lib/Composer.d.ts +1 -1
  14. package/lib/Composer.js +30 -32
  15. package/lib/Composer.js.map +1 -1
  16. package/lib/Constant.js +1 -0
  17. package/lib/Constant.js.map +1 -1
  18. package/lib/Day.d.ts +3 -15
  19. package/lib/Day.js +2 -14
  20. package/lib/Day.js.flow +1 -1
  21. package/lib/Day.js.map +1 -1
  22. package/lib/GiftedAvatar.d.ts +7 -7
  23. package/lib/GiftedAvatar.js +30 -29
  24. package/lib/GiftedAvatar.js.map +1 -1
  25. package/lib/GiftedChat.d.ts +16 -89
  26. package/lib/GiftedChat.js +204 -350
  27. package/lib/GiftedChat.js.flow +3 -3
  28. package/lib/GiftedChat.js.map +1 -1
  29. package/lib/GiftedChatContext.d.ts +2 -1
  30. package/lib/GiftedChatContext.js.map +1 -1
  31. package/lib/InputToolbar.d.ts +7 -5
  32. package/lib/InputToolbar.js +41 -34
  33. package/lib/InputToolbar.js.map +1 -1
  34. package/lib/LoadEarlier.d.ts +4 -4
  35. package/lib/LoadEarlier.js +8 -6
  36. package/lib/LoadEarlier.js.map +1 -1
  37. package/lib/Message.d.ts +8 -9
  38. package/lib/Message.js +47 -40
  39. package/lib/Message.js.flow +1 -1
  40. package/lib/Message.js.map +1 -1
  41. package/lib/MessageAudio.d.ts +2 -1
  42. package/lib/MessageAudio.js +4 -4
  43. package/lib/MessageAudio.js.flow +1 -1
  44. package/lib/MessageAudio.js.map +1 -1
  45. package/lib/MessageContainer.d.ts +17 -17
  46. package/lib/MessageContainer.js +33 -51
  47. package/lib/MessageContainer.js.map +1 -1
  48. package/lib/MessageImage.d.ts +8 -5
  49. package/lib/MessageImage.js +6 -6
  50. package/lib/MessageImage.js.flow +1 -1
  51. package/lib/MessageImage.js.map +1 -1
  52. package/lib/MessageText.d.ts +11 -10
  53. package/lib/MessageText.js +5 -10
  54. package/lib/MessageText.js.flow +1 -1
  55. package/lib/MessageText.js.map +1 -1
  56. package/lib/MessageVideo.d.ts +2 -1
  57. package/lib/MessageVideo.js +4 -4
  58. package/lib/MessageVideo.js.flow +1 -1
  59. package/lib/MessageVideo.js.map +1 -1
  60. package/lib/Models.d.ts +7 -7
  61. package/lib/QuickReplies.d.ts +4 -3
  62. package/lib/QuickReplies.js +10 -16
  63. package/lib/QuickReplies.js.flow +4 -2
  64. package/lib/QuickReplies.js.map +1 -1
  65. package/lib/Send.d.ts +4 -4
  66. package/lib/Send.js +6 -9
  67. package/lib/Send.js.map +1 -1
  68. package/lib/SystemMessage.d.ts +6 -5
  69. package/lib/SystemMessage.js +1 -2
  70. package/lib/SystemMessage.js.flow +1 -1
  71. package/lib/SystemMessage.js.map +1 -1
  72. package/lib/Time.d.ts +7 -6
  73. package/lib/Time.js +1 -3
  74. package/lib/Time.js.flow +1 -1
  75. package/lib/Time.js.map +1 -1
  76. package/lib/TypingIndicator.d.ts +2 -1
  77. package/lib/TypingIndicator.js +5 -5
  78. package/lib/TypingIndicator.js.map +1 -1
  79. package/lib/hooks/useUpdateLayoutEffect.js +2 -4
  80. package/lib/hooks/useUpdateLayoutEffect.js.map +1 -1
  81. package/lib/index.d.ts +1 -0
  82. package/lib/index.js +1 -0
  83. package/lib/index.js.map +1 -1
  84. package/lib/logging.d.ts +2 -2
  85. package/lib/logging.js.map +1 -1
  86. package/lib/types.js.flow +1 -1
  87. package/lib/utils.d.ts +1 -1
  88. package/lib/utils.js +2 -4
  89. package/lib/utils.js.map +1 -1
  90. package/package.json +83 -53
  91. package/src/Actions.tsx +114 -0
  92. package/src/Avatar.tsx +178 -0
  93. package/src/Bubble.tsx +601 -0
  94. package/src/Color.ts +17 -0
  95. package/src/Composer.tsx +147 -0
  96. package/src/Constant.ts +18 -0
  97. package/src/Day.tsx +71 -0
  98. package/src/GiftedAvatar.tsx +205 -0
  99. package/src/GiftedChat.tsx +670 -0
  100. package/src/GiftedChatContext.ts +23 -0
  101. package/src/InputToolbar.tsx +113 -0
  102. package/src/LoadEarlier.tsx +108 -0
  103. package/src/Message.tsx +229 -0
  104. package/src/MessageAudio.tsx +19 -0
  105. package/src/MessageContainer.tsx +362 -0
  106. package/src/MessageImage.tsx +78 -0
  107. package/src/MessageText.tsx +187 -0
  108. package/src/MessageVideo.tsx +19 -0
  109. package/src/Models.ts +84 -0
  110. package/src/QuickReplies.tsx +186 -0
  111. package/src/Send.tsx +102 -0
  112. package/src/SystemMessage.tsx +61 -0
  113. package/src/Time.tsx +97 -0
  114. package/src/TypingIndicator.tsx +108 -0
  115. package/src/__tests__/Actions.test.tsx +10 -0
  116. package/src/__tests__/Avatar.test.tsx +13 -0
  117. package/src/__tests__/Bubble.test.tsx +23 -0
  118. package/src/__tests__/Color.test.tsx +5 -0
  119. package/src/__tests__/Composer.test.tsx +11 -0
  120. package/src/__tests__/Constant.test.tsx +5 -0
  121. package/src/__tests__/Day.test.tsx +23 -0
  122. package/src/__tests__/GiftedAvatar.test.tsx +11 -0
  123. package/src/__tests__/GiftedChat.test.tsx +36 -0
  124. package/src/__tests__/InputToolbar.test.tsx +11 -0
  125. package/src/__tests__/LoadEarlier.test.tsx +11 -0
  126. package/src/__tests__/Message.test.tsx +77 -0
  127. package/src/__tests__/MessageContainer.test.tsx +11 -0
  128. package/src/__tests__/MessageImage.test.tsx +27 -0
  129. package/src/__tests__/MessageText.test.tsx +11 -0
  130. package/src/__tests__/Send.test.tsx +22 -0
  131. package/src/__tests__/SystemMessage.test.tsx +27 -0
  132. package/src/__tests__/Time.test.tsx +29 -0
  133. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +76 -0
  134. package/src/__tests__/__snapshots__/Avatar.test.tsx.snap +17 -0
  135. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +145 -0
  136. package/src/__tests__/__snapshots__/Color.test.tsx.snap +21 -0
  137. package/src/__tests__/__snapshots__/Composer.test.tsx.snap +35 -0
  138. package/src/__tests__/__snapshots__/Constant.test.tsx.snap +16 -0
  139. package/src/__tests__/__snapshots__/Day.test.tsx.snap +37 -0
  140. package/src/__tests__/__snapshots__/GiftedAvatar.test.tsx.snap +22 -0
  141. package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +15 -0
  142. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +60 -0
  143. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +74 -0
  144. package/src/__tests__/__snapshots__/Message.test.tsx.snap +628 -0
  145. package/src/__tests__/__snapshots__/MessageContainer.test.tsx.snap +127 -0
  146. package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +38 -0
  147. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +30 -0
  148. package/src/__tests__/__snapshots__/Send.test.tsx.snap +129 -0
  149. package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +38 -0
  150. package/src/__tests__/__snapshots__/Time.test.tsx.snap +33 -0
  151. package/src/__tests__/data.ts +8 -0
  152. package/src/__tests__/utils.test.ts +31 -0
  153. package/src/hooks/useUpdateLayoutEffect.ts +21 -0
  154. package/src/index.ts +4 -0
  155. package/src/logging.ts +8 -0
  156. package/src/utils.ts +39 -0
  157. package/.eslintignore +0 -2
  158. package/.eslintrc.js +0 -21
  159. package/jest.config.js +0 -15
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "react-native-gifted-chat",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "description": "The most complete chat UI for React Native",
5
- "main": "lib/index.js",
6
- "types": "lib/index.d.ts",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/FaridSafi/react-native-gifted-chat.git"
10
- },
11
5
  "keywords": [
12
6
  "android",
13
7
  "ios",
@@ -18,72 +12,108 @@
18
12
  "message",
19
13
  "chat"
20
14
  ],
21
- "author": "Farid Safi",
22
- "license": "MIT",
15
+ "homepage": "https://github.com/FaridSafi/react-native-gifted-chat#readme",
23
16
  "bugs": {
24
17
  "url": "https://github.com/FaridSafi/react-native-gifted-chat/issues"
25
18
  },
26
- "homepage": "https://github.com/FaridSafi/react-native-gifted-chat#readme",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/FaridSafi/react-native-gifted-chat.git"
22
+ },
23
+ "license": "MIT",
24
+ "author": "Farid Safi",
25
+ "type": "module",
26
+ "main": "lib/index.js",
27
+ "types": "lib/index.d.ts",
28
+ "files": [
29
+ "src",
30
+ "lib"
31
+ ],
27
32
  "scripts": {
28
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
29
- "lint:fix": "./node_modules/.bin/eslint ./src/*.{ts,tsx} --fix",
30
- "tsc": "node_modules/.bin/tsc --noEmit",
31
- "tsc:watch": "node_modules/.bin/tsc --watch --noEmit",
33
+ "build": "rm -rf lib/ && yarn tsc && cp flow-typedefs/*.js.flow lib/",
34
+ "lint": "yarn eslint src",
35
+ "lint:fix": "yarn eslint --cache --fix",
36
+ "prepublishOnly": "yarn lint && yarn build && yarn test",
32
37
  "start": "cd example && expo start",
33
38
  "start:web": "cd example && expo start -w --dev",
34
- "build": "rm -rf lib/ && node_modules/.bin/tsc && cp flow-typedefs/*.js.flow lib/",
35
39
  "test": "TZ=Europe/Paris jest --no-watchman",
36
- "test:watch": "TZ=Europe/Paris jest --watch",
37
40
  "test:coverage": "TZ=Europe/Paris jest --coverage",
38
- "prepublishOnly": "yarn lint && yarn build && yarn test",
39
- "prettier": "./node_modules/.bin/prettier --write \"src/**/*.{ts,tsx}\""
41
+ "test:watch": "TZ=Europe/Paris jest --watch",
42
+ "tsc:write": "yarn tsc --project tsconfig.json",
43
+ "tsc:watch": "yarn tsc --watch --noEmit",
44
+ "fresh": "yarn start --reset-cache",
45
+ "prepare": "yarn husky"
40
46
  },
41
- "devDependencies": {
42
- "@babel/core": "7.17.9",
43
- "@babel/plugin-transform-flow-strip-types": "7.16.7",
44
- "@babel/preset-env": "7.16.11",
45
- "@babel/preset-typescript": "7.16.7",
46
- "@types/jest": "27.4.1",
47
- "@types/react": "~16.9.35",
48
- "@types/react-native": "~0.63.2",
49
- "@types/react-test-renderer": "16.9.2",
50
- "@types/uuid": "3.4.9",
51
- "@typescript-eslint/eslint-plugin": "5.18.0",
52
- "@typescript-eslint/parser": "5.18.0",
53
- "babel-jest": "27.5.1",
54
- "eslint": "8.13.0",
55
- "eslint-config-prettier": "8.5.0",
56
- "flow-bin": "0.125.0",
57
- "husky": "4.2.5",
58
- "jest": "27.5.1",
59
- "json": "9.0.6",
60
- "metro-react-native-babel-preset": "0.70.1",
61
- "prettier": "2.0.5",
62
- "react": "16.13.1",
63
- "react-dom": "16.13.1",
64
- "react-native": "0.63.4",
65
- "react-test-renderer": "16.9.0",
66
- "typescript": "4.6.3"
47
+ "lint-staged": {
48
+ "src/*.{json,js,jsx,ts,tsx}": [
49
+ "yarn lint:fix",
50
+ "bash -c 'yarn tsc:write'"
51
+ ]
67
52
  },
68
53
  "dependencies": {
69
- "@expo/react-native-action-sheet": "4.0.1",
70
- "dayjs": "1.8.26",
71
- "prop-types": "15.7.2",
54
+ "@expo/react-native-action-sheet": "4.1.0",
55
+ "@types/lodash.isequal": "^4.5.8",
56
+ "dayjs": "1.11.13",
57
+ "expo-clipboard": "^6.0.3",
58
+ "lodash.isequal": "^4.5.0",
59
+ "prop-types": "15.8.1",
72
60
  "react-native-communications": "2.2.1",
61
+ "react-native-get-random-values": "^1.11.0",
73
62
  "react-native-iphone-x-helper": "1.3.1",
74
63
  "react-native-lightbox-v2": "0.9.0",
75
64
  "react-native-parsed-text": "0.0.22",
65
+ "react-native-reanimated": "^3.15.0",
66
+ "react-native-safe-area-context": "^4.10.9",
76
67
  "react-native-typing-animation": "0.1.7",
77
68
  "use-memo-one": "1.1.3",
78
- "uuid": "3.4.0"
69
+ "uuid": "10.0.0"
70
+ },
71
+ "devDependencies": {
72
+ "@babel/core": "^7.25.2",
73
+ "@babel/plugin-transform-react-jsx": "^7.25.2",
74
+ "@babel/plugin-transform-unicode-property-regex": "^7.24.7",
75
+ "@babel/preset-env": "^7.25.4",
76
+ "@react-native/eslint-config": "^0.74.82",
77
+ "@stylistic/eslint-plugin": "^2.6.4",
78
+ "@types/jest": "^29.5.12",
79
+ "@types/react": "~18.3.3",
80
+ "@types/react-native": "~0.72.8",
81
+ "@types/react-test-renderer": "18.3.0",
82
+ "@types/uuid": "10.0.0",
83
+ "@typescript-eslint/eslint-plugin": "^8.2.0",
84
+ "@typescript-eslint/parser": "^8.2.0",
85
+ "babel-jest": "^29.7.0",
86
+ "eslint": "^8.57.0",
87
+ "eslint-config-standard": "^17.1.0",
88
+ "eslint-config-standard-jsx": "^11.0.0",
89
+ "eslint-plugin-import": "^2.29.1",
90
+ "eslint-plugin-jest": "^28.8.0",
91
+ "eslint-plugin-json": "^4.0.1",
92
+ "eslint-plugin-n": "^17.10.2",
93
+ "eslint-plugin-node": "^11.1.0",
94
+ "eslint-plugin-promise": "^7.1.0",
95
+ "eslint-plugin-react": "^7.35.0",
96
+ "flow-bin": "0.244.0",
97
+ "husky": "9.1.5",
98
+ "jest": "29.7.0",
99
+ "json": "11.0.0",
100
+ "lint-staged": "^15.2.9",
101
+ "react": "18.3.1",
102
+ "react-dom": "18.3.1",
103
+ "react-native": "0.74.5",
104
+ "react-test-renderer": "18.3.1",
105
+ "typescript": "5.5.4"
79
106
  },
80
107
  "peerDependencies": {
108
+ "lodash.isequal": "*",
81
109
  "react": "*",
82
- "react-native": "*"
110
+ "react-native": "*",
111
+ "react-native-get-random-values": "*",
112
+ "react-native-reanimated": "*",
113
+ "react-native-safe-area-context": "*"
83
114
  },
84
- "husky": {
85
- "hooks": {
86
- "pre-commit": "yarn lint:fix && yarn prettier && yarn tsc"
87
- }
115
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e",
116
+ "engines": {
117
+ "node": ">=18"
88
118
  }
89
119
  }
@@ -0,0 +1,114 @@
1
+ import PropTypes from 'prop-types'
2
+ import React, { ReactNode, useCallback } from 'react'
3
+ import {
4
+ StyleSheet,
5
+ Text,
6
+ TouchableOpacity,
7
+ View,
8
+ StyleProp,
9
+ ViewStyle,
10
+ TextStyle,
11
+ } from 'react-native'
12
+ import Color from './Color'
13
+ import { StylePropType } from './utils'
14
+ import { useChatContext } from './GiftedChatContext'
15
+
16
+ export interface ActionsProps {
17
+ options?: { [key: string]: () => void }
18
+ optionTintColor?: string
19
+ icon?: () => ReactNode
20
+ wrapperStyle?: StyleProp<ViewStyle>
21
+ iconTextStyle?: StyleProp<TextStyle>
22
+ containerStyle?: StyleProp<ViewStyle>
23
+ onPressActionButton?(): void
24
+ }
25
+
26
+ export function Actions ({
27
+ options,
28
+ optionTintColor = Color.optionTintColor,
29
+ icon,
30
+ wrapperStyle,
31
+ iconTextStyle,
32
+ onPressActionButton,
33
+ containerStyle,
34
+ }: ActionsProps) {
35
+ const { actionSheet } = useChatContext()
36
+
37
+ const onActionsPress = useCallback(() => {
38
+ if (!options)
39
+ return
40
+
41
+ const optionKeys = Object.keys(options)
42
+ const cancelButtonIndex = optionKeys.indexOf('Cancel')
43
+
44
+ actionSheet().showActionSheetWithOptions(
45
+ {
46
+ options: optionKeys,
47
+ cancelButtonIndex,
48
+ tintColor: optionTintColor,
49
+ },
50
+ (buttonIndex: number | undefined) => {
51
+ if (buttonIndex === undefined)
52
+ return
53
+
54
+ const key = optionKeys[buttonIndex]
55
+ if (key)
56
+ options[key]()
57
+ }
58
+ )
59
+ }, [actionSheet, options, optionTintColor])
60
+
61
+ const renderIcon = useCallback(() => {
62
+ if (icon)
63
+ return icon()
64
+
65
+ return (
66
+ <View style={[styles.wrapper, wrapperStyle]}>
67
+ <Text style={[styles.iconText, iconTextStyle]}>{'+'}</Text>
68
+ </View>
69
+ )
70
+ }, [icon, iconTextStyle, wrapperStyle])
71
+
72
+ return (
73
+ <TouchableOpacity
74
+ style={[styles.container, containerStyle]}
75
+ onPress={onPressActionButton || onActionsPress}
76
+ >
77
+ {renderIcon()}
78
+ </TouchableOpacity>
79
+ )
80
+ }
81
+
82
+ Actions.propTypes = {
83
+ options: PropTypes.object,
84
+ optionTintColor: PropTypes.string,
85
+ icon: PropTypes.func,
86
+ onPressActionButton: PropTypes.func,
87
+ wrapperStyle: StylePropType,
88
+ containerStyle: StylePropType,
89
+ }
90
+
91
+ const styles = StyleSheet.create({
92
+ container: {
93
+ width: 26,
94
+ height: 26,
95
+ marginLeft: 10,
96
+ marginBottom: 10,
97
+ },
98
+ wrapper: {
99
+ borderRadius: 13,
100
+ borderColor: Color.defaultColor,
101
+ borderWidth: 2,
102
+ flex: 1,
103
+ alignItems: 'center',
104
+ justifyContent: 'center',
105
+ },
106
+ iconText: {
107
+ color: Color.defaultColor,
108
+ fontWeight: 'bold',
109
+ fontSize: 16,
110
+ lineHeight: 16,
111
+ backgroundColor: Color.backgroundTransparent,
112
+ textAlign: 'center',
113
+ },
114
+ })
package/src/Avatar.tsx ADDED
@@ -0,0 +1,178 @@
1
+ import PropTypes from 'prop-types'
2
+ import React, { ReactNode } from 'react'
3
+ import {
4
+ ImageStyle,
5
+ StyleSheet,
6
+ TextStyle,
7
+ View,
8
+ ViewStyle,
9
+ } from 'react-native'
10
+ import GiftedAvatar from './GiftedAvatar'
11
+ import { StylePropType, isSameUser, isSameDay } from './utils'
12
+ import { IMessage, LeftRightStyle, User } from './Models'
13
+
14
+ interface Styles {
15
+ left: {
16
+ container: ViewStyle
17
+ onTop: ViewStyle
18
+ image: ImageStyle
19
+ }
20
+ right: {
21
+ container: ViewStyle
22
+ onTop: ViewStyle
23
+ image: ImageStyle
24
+ }
25
+ }
26
+
27
+ const styles: Styles = {
28
+ left: StyleSheet.create({
29
+ container: {
30
+ marginRight: 8,
31
+ },
32
+ onTop: {
33
+ alignSelf: 'flex-start',
34
+ },
35
+ image: {
36
+ height: 36,
37
+ width: 36,
38
+ borderRadius: 18,
39
+ },
40
+ }),
41
+ right: StyleSheet.create({
42
+ container: {
43
+ marginLeft: 8,
44
+ },
45
+ onTop: {
46
+ alignSelf: 'flex-start',
47
+ },
48
+ image: {
49
+ height: 36,
50
+ width: 36,
51
+ borderRadius: 18,
52
+ },
53
+ }),
54
+ }
55
+
56
+ export interface AvatarProps<TMessage extends IMessage> {
57
+ currentMessage: TMessage
58
+ previousMessage?: TMessage
59
+ nextMessage?: TMessage
60
+ position: 'left' | 'right'
61
+ renderAvatarOnTop?: boolean
62
+ showAvatarForEveryMessage?: boolean
63
+ imageStyle?: LeftRightStyle<ImageStyle>
64
+ containerStyle?: LeftRightStyle<ViewStyle>
65
+ textStyle?: TextStyle
66
+ renderAvatar?(props: Omit<AvatarProps<TMessage>, 'renderAvatar'>): ReactNode
67
+ onPressAvatar?: (user: User) => void
68
+ onLongPressAvatar?: (user: User) => void
69
+ }
70
+
71
+ export function Avatar<TMessage extends IMessage = IMessage> (
72
+ props: AvatarProps<TMessage>
73
+ ) {
74
+ const {
75
+ renderAvatarOnTop,
76
+ showAvatarForEveryMessage,
77
+ containerStyle,
78
+ position,
79
+ currentMessage,
80
+ renderAvatar,
81
+ previousMessage,
82
+ nextMessage,
83
+ imageStyle,
84
+ onPressAvatar,
85
+ onLongPressAvatar,
86
+ } = props
87
+
88
+ const messageToCompare = renderAvatarOnTop ? previousMessage : nextMessage
89
+
90
+ if (renderAvatar === null)
91
+ return null
92
+
93
+ if (
94
+ !showAvatarForEveryMessage &&
95
+ currentMessage &&
96
+ messageToCompare &&
97
+ isSameUser(currentMessage, messageToCompare) &&
98
+ isSameDay(currentMessage, messageToCompare)
99
+ )
100
+ return (
101
+ <View
102
+ style={[
103
+ styles[position].container,
104
+ containerStyle?.[position],
105
+ ]}
106
+ >
107
+ <GiftedAvatar
108
+ avatarStyle={[
109
+ styles[position].image,
110
+ imageStyle?.[position],
111
+ ]}
112
+ />
113
+ </View>
114
+ )
115
+
116
+ const renderAvatarComponent = () => {
117
+ if (renderAvatar)
118
+ return renderAvatar({
119
+ renderAvatarOnTop,
120
+ showAvatarForEveryMessage,
121
+ containerStyle,
122
+ position,
123
+ currentMessage,
124
+ previousMessage,
125
+ nextMessage,
126
+ imageStyle,
127
+ onPressAvatar,
128
+ onLongPressAvatar,
129
+ })
130
+
131
+ if (currentMessage)
132
+ return (
133
+ <GiftedAvatar
134
+ avatarStyle={[
135
+ styles[position].image,
136
+ imageStyle?.[position],
137
+ ]}
138
+ user={currentMessage.user}
139
+ onPress={() => onPressAvatar?.(currentMessage.user)}
140
+ onLongPress={() => onLongPressAvatar?.(currentMessage.user)}
141
+ />
142
+ )
143
+
144
+ return null
145
+ }
146
+
147
+ return (
148
+ <View
149
+ style={[
150
+ styles[position].container,
151
+ renderAvatarOnTop && styles[position].onTop,
152
+ containerStyle?.[position],
153
+ ]}
154
+ >
155
+ {renderAvatarComponent()}
156
+ </View>
157
+ )
158
+ }
159
+
160
+ Avatar.propTypes = {
161
+ renderAvatarOnTop: PropTypes.bool,
162
+ showAvatarForEveryMessage: PropTypes.bool,
163
+ position: PropTypes.oneOf(['left', 'right']),
164
+ currentMessage: PropTypes.object,
165
+ previousMessage: PropTypes.object,
166
+ nextMessage: PropTypes.object,
167
+ onPressAvatar: PropTypes.func,
168
+ onLongPressAvatar: PropTypes.func,
169
+ renderAvatar: PropTypes.func,
170
+ containerStyle: PropTypes.shape({
171
+ left: StylePropType,
172
+ right: StylePropType,
173
+ }),
174
+ imageStyle: PropTypes.shape({
175
+ left: StylePropType,
176
+ right: StylePropType,
177
+ }),
178
+ }