@droppii-org/chat-mobile 0.2.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 (294) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +101 -0
  3. package/lib/module/assets/images/icon_bot.png +0 -0
  4. package/lib/module/assets/images/index.js +9 -0
  5. package/lib/module/assets/images/index.js.map +1 -0
  6. package/lib/module/assets/images/tag_bot.png +0 -0
  7. package/lib/module/assets/images/tag_mall.png +0 -0
  8. package/lib/module/build-ignore.d.js +2 -0
  9. package/lib/module/build-ignore.d.js.map +1 -0
  10. package/lib/module/components/Avatar/Avatar.js +81 -0
  11. package/lib/module/components/Avatar/Avatar.js.map +1 -0
  12. package/lib/module/components/Avatar/Avatar.types.js +2 -0
  13. package/lib/module/components/Avatar/Avatar.types.js.map +1 -0
  14. package/lib/module/components/Avatar/Avatar.utils.js +44 -0
  15. package/lib/module/components/Avatar/Avatar.utils.js.map +1 -0
  16. package/lib/module/components/Avatar/AvatarBadge.js +28 -0
  17. package/lib/module/components/Avatar/AvatarBadge.js.map +1 -0
  18. package/lib/module/components/Avatar/DoubleAvatar.js +74 -0
  19. package/lib/module/components/Avatar/DoubleAvatar.js.map +1 -0
  20. package/lib/module/components/Avatar/SingleAvatar.js +53 -0
  21. package/lib/module/components/Avatar/SingleAvatar.js.map +1 -0
  22. package/lib/module/components/Avatar/index.js +7 -0
  23. package/lib/module/components/Avatar/index.js.map +1 -0
  24. package/lib/module/components/ThreadCard/AvatarSection.js +37 -0
  25. package/lib/module/components/ThreadCard/AvatarSection.js.map +1 -0
  26. package/lib/module/components/ThreadCard/NamePrefixIcon.js +36 -0
  27. package/lib/module/components/ThreadCard/NamePrefixIcon.js.map +1 -0
  28. package/lib/module/components/ThreadCard/ThreadCard.js +132 -0
  29. package/lib/module/components/ThreadCard/ThreadCard.js.map +1 -0
  30. package/lib/module/components/ThreadCard/UnreadBadge.js +35 -0
  31. package/lib/module/components/ThreadCard/UnreadBadge.js.map +1 -0
  32. package/lib/module/components/ThreadCard/index.js +7 -0
  33. package/lib/module/components/ThreadCard/index.js.map +1 -0
  34. package/lib/module/components/ThreadCard/thread-card.utils.js +51 -0
  35. package/lib/module/components/ThreadCard/thread-card.utils.js.map +1 -0
  36. package/lib/module/core/index.js +11 -0
  37. package/lib/module/core/index.js.map +1 -0
  38. package/lib/module/core/useChatListener.js +62 -0
  39. package/lib/module/core/useChatListener.js.map +1 -0
  40. package/lib/module/core/useUserListener.js +72 -0
  41. package/lib/module/core/useUserListener.js.map +1 -0
  42. package/lib/module/hooks/query-keys.js +10 -0
  43. package/lib/module/hooks/query-keys.js.map +1 -0
  44. package/lib/module/hooks/useChatMessages.js +163 -0
  45. package/lib/module/hooks/useChatMessages.js.map +1 -0
  46. package/lib/module/hooks/useConversationList.js +51 -0
  47. package/lib/module/hooks/useConversationList.js.map +1 -0
  48. package/lib/module/index.js +14 -0
  49. package/lib/module/index.js.map +1 -0
  50. package/lib/module/package.json +1 -0
  51. package/lib/module/screens/chat-detail/ChatAttachmentPanel.js +106 -0
  52. package/lib/module/screens/chat-detail/ChatAttachmentPanel.js.map +1 -0
  53. package/lib/module/screens/chat-detail/ChatComposer.js +288 -0
  54. package/lib/module/screens/chat-detail/ChatComposer.js.map +1 -0
  55. package/lib/module/screens/chat-detail/ChatDay.js +65 -0
  56. package/lib/module/screens/chat-detail/ChatDay.js.map +1 -0
  57. package/lib/module/screens/chat-detail/ChatDetail.js +104 -0
  58. package/lib/module/screens/chat-detail/ChatDetail.js.map +1 -0
  59. package/lib/module/screens/chat-detail/ChatDetailHeader.js +92 -0
  60. package/lib/module/screens/chat-detail/ChatDetailHeader.js.map +1 -0
  61. package/lib/module/screens/chat-detail/ChatList.js +145 -0
  62. package/lib/module/screens/chat-detail/ChatList.js.map +1 -0
  63. package/lib/module/screens/chat-detail/ChatLoadEarlier.js +23 -0
  64. package/lib/module/screens/chat-detail/ChatLoadEarlier.js.map +1 -0
  65. package/lib/module/screens/chat-detail/ChatQuickActions.js +85 -0
  66. package/lib/module/screens/chat-detail/ChatQuickActions.js.map +1 -0
  67. package/lib/module/screens/chat-detail/ChatScrollToBottom.js +12 -0
  68. package/lib/module/screens/chat-detail/ChatScrollToBottom.js.map +1 -0
  69. package/lib/module/screens/chat-detail/ChatTextBubble.js +62 -0
  70. package/lib/module/screens/chat-detail/ChatTextBubble.js.map +1 -0
  71. package/lib/module/screens/chat-detail/constants.js +59 -0
  72. package/lib/module/screens/chat-detail/constants.js.map +1 -0
  73. package/lib/module/screens/chat-detail/index.js +12 -0
  74. package/lib/module/screens/chat-detail/index.js.map +1 -0
  75. package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js +24 -0
  76. package/lib/module/screens/chat-detail/messages/ChatMessageBubble.js.map +1 -0
  77. package/lib/module/screens/chat-detail/messages/types.js +4 -0
  78. package/lib/module/screens/chat-detail/messages/types.js.map +1 -0
  79. package/lib/module/screens/chat-detail/types.js +4 -0
  80. package/lib/module/screens/chat-detail/types.js.map +1 -0
  81. package/lib/module/screens/chat-detail/useChatActionPress.js +11 -0
  82. package/lib/module/screens/chat-detail/useChatActionPress.js.map +1 -0
  83. package/lib/module/screens/inbox/Inbox.js +134 -0
  84. package/lib/module/screens/inbox/Inbox.js.map +1 -0
  85. package/lib/module/screens/inbox/MessagesTab.js +58 -0
  86. package/lib/module/screens/inbox/MessagesTab.js.map +1 -0
  87. package/lib/module/screens/inbox/index.js +5 -0
  88. package/lib/module/screens/inbox/index.js.map +1 -0
  89. package/lib/module/services/apis.js +41 -0
  90. package/lib/module/services/apis.js.map +1 -0
  91. package/lib/module/services/index.js +5 -0
  92. package/lib/module/services/index.js.map +1 -0
  93. package/lib/module/services/message.js +38 -0
  94. package/lib/module/services/message.js.map +1 -0
  95. package/lib/module/store/conversation.js +89 -0
  96. package/lib/module/store/conversation.js.map +1 -0
  97. package/lib/module/store/index.js +6 -0
  98. package/lib/module/store/index.js.map +1 -0
  99. package/lib/module/store/storeConfig.js +19 -0
  100. package/lib/module/store/storeConfig.js.map +1 -0
  101. package/lib/module/store/user.js +25 -0
  102. package/lib/module/store/user.js.map +1 -0
  103. package/lib/module/translation/index.js +24 -0
  104. package/lib/module/translation/index.js.map +1 -0
  105. package/lib/module/translation/resources/i18n.js +10 -0
  106. package/lib/module/translation/resources/i18n.js.map +1 -0
  107. package/lib/module/types/auth.js +9 -0
  108. package/lib/module/types/auth.js.map +1 -0
  109. package/lib/module/types/chat.js +26 -0
  110. package/lib/module/types/chat.js.map +1 -0
  111. package/lib/module/types/message.js +16 -0
  112. package/lib/module/types/message.js.map +1 -0
  113. package/lib/module/utils/conversation.js +61 -0
  114. package/lib/module/utils/conversation.js.map +1 -0
  115. package/lib/module/utils/giftedChatMessage.js +90 -0
  116. package/lib/module/utils/giftedChatMessage.js.map +1 -0
  117. package/lib/module/utils/message.js +68 -0
  118. package/lib/module/utils/message.js.map +1 -0
  119. package/lib/module/utils/resolveMessageType.js +44 -0
  120. package/lib/module/utils/resolveMessageType.js.map +1 -0
  121. package/lib/typescript/package.json +1 -0
  122. package/lib/typescript/src/assets/images/index.d.ts +7 -0
  123. package/lib/typescript/src/assets/images/index.d.ts.map +1 -0
  124. package/lib/typescript/src/components/Avatar/Avatar.d.ts +4 -0
  125. package/lib/typescript/src/components/Avatar/Avatar.d.ts.map +1 -0
  126. package/lib/typescript/src/components/Avatar/Avatar.types.d.ts +18 -0
  127. package/lib/typescript/src/components/Avatar/Avatar.types.d.ts.map +1 -0
  128. package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts +14 -0
  129. package/lib/typescript/src/components/Avatar/Avatar.utils.d.ts.map +1 -0
  130. package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts +7 -0
  131. package/lib/typescript/src/components/Avatar/AvatarBadge.d.ts.map +1 -0
  132. package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts +13 -0
  133. package/lib/typescript/src/components/Avatar/DoubleAvatar.d.ts.map +1 -0
  134. package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts +12 -0
  135. package/lib/typescript/src/components/Avatar/SingleAvatar.d.ts.map +1 -0
  136. package/lib/typescript/src/components/Avatar/index.d.ts +6 -0
  137. package/lib/typescript/src/components/Avatar/index.d.ts.map +1 -0
  138. package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts +8 -0
  139. package/lib/typescript/src/components/ThreadCard/AvatarSection.d.ts.map +1 -0
  140. package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts +8 -0
  141. package/lib/typescript/src/components/ThreadCard/NamePrefixIcon.d.ts.map +1 -0
  142. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts +11 -0
  143. package/lib/typescript/src/components/ThreadCard/ThreadCard.d.ts.map +1 -0
  144. package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts +6 -0
  145. package/lib/typescript/src/components/ThreadCard/UnreadBadge.d.ts.map +1 -0
  146. package/lib/typescript/src/components/ThreadCard/index.d.ts +5 -0
  147. package/lib/typescript/src/components/ThreadCard/index.d.ts.map +1 -0
  148. package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts +4 -0
  149. package/lib/typescript/src/components/ThreadCard/thread-card.utils.d.ts.map +1 -0
  150. package/lib/typescript/src/core/index.d.ts +3 -0
  151. package/lib/typescript/src/core/index.d.ts.map +1 -0
  152. package/lib/typescript/src/core/useChatListener.d.ts +2 -0
  153. package/lib/typescript/src/core/useChatListener.d.ts.map +1 -0
  154. package/lib/typescript/src/core/useUserListener.d.ts +2 -0
  155. package/lib/typescript/src/core/useUserListener.d.ts.map +1 -0
  156. package/lib/typescript/src/hooks/query-keys.d.ts +9 -0
  157. package/lib/typescript/src/hooks/query-keys.d.ts.map +1 -0
  158. package/lib/typescript/src/hooks/useChatMessages.d.ts +21 -0
  159. package/lib/typescript/src/hooks/useChatMessages.d.ts.map +1 -0
  160. package/lib/typescript/src/hooks/useConversationList.d.ts +8 -0
  161. package/lib/typescript/src/hooks/useConversationList.d.ts.map +1 -0
  162. package/lib/typescript/src/index.d.ts +14 -0
  163. package/lib/typescript/src/index.d.ts.map +1 -0
  164. package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts +3 -0
  165. package/lib/typescript/src/screens/chat-detail/ChatAttachmentPanel.d.ts.map +1 -0
  166. package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts +3 -0
  167. package/lib/typescript/src/screens/chat-detail/ChatComposer.d.ts.map +1 -0
  168. package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts +3 -0
  169. package/lib/typescript/src/screens/chat-detail/ChatDay.d.ts.map +1 -0
  170. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts +4 -0
  171. package/lib/typescript/src/screens/chat-detail/ChatDetail.d.ts.map +1 -0
  172. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts +4 -0
  173. package/lib/typescript/src/screens/chat-detail/ChatDetailHeader.d.ts.map +1 -0
  174. package/lib/typescript/src/screens/chat-detail/ChatList.d.ts +3 -0
  175. package/lib/typescript/src/screens/chat-detail/ChatList.d.ts.map +1 -0
  176. package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts +3 -0
  177. package/lib/typescript/src/screens/chat-detail/ChatLoadEarlier.d.ts.map +1 -0
  178. package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts +3 -0
  179. package/lib/typescript/src/screens/chat-detail/ChatQuickActions.d.ts.map +1 -0
  180. package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts +2 -0
  181. package/lib/typescript/src/screens/chat-detail/ChatScrollToBottom.d.ts.map +1 -0
  182. package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts +3 -0
  183. package/lib/typescript/src/screens/chat-detail/ChatTextBubble.d.ts.map +1 -0
  184. package/lib/typescript/src/screens/chat-detail/constants.d.ts +17 -0
  185. package/lib/typescript/src/screens/chat-detail/constants.d.ts.map +1 -0
  186. package/lib/typescript/src/screens/chat-detail/index.d.ts +13 -0
  187. package/lib/typescript/src/screens/chat-detail/index.d.ts.map +1 -0
  188. package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts +3 -0
  189. package/lib/typescript/src/screens/chat-detail/messages/ChatMessageBubble.d.ts.map +1 -0
  190. package/lib/typescript/src/screens/chat-detail/messages/types.d.ts +13 -0
  191. package/lib/typescript/src/screens/chat-detail/messages/types.d.ts.map +1 -0
  192. package/lib/typescript/src/screens/chat-detail/types.d.ts +86 -0
  193. package/lib/typescript/src/screens/chat-detail/types.d.ts.map +1 -0
  194. package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts +3 -0
  195. package/lib/typescript/src/screens/chat-detail/useChatActionPress.d.ts.map +1 -0
  196. package/lib/typescript/src/screens/inbox/Inbox.d.ts +10 -0
  197. package/lib/typescript/src/screens/inbox/Inbox.d.ts.map +1 -0
  198. package/lib/typescript/src/screens/inbox/MessagesTab.d.ts +7 -0
  199. package/lib/typescript/src/screens/inbox/MessagesTab.d.ts.map +1 -0
  200. package/lib/typescript/src/screens/inbox/index.d.ts +3 -0
  201. package/lib/typescript/src/screens/inbox/index.d.ts.map +1 -0
  202. package/lib/typescript/src/services/apis.d.ts +12 -0
  203. package/lib/typescript/src/services/apis.d.ts.map +1 -0
  204. package/lib/typescript/src/services/index.d.ts +3 -0
  205. package/lib/typescript/src/services/index.d.ts.map +1 -0
  206. package/lib/typescript/src/services/message.d.ts +21 -0
  207. package/lib/typescript/src/services/message.d.ts.map +1 -0
  208. package/lib/typescript/src/store/conversation.d.ts +24 -0
  209. package/lib/typescript/src/store/conversation.d.ts.map +1 -0
  210. package/lib/typescript/src/store/index.d.ts +4 -0
  211. package/lib/typescript/src/store/index.d.ts.map +1 -0
  212. package/lib/typescript/src/store/storeConfig.d.ts +4 -0
  213. package/lib/typescript/src/store/storeConfig.d.ts.map +1 -0
  214. package/lib/typescript/src/store/user.d.ts +12 -0
  215. package/lib/typescript/src/store/user.d.ts.map +1 -0
  216. package/lib/typescript/src/translation/index.d.ts +4 -0
  217. package/lib/typescript/src/translation/index.d.ts.map +1 -0
  218. package/lib/typescript/src/translation/resources/i18n.d.ts +5 -0
  219. package/lib/typescript/src/translation/resources/i18n.d.ts.map +1 -0
  220. package/lib/typescript/src/types/auth.d.ts +24 -0
  221. package/lib/typescript/src/types/auth.d.ts.map +1 -0
  222. package/lib/typescript/src/types/chat.d.ts +99 -0
  223. package/lib/typescript/src/types/chat.d.ts.map +1 -0
  224. package/lib/typescript/src/types/message.d.ts +15 -0
  225. package/lib/typescript/src/types/message.d.ts.map +1 -0
  226. package/lib/typescript/src/utils/conversation.d.ts +10 -0
  227. package/lib/typescript/src/utils/conversation.d.ts.map +1 -0
  228. package/lib/typescript/src/utils/giftedChatMessage.d.ts +10 -0
  229. package/lib/typescript/src/utils/giftedChatMessage.d.ts.map +1 -0
  230. package/lib/typescript/src/utils/message.d.ts +15 -0
  231. package/lib/typescript/src/utils/message.d.ts.map +1 -0
  232. package/lib/typescript/src/utils/resolveMessageType.d.ts +4 -0
  233. package/lib/typescript/src/utils/resolveMessageType.d.ts.map +1 -0
  234. package/package.json +209 -0
  235. package/src/assets/images/icon_bot.png +0 -0
  236. package/src/assets/images/index.ts +7 -0
  237. package/src/assets/images/tag_bot.png +0 -0
  238. package/src/assets/images/tag_mall.png +0 -0
  239. package/src/build-ignore.d.ts +24 -0
  240. package/src/components/Avatar/Avatar.tsx +105 -0
  241. package/src/components/Avatar/Avatar.types.ts +17 -0
  242. package/src/components/Avatar/Avatar.utils.ts +49 -0
  243. package/src/components/Avatar/AvatarBadge.tsx +29 -0
  244. package/src/components/Avatar/DoubleAvatar.tsx +89 -0
  245. package/src/components/Avatar/SingleAvatar.tsx +74 -0
  246. package/src/components/Avatar/index.ts +5 -0
  247. package/src/components/ThreadCard/AvatarSection.tsx +42 -0
  248. package/src/components/ThreadCard/NamePrefixIcon.tsx +45 -0
  249. package/src/components/ThreadCard/ThreadCard.tsx +145 -0
  250. package/src/components/ThreadCard/UnreadBadge.tsx +35 -0
  251. package/src/components/ThreadCard/index.ts +4 -0
  252. package/src/components/ThreadCard/thread-card.utils.ts +68 -0
  253. package/src/core/index.ts +10 -0
  254. package/src/core/useChatListener.ts +85 -0
  255. package/src/core/useUserListener.ts +86 -0
  256. package/src/hooks/query-keys.ts +11 -0
  257. package/src/hooks/useChatMessages.ts +243 -0
  258. package/src/hooks/useConversationList.ts +57 -0
  259. package/src/index.tsx +36 -0
  260. package/src/screens/chat-detail/ChatAttachmentPanel.tsx +142 -0
  261. package/src/screens/chat-detail/ChatComposer.tsx +412 -0
  262. package/src/screens/chat-detail/ChatDay.tsx +73 -0
  263. package/src/screens/chat-detail/ChatDetail.tsx +118 -0
  264. package/src/screens/chat-detail/ChatDetailHeader.tsx +114 -0
  265. package/src/screens/chat-detail/ChatList.tsx +187 -0
  266. package/src/screens/chat-detail/ChatLoadEarlier.tsx +20 -0
  267. package/src/screens/chat-detail/ChatQuickActions.tsx +108 -0
  268. package/src/screens/chat-detail/ChatScrollToBottom.tsx +8 -0
  269. package/src/screens/chat-detail/ChatTextBubble.tsx +73 -0
  270. package/src/screens/chat-detail/constants.ts +76 -0
  271. package/src/screens/chat-detail/index.ts +33 -0
  272. package/src/screens/chat-detail/messages/ChatMessageBubble.tsx +24 -0
  273. package/src/screens/chat-detail/messages/types.ts +14 -0
  274. package/src/screens/chat-detail/types.ts +97 -0
  275. package/src/screens/chat-detail/useChatActionPress.ts +17 -0
  276. package/src/screens/inbox/Inbox.tsx +164 -0
  277. package/src/screens/inbox/MessagesTab.tsx +62 -0
  278. package/src/screens/inbox/index.ts +2 -0
  279. package/src/services/apis.ts +60 -0
  280. package/src/services/index.ts +2 -0
  281. package/src/services/message.ts +61 -0
  282. package/src/store/conversation.ts +116 -0
  283. package/src/store/index.ts +3 -0
  284. package/src/store/storeConfig.ts +19 -0
  285. package/src/store/user.ts +26 -0
  286. package/src/translation/index.ts +30 -0
  287. package/src/translation/resources/i18n.ts +8 -0
  288. package/src/types/auth.ts +25 -0
  289. package/src/types/chat.ts +118 -0
  290. package/src/types/message.ts +17 -0
  291. package/src/utils/conversation.ts +106 -0
  292. package/src/utils/giftedChatMessage.ts +137 -0
  293. package/src/utils/message.ts +136 -0
  294. package/src/utils/resolveMessageType.ts +49 -0
@@ -0,0 +1,187 @@
1
+ import { memo, useCallback, useMemo, useRef } from 'react';
2
+ import { ActivityIndicator, StyleSheet } from 'react-native';
3
+ import {
4
+ GiftedChat,
5
+ type DayProps,
6
+ type LoadEarlierMessagesProps,
7
+ type MessageProps,
8
+ } from 'react-native-gifted-chat';
9
+ import { KContainer, KColors, KSpacingValue } from '@droppii/libs';
10
+ import { mapOpenIMMessagesToGiftedChat } from '../../utils/giftedChatMessage';
11
+ import type { DGiftedChatMessage } from '../../utils/giftedChatMessage';
12
+ import type { ChatListProps } from './types';
13
+ import { ChatDay } from './ChatDay';
14
+ import { ChatLoadEarlier } from './ChatLoadEarlier';
15
+ import { ChatScrollToBottom } from './ChatScrollToBottom';
16
+ import { ChatMessageBubble } from './messages/ChatMessageBubble';
17
+
18
+ export const ChatList = memo(
19
+ ({
20
+ messages = [],
21
+ currentUserId = '',
22
+ renderChat,
23
+ onLoadEarlier,
24
+ isLoading,
25
+ isLoadingEarlier,
26
+ hasMoreEarlier,
27
+ }: ChatListProps) => {
28
+ const giftedMessages = useMemo(
29
+ () => mapOpenIMMessagesToGiftedChat(messages),
30
+ [messages]
31
+ );
32
+
33
+ const user = useMemo(
34
+ () => ({ _id: String(currentUserId) }),
35
+ [currentUserId]
36
+ );
37
+
38
+ const renderMessage = useCallback(
39
+ (props: MessageProps<DGiftedChatMessage>) => {
40
+ const currentMessage = props.currentMessage;
41
+
42
+ if (!currentMessage) {
43
+ return <KContainer.View />;
44
+ }
45
+
46
+ const isOutgoing = props.position === 'right';
47
+
48
+ return (
49
+ <KContainer.View
50
+ style={[
51
+ styles.messageRow,
52
+ isOutgoing ? styles.messageRowRight : styles.messageRowLeft,
53
+ ]}
54
+ >
55
+ {renderChat ? (
56
+ renderChat(currentMessage.openIMMessage)
57
+ ) : (
58
+ <ChatMessageBubble
59
+ message={currentMessage}
60
+ position={props.position}
61
+ />
62
+ )}
63
+ </KContainer.View>
64
+ );
65
+ },
66
+ [renderChat]
67
+ );
68
+
69
+ const renderDay = useCallback(
70
+ (props: DayProps) => <ChatDay {...props} />,
71
+ []
72
+ );
73
+
74
+ const renderLoadEarlier = useCallback(
75
+ (props: LoadEarlierMessagesProps) => <ChatLoadEarlier {...props} />,
76
+ []
77
+ );
78
+
79
+ const onLoadEarlierRef = useRef(onLoadEarlier);
80
+ onLoadEarlierRef.current = onLoadEarlier;
81
+
82
+ const handleLoadEarlier = useCallback(() => {
83
+ onLoadEarlierRef.current?.();
84
+ }, []);
85
+
86
+ const loadEarlierMessagesProps = useMemo(
87
+ () =>
88
+ onLoadEarlier
89
+ ? {
90
+ isAvailable: !!hasMoreEarlier,
91
+ isInfiniteScrollEnabled: true,
92
+ onPress: handleLoadEarlier,
93
+ isLoading: isLoadingEarlier ?? false,
94
+ }
95
+ : undefined,
96
+ [hasMoreEarlier, isLoadingEarlier, onLoadEarlier, handleLoadEarlier]
97
+ );
98
+
99
+ const renderScrollToBottom = useCallback(() => <ChatScrollToBottom />, []);
100
+
101
+ return (
102
+ <KContainer.View flex background={KColors.white}>
103
+ {isLoading ? (
104
+ <KContainer.View flex center>
105
+ <ActivityIndicator
106
+ color={KColors.palette.primary.w400}
107
+ size="small"
108
+ />
109
+ </KContainer.View>
110
+ ) : (
111
+ <GiftedChat
112
+ messages={giftedMessages}
113
+ user={user}
114
+ renderInputToolbar={() => null}
115
+ renderAvatar={() => null}
116
+ renderMessage={renderMessage}
117
+ renderDay={renderDay}
118
+ renderLoadEarlier={onLoadEarlier ? renderLoadEarlier : undefined}
119
+ isDayAnimationEnabled={false}
120
+ keyboardAvoidingViewProps={{ enabled: false }}
121
+ messagesContainerStyle={styles.messagesContainer}
122
+ minInputToolbarHeight={0}
123
+ loadEarlierMessagesProps={loadEarlierMessagesProps}
124
+ listProps={{
125
+ showsVerticalScrollIndicator: false,
126
+ keyboardShouldPersistTaps: 'handled',
127
+ contentContainerStyle: styles.content,
128
+ onEndReachedThreshold: 0.5,
129
+ }}
130
+ reply={{
131
+ swipe: {
132
+ isEnabled: true,
133
+ direction: 'left',
134
+ },
135
+ }}
136
+ isScrollToBottomEnabled
137
+ scrollToBottomComponent={renderScrollToBottom}
138
+ scrollToBottomStyle={styles.scrollToBottom}
139
+ scrollToBottomContentStyle={styles.scrollToBottomContent}
140
+ />
141
+ )}
142
+ </KContainer.View>
143
+ );
144
+ }
145
+ );
146
+
147
+ ChatList.displayName = 'ChatList';
148
+
149
+ const styles = StyleSheet.create({
150
+ messagesContainer: {
151
+ backgroundColor: KColors.white,
152
+ },
153
+ content: {
154
+ paddingVertical: KSpacingValue['0.75rem'],
155
+ flexGrow: 1,
156
+ },
157
+ messageRow: {
158
+ width: '100%',
159
+ paddingHorizontal: KSpacingValue['0.75rem'],
160
+ marginBottom: KSpacingValue['0.25rem'],
161
+ },
162
+ messageRowLeft: {
163
+ alignItems: 'flex-start',
164
+ },
165
+ messageRowRight: {
166
+ alignItems: 'flex-end',
167
+ },
168
+ scrollToBottom: {
169
+ position: 'absolute',
170
+ bottom: 20,
171
+ right: 16,
172
+ zIndex: 999,
173
+ },
174
+ scrollToBottomContent: {
175
+ backgroundColor: KColors.white,
176
+ width: 32,
177
+ height: 32,
178
+ borderRadius: 16,
179
+ shadowColor: KColors.black,
180
+ shadowOffset: { width: 0, height: 1 },
181
+ shadowOpacity: 0.16,
182
+ shadowRadius: 8,
183
+ elevation: 8,
184
+ justifyContent: 'center',
185
+ alignItems: 'center',
186
+ },
187
+ });
@@ -0,0 +1,20 @@
1
+ import { memo } from 'react';
2
+ import { ActivityIndicator } from 'react-native';
3
+ import { KContainer, KColors } from '@droppii/libs';
4
+ import type { LoadEarlierMessagesProps } from 'react-native-gifted-chat';
5
+
6
+ export const ChatLoadEarlier = memo(
7
+ ({ isLoading = false }: LoadEarlierMessagesProps) => {
8
+ if (!isLoading) {
9
+ return null;
10
+ }
11
+
12
+ return (
13
+ <KContainer.View center marginV="0.75rem">
14
+ <ActivityIndicator color={KColors.palette.primary.w400} size="small" />
15
+ </KContainer.View>
16
+ );
17
+ }
18
+ );
19
+
20
+ ChatLoadEarlier.displayName = 'ChatLoadEarlier';
@@ -0,0 +1,108 @@
1
+ import { memo, useCallback } from 'react';
2
+ import { FlatList, type ListRenderItem, StyleSheet } from 'react-native';
3
+ import {
4
+ KContainer,
5
+ KImage,
6
+ KLabel,
7
+ KColors,
8
+ KSpacingValue,
9
+ } from '@droppii/libs';
10
+ import { useChatActionPress } from './useChatActionPress';
11
+ import type { DChatQuickAction, ChatQuickActionsProps } from './types';
12
+
13
+ const QuickActionItem = memo(
14
+ ({
15
+ action,
16
+ onPress,
17
+ }: {
18
+ action: DChatQuickAction;
19
+ onPress: (action: DChatQuickAction) => void;
20
+ }) => {
21
+ const handlePress = useCallback(() => {
22
+ onPress(action);
23
+ }, [action, onPress]);
24
+
25
+ return (
26
+ <KContainer.Touchable
27
+ row
28
+ alignItems
29
+ onPress={handlePress}
30
+ disabled={action.disabled}
31
+ paddingH="0.75rem"
32
+ paddingV="0.375rem"
33
+ marginR="0.5rem"
34
+ background={KColors.palette.gray.w25}
35
+ br="3x"
36
+ activeOpacity={0.7}
37
+ >
38
+ <KImage.VectorIcons
39
+ name={action.iconName}
40
+ provider={action.iconProvider ?? 'MaterialCommunityIcons'}
41
+ size={14}
42
+ color={
43
+ action.disabled ? KColors.palette.gray.w300 : KColors.gray.dark
44
+ }
45
+ />
46
+ <KLabel.Text
47
+ typo="TextXsMedium"
48
+ color={
49
+ action.disabled ? KColors.palette.gray.w300 : KColors.gray.dark
50
+ }
51
+ marginL="0.25rem"
52
+ numberOfLines={1}
53
+ >
54
+ {action.label}
55
+ </KLabel.Text>
56
+ </KContainer.Touchable>
57
+ );
58
+ }
59
+ );
60
+
61
+ QuickActionItem.displayName = 'QuickActionItem';
62
+
63
+ export const ChatQuickActions = memo(
64
+ ({ actions, onActionPress, renderAction }: ChatQuickActionsProps) => {
65
+ const handleActionPress = useChatActionPress(onActionPress);
66
+
67
+ const renderItem = useCallback<ListRenderItem<DChatQuickAction>>(
68
+ ({ item }) => {
69
+ const onPress = () => handleActionPress(item);
70
+
71
+ if (renderAction) {
72
+ return <>{renderAction(item, onPress)}</>;
73
+ }
74
+
75
+ return <QuickActionItem action={item} onPress={handleActionPress} />;
76
+ },
77
+ [handleActionPress, renderAction]
78
+ );
79
+
80
+ const keyExtractor = useCallback((item: DChatQuickAction) => item.id, []);
81
+
82
+ if (!actions?.length) {
83
+ return null;
84
+ }
85
+
86
+ return (
87
+ <KContainer.View paddingT="0.75rem" paddingB="0.25rem">
88
+ <FlatList
89
+ data={actions}
90
+ horizontal
91
+ renderItem={renderItem}
92
+ keyExtractor={keyExtractor}
93
+ showsHorizontalScrollIndicator={false}
94
+ contentContainerStyle={styles.content}
95
+ keyboardShouldPersistTaps="handled"
96
+ />
97
+ </KContainer.View>
98
+ );
99
+ }
100
+ );
101
+
102
+ ChatQuickActions.displayName = 'ChatQuickActions';
103
+
104
+ const styles = StyleSheet.create({
105
+ content: {
106
+ paddingHorizontal: KSpacingValue['0.75rem'],
107
+ },
108
+ });
@@ -0,0 +1,8 @@
1
+ import { memo } from 'react';
2
+ import { KImage, KColors } from '@droppii/libs';
3
+
4
+ export const ChatScrollToBottom = memo(() => (
5
+ <KImage.VectorIcons name="arrow-down-o" size={16} color={KColors.black} />
6
+ ));
7
+
8
+ ChatScrollToBottom.displayName = 'ChatScrollToBottom';
@@ -0,0 +1,73 @@
1
+ import { memo } from 'react';
2
+ import { StyleSheet } from 'react-native';
3
+ import { KContainer, KLabel, KSpacingValue } from '@droppii/libs';
4
+ import type { ChatMessageBubbleProps } from './messages/types';
5
+ import { CHAT_BUBBLE_COLORS } from './constants';
6
+
7
+ const formatMessageTime = (createdAt: Date | number) => {
8
+ const date = new Date(createdAt);
9
+ if (Number.isNaN(date.getTime())) {
10
+ return '';
11
+ }
12
+
13
+ return date.toLocaleTimeString('vi-VN', {
14
+ hour: '2-digit',
15
+ minute: '2-digit',
16
+ hour12: false,
17
+ });
18
+ };
19
+
20
+ export const ChatTextBubble = memo(
21
+ ({ message, position }: ChatMessageBubbleProps) => {
22
+ const isOutgoing = position === 'right';
23
+ const timeLabel = formatMessageTime(message.createdAt);
24
+
25
+ if (!message.text?.trim()) {
26
+ return null;
27
+ }
28
+
29
+ return (
30
+ <KContainer.View style={styles.wrapper}>
31
+ <KContainer.View
32
+ style={[
33
+ styles.bubble,
34
+ isOutgoing ? styles.bubbleSent : styles.bubbleReceived,
35
+ ]}
36
+ >
37
+ <KLabel.Text typo="TextMdNormal" color={CHAT_BUBBLE_COLORS.text}>
38
+ {message.text}
39
+ </KLabel.Text>
40
+ </KContainer.View>
41
+
42
+ {!isOutgoing && timeLabel ? (
43
+ <KLabel.Text
44
+ typo="TextXsNormal"
45
+ color={CHAT_BUBBLE_COLORS.timestamp}
46
+ marginL={'0.25rem'}
47
+ >
48
+ {timeLabel}
49
+ </KLabel.Text>
50
+ ) : null}
51
+ </KContainer.View>
52
+ );
53
+ }
54
+ );
55
+
56
+ ChatTextBubble.displayName = 'ChatTextBubble';
57
+
58
+ const styles = StyleSheet.create({
59
+ wrapper: {
60
+ maxWidth: '80%',
61
+ },
62
+ bubble: {
63
+ paddingHorizontal: KSpacingValue['0.75rem'],
64
+ paddingVertical: KSpacingValue['0.5rem'],
65
+ borderRadius: KSpacingValue['1.25rem'],
66
+ },
67
+ bubbleReceived: {
68
+ backgroundColor: CHAT_BUBBLE_COLORS.received,
69
+ },
70
+ bubbleSent: {
71
+ backgroundColor: CHAT_BUBBLE_COLORS.sent,
72
+ },
73
+ });
@@ -0,0 +1,76 @@
1
+ import { KColors } from '@droppii/libs';
2
+ import type { DChatQuickAction, DChatAttachmentAction } from './types';
3
+
4
+ export const CHAT_BUBBLE_COLORS = {
5
+ received: 'rgba(131, 137, 157, 0.1)',
6
+ sent: 'rgba(0, 81, 255, 0.1)',
7
+ text: KColors.gray.dark,
8
+ timestamp: KColors.gray.light,
9
+ dayLabel: KColors.gray.light,
10
+ } as const;
11
+
12
+ export const DEFAULT_Chat_QUICK_ACTIONS: DChatQuickAction[] = [
13
+ {
14
+ id: 'restart',
15
+ label: 'Bắt đầu lại',
16
+ iconName: 'refresh',
17
+ },
18
+ {
19
+ id: 'send-order',
20
+ label: 'Gửi đơn hàng',
21
+ iconName: 'file-document-outline',
22
+ },
23
+ {
24
+ id: 'scam-warning',
25
+ label: 'Cảnh báo lừa đảo/g...',
26
+ iconName: 'alert-outline',
27
+ },
28
+ ];
29
+
30
+ export const ATTACHMENT_PANEL_COLUMNS = 4;
31
+ export const ATTACHMENT_ITEM_HEIGHT = 100;
32
+ export const ATTACHMENT_PANEL_VERTICAL_PADDING = 16;
33
+
34
+ export const getAttachmentPanelHeight = (
35
+ actionCount: number,
36
+ columns = ATTACHMENT_PANEL_COLUMNS
37
+ ): number => {
38
+ const rows = Math.ceil(actionCount / columns);
39
+ return rows * ATTACHMENT_ITEM_HEIGHT + ATTACHMENT_PANEL_VERTICAL_PADDING;
40
+ };
41
+
42
+ /** @deprecated use getAttachmentPanelHeight */
43
+ export const DEFAULT_ATTACHMENT_PANEL_HEIGHT = getAttachmentPanelHeight(6);
44
+
45
+ export const DEFAULT_ATTACHMENT_ACTIONS: DChatAttachmentAction[] = [
46
+ {
47
+ id: 'gallery',
48
+ label: 'Ảnh/Video',
49
+ iconName: 'image-multiple-outline',
50
+ },
51
+ {
52
+ id: 'camera',
53
+ label: 'Chụp ảnh',
54
+ iconName: 'camera-outline',
55
+ },
56
+ {
57
+ id: 'file',
58
+ label: 'Đính kèm file',
59
+ iconName: 'paperclip',
60
+ },
61
+ {
62
+ id: 'order',
63
+ label: 'Gửi đơn hàng',
64
+ iconName: 'receipt',
65
+ },
66
+ {
67
+ id: 'product',
68
+ label: 'Gửi sản phẩm',
69
+ iconName: 'basket-outline',
70
+ },
71
+ {
72
+ id: 'poll',
73
+ label: 'Tạo bình chọn',
74
+ iconName: 'poll',
75
+ },
76
+ ];
@@ -0,0 +1,33 @@
1
+ export { default as ChatDetail } from './ChatDetail';
2
+ export { default as ChatDetailHeader } from './ChatDetailHeader';
3
+ export { ChatList } from './ChatList';
4
+ export { ChatComposer } from './ChatComposer';
5
+ export { ChatQuickActions } from './ChatQuickActions';
6
+ export { ChatAttachmentPanel } from './ChatAttachmentPanel';
7
+ export {
8
+ DEFAULT_Chat_QUICK_ACTIONS,
9
+ DEFAULT_ATTACHMENT_ACTIONS,
10
+ DEFAULT_ATTACHMENT_PANEL_HEIGHT,
11
+ } from './constants';
12
+ export type {
13
+ DChatActionItem,
14
+ DChatActionIconProvider,
15
+ DChatQuickAction,
16
+ DChatAttachmentAction,
17
+ ChatDetailProps,
18
+ ChatDetailHeaderProps,
19
+ ChatListProps,
20
+ ChatComposerProps,
21
+ ChatQuickActionsProps,
22
+ ChatAttachmentPanelProps,
23
+ } from './types';
24
+ export type { DGiftedChatMessage } from '../../utils/giftedChatMessage';
25
+ export {
26
+ DChatMessageType,
27
+ CUSTOM_MESSAGE_DATA_TYPE,
28
+ } from '../../types/message';
29
+ export type { ChatMessageBubbleProps } from './messages/types';
30
+ export {
31
+ mapOpenIMMessageToGiftedChat,
32
+ mapOpenIMMessagesToGiftedChat,
33
+ } from '../../utils/giftedChatMessage';
@@ -0,0 +1,24 @@
1
+ import { memo } from 'react';
2
+ import { DChatMessageType } from '../../../types/message';
3
+ import { ChatTextBubble } from '../ChatTextBubble';
4
+ import type { ChatMessageBubbleProps, ChatMessageRenderer } from './types';
5
+
6
+ const getMessageRenderers = (): Partial<
7
+ Record<DChatMessageType, ChatMessageRenderer>
8
+ > => ({
9
+ [DChatMessageType.Text]: ChatTextBubble,
10
+ });
11
+
12
+ export const ChatMessageBubble = memo(
13
+ ({ message, position }: ChatMessageBubbleProps) => {
14
+ const Renderer = getMessageRenderers()[message.messageType];
15
+
16
+ if (!Renderer) {
17
+ return null;
18
+ }
19
+
20
+ return <Renderer message={message} position={position} />;
21
+ }
22
+ );
23
+
24
+ ChatMessageBubble.displayName = 'ChatMessageBubble';
@@ -0,0 +1,14 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { IMessage } from 'react-native-gifted-chat';
3
+ import type { DMessageItem } from '../../../types/chat';
4
+ import type { DChatMessageType } from '../../../types/message';
5
+
6
+ export type ChatMessageBubbleProps = {
7
+ message: IMessage & {
8
+ openIMMessage: DMessageItem;
9
+ messageType: DChatMessageType;
10
+ };
11
+ position: 'left' | 'right';
12
+ };
13
+
14
+ export type ChatMessageRenderer = ComponentType<ChatMessageBubbleProps>;
@@ -0,0 +1,97 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { DChatType } from '../../types/chat';
3
+ import type { DMessageItem } from '../../types/chat';
4
+
5
+ export type DChatActionIconProvider = 'MaterialCommunityIcons' | 'DroppiiNew';
6
+
7
+ export interface DChatActionItem {
8
+ id: string;
9
+ label: string;
10
+ iconName: string;
11
+ iconProvider?: DChatActionIconProvider;
12
+ disabled?: boolean;
13
+ onPress?: () => void;
14
+ meta?: Record<string, unknown>;
15
+ }
16
+
17
+ export type DChatQuickAction = DChatActionItem;
18
+ export type DChatAttachmentAction = DChatActionItem;
19
+
20
+ export interface ChatDetailHeaderProps {
21
+ title: string;
22
+ subtitle?: string;
23
+ avatarUri?: string | null;
24
+ avatarFullName?: string;
25
+ chatType?: DChatType;
26
+ showAddMember?: boolean;
27
+ onBack?: () => void;
28
+ onPressSearch?: () => void;
29
+ onPressAddMember?: () => void;
30
+ onPressMenu?: () => void;
31
+ onPressAvatar?: () => void;
32
+ }
33
+
34
+ export interface ChatQuickActionsProps {
35
+ actions?: DChatQuickAction[];
36
+ onActionPress?: (action: DChatQuickAction) => void;
37
+ renderAction?: (action: DChatQuickAction, onPress: () => void) => ReactNode;
38
+ }
39
+
40
+ export interface ChatAttachmentPanelProps {
41
+ actions?: DChatAttachmentAction[];
42
+ columns?: number;
43
+ onActionPress?: (action: DChatAttachmentAction) => void;
44
+ renderAction?: (
45
+ action: DChatAttachmentAction,
46
+ onPress: () => void
47
+ ) => ReactNode;
48
+ }
49
+
50
+ export interface ChatComposerProps {
51
+ value?: string;
52
+ placeholder?: string;
53
+ onChangeText?: (text: string) => void;
54
+ onSend?: () => void;
55
+ onPressAttach?: () => void;
56
+ onPressEmoji?: () => void;
57
+ quickActions?: DChatQuickAction[];
58
+ attachmentActions?: DChatAttachmentAction[];
59
+ onQuickActionPress?: (action: DChatQuickAction) => void;
60
+ onAttachmentAction?: (action: DChatAttachmentAction) => void;
61
+ renderQuickAction?: ChatQuickActionsProps['renderAction'];
62
+ renderAttachmentAction?: ChatAttachmentPanelProps['renderAction'];
63
+ attachmentColumns?: number;
64
+ }
65
+
66
+ export interface ChatListProps {
67
+ messages?: DMessageItem[];
68
+ currentUserId?: string;
69
+ renderChat?: (item: DMessageItem) => ReactNode;
70
+ onLoadEarlier?: () => void;
71
+ isLoading?: boolean;
72
+ isLoadingEarlier?: boolean;
73
+ hasMoreEarlier?: boolean;
74
+ }
75
+
76
+ export interface ChatDetailProps extends ChatDetailHeaderProps {
77
+ messages?: DMessageItem[];
78
+ currentUserId?: string;
79
+ renderChat?: (item: DMessageItem) => ReactNode;
80
+ onLoadEarlier?: () => void;
81
+ isLoading?: boolean;
82
+ isLoadingEarlier?: boolean;
83
+ hasMoreEarlier?: boolean;
84
+ quickActions?: DChatQuickAction[];
85
+ attachmentActions?: DChatAttachmentAction[];
86
+ inputValue?: string;
87
+ inputPlaceholder?: string;
88
+ onChangeInput?: (text: string) => void;
89
+ onSend?: () => void;
90
+ onPressAttach?: () => void;
91
+ onPressEmoji?: () => void;
92
+ onQuickActionPress?: (action: DChatQuickAction) => void;
93
+ onAttachmentAction?: (action: DChatAttachmentAction) => void;
94
+ renderQuickAction?: ChatQuickActionsProps['renderAction'];
95
+ renderAttachmentAction?: ChatAttachmentPanelProps['renderAction'];
96
+ attachmentColumns?: number;
97
+ }
@@ -0,0 +1,17 @@
1
+ import { useCallback } from 'react';
2
+ import type { DChatActionItem } from './types';
3
+
4
+ export const useChatActionPress = <T extends DChatActionItem>(
5
+ onActionPress?: (action: T) => void
6
+ ) =>
7
+ useCallback(
8
+ (action: T) => {
9
+ if (action.disabled) {
10
+ return;
11
+ }
12
+
13
+ action.onPress?.();
14
+ onActionPress?.(action);
15
+ },
16
+ [onActionPress]
17
+ );