react-native-gifted-chat 3.3.2 → 3.4.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 (325) hide show
  1. package/README.md +30 -2
  2. package/lib/Actions.d.ts +16 -0
  3. package/lib/Actions.d.ts.map +1 -0
  4. package/lib/Actions.js +64 -0
  5. package/lib/Actions.js.map +1 -0
  6. package/lib/Avatar.d.ts +19 -0
  7. package/lib/Avatar.d.ts.map +1 -0
  8. package/lib/Avatar.js +93 -0
  9. package/lib/Avatar.js.map +1 -0
  10. package/lib/Bubble/index.d.ts +6 -0
  11. package/lib/Bubble/index.d.ts.map +1 -0
  12. package/lib/Bubble/index.js +268 -0
  13. package/lib/Bubble/index.js.map +1 -0
  14. package/lib/Bubble/styles.d.ts +57 -0
  15. package/lib/Bubble/styles.d.ts.map +1 -0
  16. package/lib/Bubble/styles.js +59 -0
  17. package/lib/Bubble/styles.js.map +1 -0
  18. package/lib/Bubble/types.d.ts +59 -0
  19. package/lib/Bubble/types.d.ts.map +1 -0
  20. package/lib/Bubble/types.js +2 -0
  21. package/lib/Bubble/types.js.map +1 -0
  22. package/lib/Color.d.ts +18 -0
  23. package/lib/Color.d.ts.map +1 -0
  24. package/lib/Color.js +18 -0
  25. package/lib/Color.js.map +1 -0
  26. package/lib/Composer.d.ts +9 -0
  27. package/lib/Composer.d.ts.map +1 -0
  28. package/lib/Composer.js +56 -0
  29. package/lib/Composer.js.map +1 -0
  30. package/lib/Constant.d.ts +8 -0
  31. package/lib/Constant.d.ts.map +1 -0
  32. package/lib/Constant.js +8 -0
  33. package/lib/Constant.js.map +1 -0
  34. package/lib/Day/index.d.ts +5 -0
  35. package/lib/Day/index.d.ts.map +1 -0
  36. package/lib/Day/index.js +39 -0
  37. package/lib/Day/index.js.map +1 -0
  38. package/lib/Day/styles.d.ts +21 -0
  39. package/lib/Day/styles.d.ts.map +1 -0
  40. package/lib/Day/styles.js +22 -0
  41. package/lib/Day/styles.js.map +1 -0
  42. package/lib/Day/types.d.ts +11 -0
  43. package/lib/Day/types.d.ts.map +1 -0
  44. package/lib/Day/types.js +2 -0
  45. package/lib/Day/types.js.map +1 -0
  46. package/lib/GiftedAvatar.d.ts +12 -0
  47. package/lib/GiftedAvatar.d.ts.map +1 -0
  48. package/lib/GiftedAvatar.js +100 -0
  49. package/lib/GiftedAvatar.js.map +1 -0
  50. package/lib/GiftedChat/index.d.ts +10 -0
  51. package/lib/GiftedChat/index.d.ts.map +1 -0
  52. package/lib/GiftedChat/index.js +240 -0
  53. package/lib/GiftedChat/index.js.map +1 -0
  54. package/lib/GiftedChat/styles.d.ts +13 -0
  55. package/lib/GiftedChat/styles.d.ts.map +1 -0
  56. package/lib/GiftedChat/styles.js +13 -0
  57. package/lib/GiftedChat/styles.js.map +1 -0
  58. package/lib/GiftedChat/types.d.ts +90 -0
  59. package/lib/GiftedChat/types.d.ts.map +1 -0
  60. package/lib/GiftedChat/types.js +2 -0
  61. package/lib/GiftedChat/types.js.map +1 -0
  62. package/lib/GiftedChatContext.d.ts +12 -0
  63. package/lib/GiftedChatContext.d.ts.map +1 -0
  64. package/lib/GiftedChatContext.js +10 -0
  65. package/lib/GiftedChatContext.js.map +1 -0
  66. package/lib/InputToolbar.d.ts +36 -0
  67. package/lib/InputToolbar.d.ts.map +1 -0
  68. package/lib/InputToolbar.js +108 -0
  69. package/lib/InputToolbar.js.map +1 -0
  70. package/lib/LoadEarlierMessages.d.ts +17 -0
  71. package/lib/LoadEarlierMessages.d.ts.map +1 -0
  72. package/lib/LoadEarlierMessages.js +44 -0
  73. package/lib/LoadEarlierMessages.js.map +1 -0
  74. package/lib/Message/index.d.ts +6 -0
  75. package/lib/Message/index.d.ts.map +1 -0
  76. package/lib/Message/index.js +180 -0
  77. package/lib/Message/index.js.map +1 -0
  78. package/lib/Message/styles.d.ts +18 -0
  79. package/lib/Message/styles.d.ts.map +1 -0
  80. package/lib/Message/styles.js +18 -0
  81. package/lib/Message/styles.js.map +1 -0
  82. package/lib/Message/types.d.ts +25 -0
  83. package/lib/Message/types.d.ts.map +1 -0
  84. package/lib/Message/types.js +2 -0
  85. package/lib/Message/types.js.map +1 -0
  86. package/lib/MessageAudio.d.ts +3 -0
  87. package/lib/MessageAudio.d.ts.map +1 -0
  88. package/lib/MessageAudio.js +24 -0
  89. package/lib/MessageAudio.js.map +1 -0
  90. package/lib/MessageImage.d.ts +12 -0
  91. package/lib/MessageImage.d.ts.map +1 -0
  92. package/lib/MessageImage.js +164 -0
  93. package/lib/MessageImage.js.map +1 -0
  94. package/lib/MessageReply.d.ts +15 -0
  95. package/lib/MessageReply.d.ts.map +1 -0
  96. package/lib/MessageReply.js +102 -0
  97. package/lib/MessageReply.js.map +1 -0
  98. package/lib/MessageText.d.ts +24 -0
  99. package/lib/MessageText.d.ts.map +1 -0
  100. package/lib/MessageText.js +40 -0
  101. package/lib/MessageText.js.map +1 -0
  102. package/lib/MessageVideo.d.ts +3 -0
  103. package/lib/MessageVideo.d.ts.map +1 -0
  104. package/lib/MessageVideo.js +24 -0
  105. package/lib/MessageVideo.js.map +1 -0
  106. package/lib/MessagesContainer/components/DayAnimated/index.d.ts +5 -0
  107. package/lib/MessagesContainer/components/DayAnimated/index.d.ts.map +1 -0
  108. package/lib/MessagesContainer/components/DayAnimated/index.js +92 -0
  109. package/lib/MessagesContainer/components/DayAnimated/index.js.map +1 -0
  110. package/lib/MessagesContainer/components/DayAnimated/styles.d.ts +12 -0
  111. package/lib/MessagesContainer/components/DayAnimated/styles.d.ts.map +1 -0
  112. package/lib/MessagesContainer/components/DayAnimated/styles.js +12 -0
  113. package/lib/MessagesContainer/components/DayAnimated/styles.js.map +1 -0
  114. package/lib/MessagesContainer/components/DayAnimated/types.d.ts +18 -0
  115. package/lib/MessagesContainer/components/DayAnimated/types.d.ts.map +1 -0
  116. package/lib/MessagesContainer/components/DayAnimated/types.js +2 -0
  117. package/lib/MessagesContainer/components/DayAnimated/types.js.map +1 -0
  118. package/lib/MessagesContainer/components/Item/index.d.ts +23 -0
  119. package/lib/MessagesContainer/components/Item/index.d.ts.map +1 -0
  120. package/lib/MessagesContainer/components/Item/index.js +120 -0
  121. package/lib/MessagesContainer/components/Item/index.js.map +1 -0
  122. package/lib/MessagesContainer/components/Item/types.d.ts +19 -0
  123. package/lib/MessagesContainer/components/Item/types.d.ts.map +1 -0
  124. package/lib/MessagesContainer/components/Item/types.js +2 -0
  125. package/lib/MessagesContainer/components/Item/types.js.map +1 -0
  126. package/lib/MessagesContainer/index.d.ts +6 -0
  127. package/lib/MessagesContainer/index.d.ts.map +1 -0
  128. package/lib/MessagesContainer/index.js +258 -0
  129. package/lib/MessagesContainer/index.js.map +1 -0
  130. package/lib/MessagesContainer/styles.d.ts +55 -0
  131. package/lib/MessagesContainer/styles.d.ts.map +1 -0
  132. package/lib/MessagesContainer/styles.js +42 -0
  133. package/lib/MessagesContainer/styles.js.map +1 -0
  134. package/lib/MessagesContainer/types.d.ts +88 -0
  135. package/lib/MessagesContainer/types.d.ts.map +1 -0
  136. package/lib/MessagesContainer/types.js +10 -0
  137. package/lib/MessagesContainer/types.js.map +1 -0
  138. package/lib/Models.d.ts +58 -0
  139. package/lib/Models.d.ts.map +1 -0
  140. package/lib/Models.js +2 -0
  141. package/lib/Models.js.map +1 -0
  142. package/lib/QuickReplies.d.ts +16 -0
  143. package/lib/QuickReplies.d.ts.map +1 -0
  144. package/lib/QuickReplies.js +107 -0
  145. package/lib/QuickReplies.js.map +1 -0
  146. package/lib/Reply/index.d.ts +2 -0
  147. package/lib/Reply/index.d.ts.map +1 -0
  148. package/lib/Reply/index.js +2 -0
  149. package/lib/Reply/index.js.map +1 -0
  150. package/lib/Reply/types.d.ts +72 -0
  151. package/lib/Reply/types.d.ts.map +1 -0
  152. package/lib/Reply/types.js +2 -0
  153. package/lib/Reply/types.js.map +1 -0
  154. package/lib/ReplyPreview.d.ts +14 -0
  155. package/lib/ReplyPreview.d.ts.map +1 -0
  156. package/lib/ReplyPreview.js +94 -0
  157. package/lib/ReplyPreview.js.map +1 -0
  158. package/lib/Send.d.ts +19 -0
  159. package/lib/Send.d.ts.map +1 -0
  160. package/lib/Send.js +56 -0
  161. package/lib/Send.js.map +1 -0
  162. package/lib/SystemMessage.d.ts +14 -0
  163. package/lib/SystemMessage.d.ts.map +1 -0
  164. package/lib/SystemMessage.js +42 -0
  165. package/lib/SystemMessage.js.map +1 -0
  166. package/lib/Time.d.ts +12 -0
  167. package/lib/Time.d.ts.map +1 -0
  168. package/lib/Time.js +38 -0
  169. package/lib/Time.js.map +1 -0
  170. package/lib/TypingIndicator/index.d.ts +5 -0
  171. package/lib/TypingIndicator/index.d.ts.map +1 -0
  172. package/lib/TypingIndicator/index.js +94 -0
  173. package/lib/TypingIndicator/index.js.map +1 -0
  174. package/lib/TypingIndicator/styles.d.ts +21 -0
  175. package/lib/TypingIndicator/styles.d.ts.map +1 -0
  176. package/lib/TypingIndicator/styles.js +22 -0
  177. package/lib/TypingIndicator/styles.js.map +1 -0
  178. package/lib/TypingIndicator/types.d.ts +6 -0
  179. package/lib/TypingIndicator/types.d.ts.map +1 -0
  180. package/lib/TypingIndicator/types.js +2 -0
  181. package/lib/TypingIndicator/types.js.map +1 -0
  182. package/lib/components/MessageReply.d.ts +29 -0
  183. package/lib/components/MessageReply.d.ts.map +1 -0
  184. package/lib/components/MessageReply.js +87 -0
  185. package/lib/components/MessageReply.js.map +1 -0
  186. package/lib/components/ReplyPreview.d.ts +17 -0
  187. package/lib/components/ReplyPreview.d.ts.map +1 -0
  188. package/lib/components/ReplyPreview.js +148 -0
  189. package/lib/components/ReplyPreview.js.map +1 -0
  190. package/lib/components/TouchableOpacity.d.ts +9 -0
  191. package/lib/components/TouchableOpacity.d.ts.map +1 -0
  192. package/lib/components/TouchableOpacity.js +47 -0
  193. package/lib/components/TouchableOpacity.js.map +1 -0
  194. package/lib/hooks/useColorScheme.d.ts +8 -0
  195. package/lib/hooks/useColorScheme.d.ts.map +1 -0
  196. package/lib/hooks/useColorScheme.js +17 -0
  197. package/lib/hooks/useColorScheme.js.map +1 -0
  198. package/lib/hooks/useUpdateLayoutEffect.d.ts +9 -0
  199. package/lib/hooks/useUpdateLayoutEffect.d.ts.map +1 -0
  200. package/lib/hooks/useUpdateLayoutEffect.js +17 -0
  201. package/lib/hooks/useUpdateLayoutEffect.js.map +1 -0
  202. package/lib/index.d.ts +31 -0
  203. package/lib/index.d.ts.map +1 -0
  204. package/lib/index.js +31 -0
  205. package/lib/index.js.map +1 -0
  206. package/lib/linkParser.d.ts +39 -0
  207. package/lib/linkParser.d.ts.map +1 -0
  208. package/lib/linkParser.js +154 -0
  209. package/lib/linkParser.js.map +1 -0
  210. package/lib/logging.d.ts +3 -0
  211. package/lib/logging.d.ts.map +1 -0
  212. package/lib/logging.js +5 -0
  213. package/lib/logging.js.map +1 -0
  214. package/lib/styles.d.ts +14 -0
  215. package/lib/styles.d.ts.map +1 -0
  216. package/lib/styles.js +23 -0
  217. package/lib/styles.js.map +1 -0
  218. package/lib/types.d.ts +19 -0
  219. package/lib/types.d.ts.map +1 -0
  220. package/lib/types.js +2 -0
  221. package/lib/types.js.map +1 -0
  222. package/lib/utils.d.ts +8 -0
  223. package/lib/utils.d.ts.map +1 -0
  224. package/lib/utils.js +105 -0
  225. package/lib/utils.js.map +1 -0
  226. package/package.json +43 -41
  227. package/src/Actions.tsx +0 -110
  228. package/src/Avatar.tsx +0 -169
  229. package/src/Bubble/index.tsx +0 -407
  230. package/src/Bubble/styles.ts +0 -66
  231. package/src/Bubble/types.ts +0 -104
  232. package/src/Color.ts +0 -17
  233. package/src/Composer.tsx +0 -100
  234. package/src/Constant.ts +0 -8
  235. package/src/Day/index.tsx +0 -63
  236. package/src/Day/styles.ts +0 -22
  237. package/src/Day/types.ts +0 -15
  238. package/src/GiftedAvatar.tsx +0 -187
  239. package/src/GiftedChat/index.tsx +0 -397
  240. package/src/GiftedChat/styles.ts +0 -13
  241. package/src/GiftedChat/types.ts +0 -156
  242. package/src/GiftedChatContext.ts +0 -25
  243. package/src/InputToolbar.tsx +0 -177
  244. package/src/LoadEarlierMessages.tsx +0 -94
  245. package/src/Message/index.tsx +0 -273
  246. package/src/Message/styles.ts +0 -18
  247. package/src/Message/types.ts +0 -26
  248. package/src/MessageAudio.tsx +0 -29
  249. package/src/MessageImage.tsx +0 -251
  250. package/src/MessageReply.tsx +0 -160
  251. package/src/MessageText.tsx +0 -111
  252. package/src/MessageVideo.tsx +0 -29
  253. package/src/MessagesContainer/components/DayAnimated/index.tsx +0 -151
  254. package/src/MessagesContainer/components/DayAnimated/styles.ts +0 -12
  255. package/src/MessagesContainer/components/DayAnimated/types.ts +0 -12
  256. package/src/MessagesContainer/components/Item/index.tsx +0 -197
  257. package/src/MessagesContainer/components/Item/types.ts +0 -13
  258. package/src/MessagesContainer/index.tsx +0 -434
  259. package/src/MessagesContainer/styles.ts +0 -42
  260. package/src/MessagesContainer/types.ts +0 -102
  261. package/src/Models.ts +0 -66
  262. package/src/QuickReplies.tsx +0 -181
  263. package/src/Reply/index.ts +0 -1
  264. package/src/Reply/types.ts +0 -80
  265. package/src/ReplyPreview.tsx +0 -132
  266. package/src/Send.tsx +0 -115
  267. package/src/SystemMessage.tsx +0 -79
  268. package/src/Time.tsx +0 -64
  269. package/src/TypingIndicator/index.tsx +0 -155
  270. package/src/TypingIndicator/styles.ts +0 -22
  271. package/src/TypingIndicator/types.ts +0 -6
  272. package/src/__tests__/Actions.test.tsx +0 -9
  273. package/src/__tests__/Avatar.test.tsx +0 -17
  274. package/src/__tests__/Bubble.test.tsx +0 -17
  275. package/src/__tests__/Color.test.tsx +0 -5
  276. package/src/__tests__/Composer.test.tsx +0 -10
  277. package/src/__tests__/Constant.test.tsx +0 -5
  278. package/src/__tests__/Day.test.tsx +0 -20
  279. package/src/__tests__/DayAnimated.test.tsx +0 -46
  280. package/src/__tests__/GiftedAvatar.test.tsx +0 -10
  281. package/src/__tests__/GiftedChat.test.tsx +0 -60
  282. package/src/__tests__/InputToolbar.test.tsx +0 -10
  283. package/src/__tests__/LoadEarlier.test.tsx +0 -10
  284. package/src/__tests__/Message.test.tsx +0 -67
  285. package/src/__tests__/MessageImage.test.tsx +0 -24
  286. package/src/__tests__/MessageReply.test.tsx +0 -54
  287. package/src/__tests__/MessageText.test.tsx +0 -15
  288. package/src/__tests__/MessagesContainer.test.tsx +0 -38
  289. package/src/__tests__/ReplyPreview.test.tsx +0 -41
  290. package/src/__tests__/Send.test.tsx +0 -21
  291. package/src/__tests__/SystemMessage.test.tsx +0 -24
  292. package/src/__tests__/Time.test.tsx +0 -26
  293. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +0 -40
  294. package/src/__tests__/__snapshots__/Avatar.test.tsx.snap +0 -17
  295. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +0 -121
  296. package/src/__tests__/__snapshots__/Color.test.tsx.snap +0 -21
  297. package/src/__tests__/__snapshots__/Composer.test.tsx.snap +0 -51
  298. package/src/__tests__/__snapshots__/Constant.test.tsx.snap +0 -13
  299. package/src/__tests__/__snapshots__/Day.test.tsx.snap +0 -99
  300. package/src/__tests__/__snapshots__/DayAnimated.test.tsx.snap +0 -5
  301. package/src/__tests__/__snapshots__/GiftedAvatar.test.tsx.snap +0 -24
  302. package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +0 -184
  303. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +0 -123
  304. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +0 -33
  305. package/src/__tests__/__snapshots__/Message.test.tsx.snap +0 -510
  306. package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +0 -203
  307. package/src/__tests__/__snapshots__/MessageReply.test.tsx.snap +0 -181
  308. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +0 -29
  309. package/src/__tests__/__snapshots__/ReplyPreview.test.tsx.snap +0 -349
  310. package/src/__tests__/__snapshots__/Send.test.tsx.snap +0 -148
  311. package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +0 -77
  312. package/src/__tests__/__snapshots__/Time.test.tsx.snap +0 -22
  313. package/src/__tests__/data.ts +0 -8
  314. package/src/__tests__/utils.test.ts +0 -31
  315. package/src/components/MessageReply.tsx +0 -156
  316. package/src/components/ReplyPreview.tsx +0 -230
  317. package/src/components/TouchableOpacity.tsx +0 -67
  318. package/src/hooks/useColorScheme.ts +0 -18
  319. package/src/hooks/useUpdateLayoutEffect.ts +0 -21
  320. package/src/index.ts +0 -29
  321. package/src/linkParser.tsx +0 -255
  322. package/src/logging.ts +0 -8
  323. package/src/styles.ts +0 -25
  324. package/src/types.ts +0 -25
  325. package/src/utils.ts +0 -139
@@ -1,273 +0,0 @@
1
- import React, { useCallback, useMemo, useRef } from 'react'
2
- import { View, StyleSheet } from 'react-native'
3
- import ReanimatedSwipeable, { SwipeableMethods } from 'react-native-gesture-handler/ReanimatedSwipeable'
4
- import Animated, { SharedValue, useAnimatedStyle } from 'react-native-reanimated'
5
-
6
- import { Avatar } from '../Avatar'
7
- import { Bubble } from '../Bubble'
8
- import { Color } from '../Color'
9
- import { IMessage } from '../Models'
10
- import { SwipeToReplyProps } from '../Reply'
11
- import { getStyleWithPosition } from '../styles'
12
- import { SystemMessage } from '../SystemMessage'
13
- import { isSameUser, renderComponentOrElement } from '../utils'
14
- import styles from './styles'
15
- import { MessageProps } from './types'
16
-
17
- export * from './types'
18
-
19
- interface ReplyIconProps {
20
- progress: SharedValue<number>
21
- translation: SharedValue<number>
22
- direction: 'left' | 'right'
23
- position: 'left' | 'right'
24
- style?: SwipeToReplyProps<IMessage>['actionContainerStyle']
25
- }
26
-
27
- const ReplyIcon = ({ progress, direction, position, style }: ReplyIconProps) => {
28
- const animatedStyle = useAnimatedStyle(() => {
29
- 'worklet'
30
-
31
- const scale = Math.min(progress.value, 1)
32
- // When swiping left (icon on right), icon should move left (negative)
33
- // When swiping right (icon on left), icon should move right (positive)
34
- const translateX = direction === 'left'
35
- ? Math.min(progress.value * -12, -12)
36
- : Math.max(progress.value * 12, 12)
37
-
38
- return {
39
- transform: [{ scale }, { translateX }],
40
- marginLeft: position === 'left' ? 0 : 16,
41
- marginRight: position === 'right' ? 0 : 16,
42
- }
43
- })
44
-
45
- return (
46
- <Animated.View style={[localStyles.swipeActionContainer, animatedStyle, style]}>
47
- <View style={localStyles.replyIconContainer}>
48
- <View style={localStyles.replyIcon}>
49
- <View style={localStyles.replyIconArrow} />
50
- <View style={localStyles.replyIconLine} />
51
- </View>
52
- </View>
53
- </Animated.View>
54
- )
55
- }
56
-
57
- export const Message = <TMessage extends IMessage = IMessage>(props: MessageProps<TMessage>) => {
58
- const {
59
- currentMessage,
60
- renderBubble: renderBubbleProp,
61
- renderSystemMessage: renderSystemMessageProp,
62
- onMessageLayout,
63
- nextMessage,
64
- position,
65
- containerStyle,
66
- user,
67
- isUserAvatarVisible,
68
- swipeToReply,
69
- } = props
70
-
71
- // Extract swipe props
72
- const isSwipeToReplyEnabled = swipeToReply?.isEnabled ?? false
73
- const swipeToReplyDirection = swipeToReply?.direction ?? 'left'
74
- const onSwipeToReply = swipeToReply?.onSwipe
75
- const renderSwipeToReplyActionProp = swipeToReply?.renderAction
76
- const swipeToReplyActionContainerStyle = swipeToReply?.actionContainerStyle
77
-
78
- const swipeableRef = useRef<SwipeableMethods>(null)
79
-
80
- const renderBubble = useCallback(() => {
81
- const {
82
- /* eslint-disable @typescript-eslint/no-unused-vars */
83
- containerStyle,
84
- onMessageLayout,
85
- swipeToReply,
86
- /* eslint-enable @typescript-eslint/no-unused-vars */
87
- ...rest
88
- } = props
89
-
90
- if (renderBubbleProp)
91
- return renderComponentOrElement(renderBubbleProp, rest)
92
-
93
- return <Bubble {...rest} />
94
- }, [props, renderBubbleProp])
95
-
96
- const renderSystemMessage = useCallback(() => {
97
- const {
98
- /* eslint-disable @typescript-eslint/no-unused-vars */
99
- containerStyle,
100
- onMessageLayout,
101
- swipeToReply,
102
- /* eslint-enable @typescript-eslint/no-unused-vars */
103
- ...rest
104
- } = props
105
-
106
- if (renderSystemMessageProp)
107
- return renderComponentOrElement(renderSystemMessageProp, rest)
108
-
109
- return <SystemMessage {...rest} />
110
- }, [props, renderSystemMessageProp])
111
-
112
- const renderAvatar = useCallback(() => {
113
- if (
114
- user?._id &&
115
- currentMessage?.user &&
116
- user._id === currentMessage.user._id &&
117
- !isUserAvatarVisible
118
- )
119
- return null
120
-
121
- if (currentMessage?.user?.avatar === null)
122
- return null
123
-
124
- const {
125
- /* eslint-disable @typescript-eslint/no-unused-vars */
126
- containerStyle,
127
- onMessageLayout,
128
- swipeToReply,
129
- /* eslint-enable @typescript-eslint/no-unused-vars */
130
- ...rest
131
- } = props
132
-
133
- return <Avatar {...rest} />
134
- }, [
135
- props,
136
- user,
137
- currentMessage,
138
- isUserAvatarVisible,
139
- ])
140
-
141
- const renderSwipeAction = useCallback((
142
- progress: SharedValue<number>,
143
- translation: SharedValue<number>
144
- ) => {
145
- if (renderSwipeToReplyActionProp)
146
- return renderSwipeToReplyActionProp(progress, translation, position)
147
-
148
- return (
149
- <ReplyIcon
150
- progress={progress}
151
- translation={translation}
152
- direction={swipeToReplyDirection}
153
- position={position}
154
- style={swipeToReplyActionContainerStyle}
155
- />
156
- )
157
- }, [position, renderSwipeToReplyActionProp, swipeToReplyDirection, swipeToReplyActionContainerStyle])
158
-
159
- const handleSwipeableOpen = useCallback(() => {
160
- swipeableRef.current?.close()
161
- }, [])
162
-
163
- const handleSwipeableWillOpen = useCallback(() => {
164
- if (onSwipeToReply && currentMessage)
165
- onSwipeToReply(currentMessage)
166
- }, [onSwipeToReply, currentMessage])
167
-
168
- const sameUser = useMemo(() =>
169
- isSameUser(currentMessage, nextMessage!)
170
- , [currentMessage, nextMessage])
171
-
172
- const messageContent = useMemo(() => {
173
- if (currentMessage?.system)
174
- return renderSystemMessage()
175
-
176
- return (
177
- <View
178
- style={[
179
- getStyleWithPosition(styles, 'container', position),
180
- { marginBottom: sameUser ? 2 : 10 },
181
- !props.isInverted && { marginBottom: 2 },
182
- containerStyle?.[position],
183
- ]}
184
- >
185
- {position === 'left' && renderAvatar()}
186
- {renderBubble()}
187
- {position === 'right' && renderAvatar()}
188
- </View>
189
- )
190
- }, [
191
- currentMessage?.system,
192
- renderSystemMessage,
193
- position,
194
- sameUser,
195
- props.isInverted,
196
- containerStyle,
197
- renderAvatar,
198
- renderBubble,
199
- ])
200
-
201
- if (!currentMessage)
202
- return null
203
-
204
- // Don't wrap system messages in Swipeable
205
- if (currentMessage.system || !isSwipeToReplyEnabled)
206
- return (
207
- <View onLayout={onMessageLayout}>
208
- {messageContent}
209
- </View>
210
- )
211
-
212
- return (
213
- <View onLayout={onMessageLayout}>
214
- <ReanimatedSwipeable
215
- ref={swipeableRef}
216
- friction={2}
217
- overshootFriction={8}
218
- renderRightActions={swipeToReplyDirection === 'left' ? renderSwipeAction : undefined}
219
- renderLeftActions={swipeToReplyDirection === 'right' ? renderSwipeAction : undefined}
220
- onSwipeableOpen={handleSwipeableOpen}
221
- onSwipeableWillOpen={handleSwipeableWillOpen}
222
- >
223
- {messageContent}
224
- </ReanimatedSwipeable>
225
- </View>
226
- )
227
- }
228
-
229
- const localStyles = StyleSheet.create({
230
- swipeActionContainer: {
231
- width: 40,
232
- justifyContent: 'center',
233
- alignItems: 'center',
234
- },
235
- replyIconContainer: {
236
- width: 28,
237
- height: 28,
238
- borderRadius: 14,
239
- backgroundColor: Color.defaultBlue,
240
- justifyContent: 'center',
241
- alignItems: 'center',
242
- },
243
- replyIcon: {
244
- width: 14,
245
- height: 10,
246
- transform: [{ scaleX: -1 }],
247
- },
248
- replyIconArrow: {
249
- position: 'absolute',
250
- top: 0,
251
- left: 0,
252
- width: 0,
253
- height: 0,
254
- borderTopWidth: 5,
255
- borderTopColor: 'transparent',
256
- borderBottomWidth: 5,
257
- borderBottomColor: 'transparent',
258
- borderRightWidth: 6,
259
- borderRightColor: Color.white,
260
- },
261
- replyIconLine: {
262
- position: 'absolute',
263
- top: 3,
264
- left: 5,
265
- width: 9,
266
- height: 4,
267
- borderTopWidth: 2,
268
- borderRightWidth: 2,
269
- borderTopColor: Color.white,
270
- borderRightColor: Color.white,
271
- borderTopRightRadius: 4,
272
- },
273
- })
@@ -1,18 +0,0 @@
1
- import { StyleSheet } from 'react-native'
2
-
3
- export default StyleSheet.create({
4
- container: {
5
- flexDirection: 'row',
6
- alignItems: 'flex-end',
7
- maxWidth: '70%',
8
- },
9
- container_left: {
10
- justifyContent: 'flex-start',
11
- marginLeft: 8,
12
- },
13
- container_right: {
14
- justifyContent: 'flex-end',
15
- marginRight: 8,
16
- alignSelf: 'flex-end',
17
- },
18
- })
@@ -1,26 +0,0 @@
1
- import { ViewStyle, LayoutChangeEvent } from 'react-native'
2
-
3
- import { AvatarProps } from '../Avatar'
4
- import { BubbleProps } from '../Bubble'
5
- import { DayProps } from '../Day'
6
- import { IMessage, User, LeftRightStyle } from '../Models'
7
- import { SwipeToReplyProps } from '../Reply'
8
- import { SystemMessageProps } from '../SystemMessage'
9
-
10
- export interface MessageProps<TMessage extends IMessage> {
11
- isUserAvatarVisible?: boolean
12
- position: 'left' | 'right'
13
- currentMessage: TMessage
14
- nextMessage?: TMessage
15
- previousMessage?: TMessage
16
- user: User
17
- isInverted?: boolean
18
- containerStyle?: LeftRightStyle<ViewStyle>
19
- renderBubble?: (props: BubbleProps<TMessage>) => React.ReactNode
20
- renderDay?: (props: DayProps) => React.ReactNode
21
- renderSystemMessage?: (props: SystemMessageProps<TMessage>) => React.ReactNode
22
- renderAvatar?: (props: AvatarProps<TMessage>) => React.ReactNode
23
- onMessageLayout?: (event: LayoutChangeEvent) => void
24
- /** Swipe to reply configuration */
25
- swipeToReply?: SwipeToReplyProps<TMessage>
26
- }
@@ -1,29 +0,0 @@
1
- import React, { useMemo } from 'react'
2
- import { View, StyleSheet } from 'react-native'
3
- import { Text } from 'react-native-gesture-handler'
4
- import { Color } from './Color'
5
-
6
- const styles = StyleSheet.create({
7
- container: {
8
- padding: 10,
9
- },
10
- text: {
11
- color: Color.alizarin,
12
- fontWeight: '600',
13
- },
14
- })
15
-
16
- export function MessageAudio () {
17
- const content = useMemo(() => (
18
- <View style={styles.container}>
19
- <Text style={styles.text}>
20
- {'Audio is not implemented by GiftedChat.'}
21
- </Text>
22
- <Text style={styles.text}>
23
- {'\nYou need to provide your own implementation by using renderMessageAudio prop.'}
24
- </Text>
25
- </View>
26
- ), [])
27
-
28
- return content
29
- }
@@ -1,251 +0,0 @@
1
- import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
2
- import {
3
- Image,
4
- StyleSheet,
5
- View,
6
- ImageProps,
7
- ViewStyle,
8
- StyleProp,
9
- ImageStyle,
10
- ImageURISource,
11
- LayoutChangeEvent,
12
- useWindowDimensions,
13
- StatusBar,
14
- } from 'react-native'
15
- import { BaseButton, GestureHandlerRootView, Text } from 'react-native-gesture-handler'
16
- import { OverKeyboardView } from 'react-native-keyboard-controller'
17
- import Animated, {
18
- useAnimatedStyle,
19
- useSharedValue,
20
- withTiming,
21
- Easing,
22
- runOnJS,
23
- } from 'react-native-reanimated'
24
- import { SafeAreaProvider, useSafeAreaInsets } from 'react-native-safe-area-context'
25
- import Zoom from 'react-native-zoom-reanimated'
26
- import { TouchableOpacity } from './components/TouchableOpacity'
27
- import { IMessage } from './Models'
28
- import commonStyles from './styles'
29
-
30
- interface ModalContentProps {
31
- isVisible: boolean
32
- imageSource: ImageURISource
33
- modalImageDimensions: { width: number, height: number } | undefined
34
- imageProps?: Partial<ImageProps>
35
- onClose: () => void
36
- }
37
-
38
- function ModalContent({ isVisible, imageSource, modalImageDimensions, imageProps, onClose }: ModalContentProps) {
39
- const insets = useSafeAreaInsets()
40
-
41
- // Animation values
42
- const modalOpacity = useSharedValue(0)
43
- const modalScale = useSharedValue(0.9)
44
- const modalBorderRadius = useSharedValue(40)
45
-
46
- const handleModalClose = useCallback(() => {
47
- modalOpacity.value = withTiming(0, { duration: 200, easing: Easing.in(Easing.ease) })
48
- modalScale.value = withTiming(0.9, { duration: 200, easing: Easing.in(Easing.ease) }, () => {
49
- runOnJS(onClose)()
50
- })
51
- modalBorderRadius.value = withTiming(40, { duration: 200, easing: Easing.in(Easing.ease) })
52
- }, [onClose, modalOpacity, modalScale, modalBorderRadius])
53
-
54
- // Animate on visibility change
55
- useEffect(() => {
56
- if (isVisible) {
57
- modalOpacity.value = withTiming(1, { duration: 300, easing: Easing.out(Easing.ease) })
58
- modalScale.value = withTiming(1, { duration: 300, easing: Easing.out(Easing.ease) })
59
- modalBorderRadius.value = withTiming(0, { duration: 300, easing: Easing.out(Easing.ease) })
60
- }
61
- }, [isVisible, modalOpacity, modalScale, modalBorderRadius])
62
-
63
- const modalAnimatedStyle = useAnimatedStyle(() => ({
64
- opacity: modalOpacity.value,
65
- transform: [{ scale: modalScale.value }],
66
- }), [modalOpacity, modalScale])
67
-
68
- const modalBorderRadiusStyle = useAnimatedStyle(() => ({
69
- borderRadius: modalBorderRadius.value,
70
- }), [modalBorderRadius])
71
-
72
- return (
73
- <>
74
- <StatusBar animated barStyle='dark-content' />
75
- <Animated.View style={[styles.modalOverlay, modalAnimatedStyle, modalBorderRadiusStyle]}>
76
- <GestureHandlerRootView style={commonStyles.fill}>
77
- <Animated.View style={[commonStyles.fill, styles.modalContent, modalBorderRadiusStyle, { paddingTop: insets.top, paddingBottom: insets.bottom }]}>
78
-
79
- {/* close button */}
80
- <View style={styles.closeButtonContainer}>
81
- <BaseButton onPress={handleModalClose}>
82
- <View style={styles.closeButtonContent}>
83
- <Text style={styles.closeButtonIcon}>
84
- {'X'}
85
- </Text>
86
- </View>
87
- </BaseButton>
88
- </View>
89
-
90
- <View style={[commonStyles.fill, commonStyles.centerItems]}>
91
- <Zoom>
92
- <Image
93
- style={modalImageDimensions}
94
- source={imageSource}
95
- resizeMode='contain'
96
- {...imageProps}
97
- />
98
- </Zoom>
99
- </View>
100
- </Animated.View>
101
- </GestureHandlerRootView>
102
- </Animated.View>
103
- </>
104
- )
105
- }
106
-
107
- export interface MessageImageProps<TMessage extends IMessage> {
108
- currentMessage: TMessage
109
- containerStyle?: StyleProp<ViewStyle>
110
- imageSourceProps?: Partial<ImageURISource>
111
- imageStyle?: StyleProp<ImageStyle>
112
- imageProps?: Partial<ImageProps>
113
- }
114
-
115
- export function MessageImage<TMessage extends IMessage = IMessage> ({
116
- containerStyle,
117
- imageProps,
118
- imageSourceProps,
119
- imageStyle,
120
- currentMessage,
121
- }: MessageImageProps<TMessage>) {
122
- const [isModalVisible, setIsModalVisible] = useState(false)
123
- const [imageDimensions, setImageDimensions] = useState<{ width: number, height: number }>()
124
- const windowDimensions = useWindowDimensions()
125
-
126
- const imageSource = useMemo(() => ({
127
- ...imageSourceProps,
128
- uri: currentMessage?.image,
129
- }), [imageSourceProps, currentMessage?.image])
130
-
131
- const isImageSourceChanged = useRef(true)
132
-
133
- const computedImageStyle = useMemo(() => [
134
- styles.image,
135
- imageStyle,
136
- ], [imageStyle])
137
-
138
- const handleImagePress = useCallback(() => {
139
- if (!imageSource.uri)
140
- return
141
-
142
- setIsModalVisible(true)
143
-
144
- if (isImageSourceChanged.current || !imageDimensions)
145
- Image.getSize(imageSource.uri, (width, height) => {
146
- setImageDimensions({ width, height })
147
- })
148
- }, [imageSource.uri, imageDimensions])
149
-
150
- const handleModalClose = useCallback(() => {
151
- setIsModalVisible(false)
152
- }, [])
153
-
154
- const handleImageLayout = useCallback((e: LayoutChangeEvent) => {
155
- setImageDimensions({
156
- width: e.nativeEvent.layout.width,
157
- height: e.nativeEvent.layout.height,
158
- })
159
- }, [])
160
-
161
- const modalImageDimensions = useMemo(() => {
162
- if (!imageDimensions)
163
- return undefined
164
-
165
- const aspectRatio = imageDimensions.width / imageDimensions.height
166
-
167
- let width = windowDimensions.width
168
- let height = width / aspectRatio
169
-
170
- if (height > windowDimensions.height) {
171
- height = windowDimensions.height
172
- width = height * aspectRatio
173
- }
174
-
175
- return {
176
- width,
177
- height,
178
- }
179
- }, [imageDimensions, windowDimensions.height, windowDimensions.width])
180
-
181
- useEffect(() => {
182
- isImageSourceChanged.current = true
183
- }, [imageSource.uri])
184
-
185
- if (currentMessage == null)
186
- return null
187
-
188
- return (
189
- <View style={containerStyle}>
190
- <TouchableOpacity onPress={handleImagePress}>
191
- <Image
192
- {...imageProps}
193
- style={computedImageStyle}
194
- source={imageSource}
195
- onLayout={handleImageLayout}
196
- resizeMode='cover'
197
- />
198
- </TouchableOpacity>
199
-
200
- <OverKeyboardView visible={isModalVisible}>
201
- <SafeAreaProvider>
202
- <ModalContent
203
- isVisible={isModalVisible}
204
- imageSource={imageSource}
205
- modalImageDimensions={modalImageDimensions}
206
- imageProps={imageProps}
207
- onClose={handleModalClose}
208
- />
209
- </SafeAreaProvider>
210
- </OverKeyboardView>
211
- </View>
212
- )
213
- }
214
-
215
- const styles = StyleSheet.create({
216
- image: {
217
- width: 150,
218
- height: 100,
219
- borderRadius: 13,
220
- margin: 3,
221
- },
222
- modalOverlay: {
223
- position: 'absolute',
224
- top: 0,
225
- left: 0,
226
- right: 0,
227
- bottom: 0,
228
- zIndex: 1000,
229
- },
230
- modalContent: {
231
- backgroundColor: '#000',
232
- overflow: 'hidden',
233
- },
234
- modalImageContainer: {
235
- width: '100%',
236
- height: '100%',
237
- },
238
-
239
- closeButtonContainer: {
240
- flexDirection: 'row',
241
- justifyContent: 'flex-end',
242
- },
243
- closeButtonContent: {
244
- padding: 20,
245
- },
246
- closeButtonIcon: {
247
- fontSize: 20,
248
- lineHeight: 20,
249
- color: 'white',
250
- },
251
- })