react-native-gifted-chat 3.3.0 → 3.3.3

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 (326) hide show
  1. package/CHANGELOG.md +435 -0
  2. package/README.md +68 -12
  3. package/lib/Actions.d.ts +16 -0
  4. package/lib/Actions.d.ts.map +1 -0
  5. package/lib/Actions.js +65 -0
  6. package/lib/Actions.js.map +1 -0
  7. package/lib/Avatar.d.ts +19 -0
  8. package/lib/Avatar.d.ts.map +1 -0
  9. package/lib/Avatar.js +93 -0
  10. package/lib/Avatar.js.map +1 -0
  11. package/lib/Bubble/index.d.ts +6 -0
  12. package/lib/Bubble/index.d.ts.map +1 -0
  13. package/lib/Bubble/index.js +269 -0
  14. package/lib/Bubble/index.js.map +1 -0
  15. package/lib/Bubble/styles.d.ts +57 -0
  16. package/lib/Bubble/styles.d.ts.map +1 -0
  17. package/lib/Bubble/styles.js +59 -0
  18. package/lib/Bubble/styles.js.map +1 -0
  19. package/lib/Bubble/types.d.ts +59 -0
  20. package/lib/Bubble/types.d.ts.map +1 -0
  21. package/lib/Bubble/types.js +2 -0
  22. package/lib/Bubble/types.js.map +1 -0
  23. package/lib/Color.d.ts +18 -0
  24. package/lib/Color.d.ts.map +1 -0
  25. package/lib/Color.js +18 -0
  26. package/lib/Color.js.map +1 -0
  27. package/lib/Composer.d.ts +9 -0
  28. package/lib/Composer.d.ts.map +1 -0
  29. package/lib/Composer.js +56 -0
  30. package/lib/Composer.js.map +1 -0
  31. package/lib/Constant.d.ts +8 -0
  32. package/lib/Constant.d.ts.map +1 -0
  33. package/lib/Constant.js +8 -0
  34. package/lib/Constant.js.map +1 -0
  35. package/lib/Day/index.d.ts +5 -0
  36. package/lib/Day/index.d.ts.map +1 -0
  37. package/lib/Day/index.js +40 -0
  38. package/lib/Day/index.js.map +1 -0
  39. package/lib/Day/styles.d.ts +21 -0
  40. package/lib/Day/styles.d.ts.map +1 -0
  41. package/lib/Day/styles.js +22 -0
  42. package/lib/Day/styles.js.map +1 -0
  43. package/lib/Day/types.d.ts +11 -0
  44. package/lib/Day/types.d.ts.map +1 -0
  45. package/lib/Day/types.js +2 -0
  46. package/lib/Day/types.js.map +1 -0
  47. package/lib/GiftedAvatar.d.ts +12 -0
  48. package/lib/GiftedAvatar.d.ts.map +1 -0
  49. package/lib/GiftedAvatar.js +101 -0
  50. package/lib/GiftedAvatar.js.map +1 -0
  51. package/lib/GiftedChat/index.d.ts +10 -0
  52. package/lib/GiftedChat/index.d.ts.map +1 -0
  53. package/lib/GiftedChat/index.js +241 -0
  54. package/lib/GiftedChat/index.js.map +1 -0
  55. package/lib/GiftedChat/styles.d.ts +13 -0
  56. package/lib/GiftedChat/styles.d.ts.map +1 -0
  57. package/lib/GiftedChat/styles.js +13 -0
  58. package/lib/GiftedChat/styles.js.map +1 -0
  59. package/lib/GiftedChat/types.d.ts +90 -0
  60. package/lib/GiftedChat/types.d.ts.map +1 -0
  61. package/lib/GiftedChat/types.js +2 -0
  62. package/lib/GiftedChat/types.js.map +1 -0
  63. package/lib/GiftedChatContext.d.ts +11 -0
  64. package/lib/GiftedChatContext.d.ts.map +1 -0
  65. package/lib/GiftedChatContext.js +10 -0
  66. package/lib/GiftedChatContext.js.map +1 -0
  67. package/lib/InputToolbar.d.ts +36 -0
  68. package/lib/InputToolbar.d.ts.map +1 -0
  69. package/lib/InputToolbar.js +108 -0
  70. package/lib/InputToolbar.js.map +1 -0
  71. package/lib/LoadEarlierMessages.d.ts +17 -0
  72. package/lib/LoadEarlierMessages.d.ts.map +1 -0
  73. package/lib/LoadEarlierMessages.js +45 -0
  74. package/lib/LoadEarlierMessages.js.map +1 -0
  75. package/lib/Message/index.d.ts +6 -0
  76. package/lib/Message/index.d.ts.map +1 -0
  77. package/lib/Message/index.js +180 -0
  78. package/lib/Message/index.js.map +1 -0
  79. package/lib/Message/styles.d.ts +18 -0
  80. package/lib/Message/styles.d.ts.map +1 -0
  81. package/lib/Message/styles.js +18 -0
  82. package/lib/Message/styles.js.map +1 -0
  83. package/lib/Message/types.d.ts +25 -0
  84. package/lib/Message/types.d.ts.map +1 -0
  85. package/lib/Message/types.js +2 -0
  86. package/lib/Message/types.js.map +1 -0
  87. package/lib/MessageAudio.d.ts +3 -0
  88. package/lib/MessageAudio.d.ts.map +1 -0
  89. package/lib/MessageAudio.js +25 -0
  90. package/lib/MessageAudio.js.map +1 -0
  91. package/lib/MessageImage.d.ts +12 -0
  92. package/lib/MessageImage.d.ts.map +1 -0
  93. package/lib/MessageImage.js +164 -0
  94. package/lib/MessageImage.js.map +1 -0
  95. package/lib/MessageReply.d.ts +15 -0
  96. package/lib/MessageReply.d.ts.map +1 -0
  97. package/lib/MessageReply.js +103 -0
  98. package/lib/MessageReply.js.map +1 -0
  99. package/lib/MessageText.d.ts +24 -0
  100. package/lib/MessageText.d.ts.map +1 -0
  101. package/lib/MessageText.js +41 -0
  102. package/lib/MessageText.js.map +1 -0
  103. package/lib/MessageVideo.d.ts +3 -0
  104. package/lib/MessageVideo.d.ts.map +1 -0
  105. package/lib/MessageVideo.js +25 -0
  106. package/lib/MessageVideo.js.map +1 -0
  107. package/lib/MessagesContainer/components/DayAnimated/index.d.ts +5 -0
  108. package/lib/MessagesContainer/components/DayAnimated/index.d.ts.map +1 -0
  109. package/lib/MessagesContainer/components/DayAnimated/index.js +92 -0
  110. package/lib/MessagesContainer/components/DayAnimated/index.js.map +1 -0
  111. package/lib/MessagesContainer/components/DayAnimated/styles.d.ts +12 -0
  112. package/lib/MessagesContainer/components/DayAnimated/styles.d.ts.map +1 -0
  113. package/lib/MessagesContainer/components/DayAnimated/styles.js +12 -0
  114. package/lib/MessagesContainer/components/DayAnimated/styles.js.map +1 -0
  115. package/lib/MessagesContainer/components/DayAnimated/types.d.ts +18 -0
  116. package/lib/MessagesContainer/components/DayAnimated/types.d.ts.map +1 -0
  117. package/lib/MessagesContainer/components/DayAnimated/types.js +2 -0
  118. package/lib/MessagesContainer/components/DayAnimated/types.js.map +1 -0
  119. package/lib/MessagesContainer/components/Item/index.d.ts +23 -0
  120. package/lib/MessagesContainer/components/Item/index.d.ts.map +1 -0
  121. package/lib/MessagesContainer/components/Item/index.js +120 -0
  122. package/lib/MessagesContainer/components/Item/index.js.map +1 -0
  123. package/lib/MessagesContainer/components/Item/types.d.ts +19 -0
  124. package/lib/MessagesContainer/components/Item/types.d.ts.map +1 -0
  125. package/lib/MessagesContainer/components/Item/types.js +2 -0
  126. package/lib/MessagesContainer/components/Item/types.js.map +1 -0
  127. package/lib/MessagesContainer/index.d.ts +6 -0
  128. package/lib/MessagesContainer/index.d.ts.map +1 -0
  129. package/lib/MessagesContainer/index.js +258 -0
  130. package/lib/MessagesContainer/index.js.map +1 -0
  131. package/lib/MessagesContainer/styles.d.ts +55 -0
  132. package/lib/MessagesContainer/styles.d.ts.map +1 -0
  133. package/lib/MessagesContainer/styles.js +42 -0
  134. package/lib/MessagesContainer/styles.js.map +1 -0
  135. package/lib/MessagesContainer/types.d.ts +88 -0
  136. package/lib/MessagesContainer/types.d.ts.map +1 -0
  137. package/lib/MessagesContainer/types.js +10 -0
  138. package/lib/MessagesContainer/types.js.map +1 -0
  139. package/lib/Models.d.ts +58 -0
  140. package/lib/Models.d.ts.map +1 -0
  141. package/lib/Models.js +2 -0
  142. package/lib/Models.js.map +1 -0
  143. package/lib/QuickReplies.d.ts +16 -0
  144. package/lib/QuickReplies.d.ts.map +1 -0
  145. package/lib/QuickReplies.js +108 -0
  146. package/lib/QuickReplies.js.map +1 -0
  147. package/lib/Reply/index.d.ts +2 -0
  148. package/lib/Reply/index.d.ts.map +1 -0
  149. package/lib/Reply/index.js +2 -0
  150. package/lib/Reply/index.js.map +1 -0
  151. package/lib/Reply/types.d.ts +72 -0
  152. package/lib/Reply/types.d.ts.map +1 -0
  153. package/lib/Reply/types.js +2 -0
  154. package/lib/Reply/types.js.map +1 -0
  155. package/lib/ReplyPreview.d.ts +14 -0
  156. package/lib/ReplyPreview.d.ts.map +1 -0
  157. package/lib/ReplyPreview.js +95 -0
  158. package/lib/ReplyPreview.js.map +1 -0
  159. package/lib/Send.d.ts +19 -0
  160. package/lib/Send.d.ts.map +1 -0
  161. package/lib/Send.js +57 -0
  162. package/lib/Send.js.map +1 -0
  163. package/lib/SystemMessage.d.ts +14 -0
  164. package/lib/SystemMessage.d.ts.map +1 -0
  165. package/lib/SystemMessage.js +42 -0
  166. package/lib/SystemMessage.js.map +1 -0
  167. package/lib/Time.d.ts +12 -0
  168. package/lib/Time.d.ts.map +1 -0
  169. package/lib/Time.js +39 -0
  170. package/lib/Time.js.map +1 -0
  171. package/lib/TypingIndicator/index.d.ts +5 -0
  172. package/lib/TypingIndicator/index.d.ts.map +1 -0
  173. package/lib/TypingIndicator/index.js +94 -0
  174. package/lib/TypingIndicator/index.js.map +1 -0
  175. package/lib/TypingIndicator/styles.d.ts +21 -0
  176. package/lib/TypingIndicator/styles.d.ts.map +1 -0
  177. package/lib/TypingIndicator/styles.js +22 -0
  178. package/lib/TypingIndicator/styles.js.map +1 -0
  179. package/lib/TypingIndicator/types.d.ts +6 -0
  180. package/lib/TypingIndicator/types.d.ts.map +1 -0
  181. package/lib/TypingIndicator/types.js +2 -0
  182. package/lib/TypingIndicator/types.js.map +1 -0
  183. package/lib/components/MessageReply.d.ts +29 -0
  184. package/lib/components/MessageReply.d.ts.map +1 -0
  185. package/lib/components/MessageReply.js +87 -0
  186. package/lib/components/MessageReply.js.map +1 -0
  187. package/lib/components/ReplyPreview.d.ts +17 -0
  188. package/lib/components/ReplyPreview.d.ts.map +1 -0
  189. package/lib/components/ReplyPreview.js +148 -0
  190. package/lib/components/ReplyPreview.js.map +1 -0
  191. package/lib/components/TouchableOpacity.d.ts +9 -0
  192. package/lib/components/TouchableOpacity.d.ts.map +1 -0
  193. package/lib/components/TouchableOpacity.js +37 -0
  194. package/lib/components/TouchableOpacity.js.map +1 -0
  195. package/lib/hooks/useColorScheme.d.ts +8 -0
  196. package/lib/hooks/useColorScheme.d.ts.map +1 -0
  197. package/lib/hooks/useColorScheme.js +17 -0
  198. package/lib/hooks/useColorScheme.js.map +1 -0
  199. package/lib/hooks/useUpdateLayoutEffect.d.ts +9 -0
  200. package/lib/hooks/useUpdateLayoutEffect.d.ts.map +1 -0
  201. package/lib/hooks/useUpdateLayoutEffect.js +17 -0
  202. package/lib/hooks/useUpdateLayoutEffect.js.map +1 -0
  203. package/lib/index.d.ts +31 -0
  204. package/lib/index.d.ts.map +1 -0
  205. package/lib/index.js +31 -0
  206. package/lib/index.js.map +1 -0
  207. package/lib/linkParser.d.ts +39 -0
  208. package/lib/linkParser.d.ts.map +1 -0
  209. package/lib/linkParser.js +154 -0
  210. package/lib/linkParser.js.map +1 -0
  211. package/lib/logging.d.ts +3 -0
  212. package/lib/logging.d.ts.map +1 -0
  213. package/lib/logging.js +5 -0
  214. package/lib/logging.js.map +1 -0
  215. package/lib/styles.d.ts +14 -0
  216. package/lib/styles.d.ts.map +1 -0
  217. package/lib/styles.js +23 -0
  218. package/lib/styles.js.map +1 -0
  219. package/lib/types.d.ts +19 -0
  220. package/lib/types.d.ts.map +1 -0
  221. package/lib/types.js +2 -0
  222. package/lib/types.js.map +1 -0
  223. package/lib/utils.d.ts +8 -0
  224. package/lib/utils.d.ts.map +1 -0
  225. package/lib/utils.js +105 -0
  226. package/lib/utils.js.map +1 -0
  227. package/package.json +12 -11
  228. package/src/Actions.tsx +0 -110
  229. package/src/Avatar.tsx +0 -169
  230. package/src/Bubble/index.tsx +0 -407
  231. package/src/Bubble/styles.ts +0 -66
  232. package/src/Bubble/types.ts +0 -104
  233. package/src/Color.ts +0 -17
  234. package/src/Composer.tsx +0 -100
  235. package/src/Constant.ts +0 -8
  236. package/src/Day/index.tsx +0 -63
  237. package/src/Day/styles.ts +0 -22
  238. package/src/Day/types.ts +0 -15
  239. package/src/GiftedAvatar.tsx +0 -187
  240. package/src/GiftedChat/index.tsx +0 -420
  241. package/src/GiftedChat/styles.ts +0 -10
  242. package/src/GiftedChat/types.ts +0 -156
  243. package/src/GiftedChatContext.ts +0 -25
  244. package/src/InputToolbar.tsx +0 -177
  245. package/src/LoadEarlierMessages.tsx +0 -94
  246. package/src/Message/index.tsx +0 -273
  247. package/src/Message/styles.ts +0 -18
  248. package/src/Message/types.ts +0 -26
  249. package/src/MessageAudio.tsx +0 -29
  250. package/src/MessageImage.tsx +0 -251
  251. package/src/MessageReply.tsx +0 -160
  252. package/src/MessageText.tsx +0 -111
  253. package/src/MessageVideo.tsx +0 -29
  254. package/src/MessagesContainer/components/DayAnimated/index.tsx +0 -151
  255. package/src/MessagesContainer/components/DayAnimated/styles.ts +0 -12
  256. package/src/MessagesContainer/components/DayAnimated/types.ts +0 -12
  257. package/src/MessagesContainer/components/Item/index.tsx +0 -197
  258. package/src/MessagesContainer/components/Item/types.ts +0 -13
  259. package/src/MessagesContainer/index.tsx +0 -434
  260. package/src/MessagesContainer/styles.ts +0 -42
  261. package/src/MessagesContainer/types.ts +0 -102
  262. package/src/Models.ts +0 -66
  263. package/src/QuickReplies.tsx +0 -181
  264. package/src/Reply/index.ts +0 -1
  265. package/src/Reply/types.ts +0 -80
  266. package/src/ReplyPreview.tsx +0 -132
  267. package/src/Send.tsx +0 -115
  268. package/src/SystemMessage.tsx +0 -79
  269. package/src/Time.tsx +0 -64
  270. package/src/TypingIndicator/index.tsx +0 -155
  271. package/src/TypingIndicator/styles.ts +0 -22
  272. package/src/TypingIndicator/types.ts +0 -6
  273. package/src/__tests__/Actions.test.tsx +0 -9
  274. package/src/__tests__/Avatar.test.tsx +0 -17
  275. package/src/__tests__/Bubble.test.tsx +0 -17
  276. package/src/__tests__/Color.test.tsx +0 -5
  277. package/src/__tests__/Composer.test.tsx +0 -10
  278. package/src/__tests__/Constant.test.tsx +0 -5
  279. package/src/__tests__/Day.test.tsx +0 -20
  280. package/src/__tests__/DayAnimated.test.tsx +0 -46
  281. package/src/__tests__/GiftedAvatar.test.tsx +0 -10
  282. package/src/__tests__/GiftedChat.test.tsx +0 -60
  283. package/src/__tests__/InputToolbar.test.tsx +0 -10
  284. package/src/__tests__/LoadEarlier.test.tsx +0 -10
  285. package/src/__tests__/Message.test.tsx +0 -67
  286. package/src/__tests__/MessageImage.test.tsx +0 -24
  287. package/src/__tests__/MessageReply.test.tsx +0 -54
  288. package/src/__tests__/MessageText.test.tsx +0 -15
  289. package/src/__tests__/MessagesContainer.test.tsx +0 -38
  290. package/src/__tests__/ReplyPreview.test.tsx +0 -41
  291. package/src/__tests__/Send.test.tsx +0 -21
  292. package/src/__tests__/SystemMessage.test.tsx +0 -24
  293. package/src/__tests__/Time.test.tsx +0 -26
  294. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +0 -40
  295. package/src/__tests__/__snapshots__/Avatar.test.tsx.snap +0 -17
  296. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +0 -121
  297. package/src/__tests__/__snapshots__/Color.test.tsx.snap +0 -21
  298. package/src/__tests__/__snapshots__/Composer.test.tsx.snap +0 -51
  299. package/src/__tests__/__snapshots__/Constant.test.tsx.snap +0 -13
  300. package/src/__tests__/__snapshots__/Day.test.tsx.snap +0 -99
  301. package/src/__tests__/__snapshots__/DayAnimated.test.tsx.snap +0 -5
  302. package/src/__tests__/__snapshots__/GiftedAvatar.test.tsx.snap +0 -24
  303. package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +0 -169
  304. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +0 -145
  305. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +0 -33
  306. package/src/__tests__/__snapshots__/Message.test.tsx.snap +0 -510
  307. package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +0 -293
  308. package/src/__tests__/__snapshots__/MessageReply.test.tsx.snap +0 -181
  309. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +0 -29
  310. package/src/__tests__/__snapshots__/ReplyPreview.test.tsx.snap +0 -403
  311. package/src/__tests__/__snapshots__/Send.test.tsx.snap +0 -214
  312. package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +0 -77
  313. package/src/__tests__/__snapshots__/Time.test.tsx.snap +0 -22
  314. package/src/__tests__/data.ts +0 -8
  315. package/src/__tests__/utils.test.ts +0 -31
  316. package/src/components/MessageReply.tsx +0 -156
  317. package/src/components/ReplyPreview.tsx +0 -230
  318. package/src/components/TouchableOpacity.tsx +0 -67
  319. package/src/hooks/useColorScheme.ts +0 -18
  320. package/src/hooks/useUpdateLayoutEffect.ts +0 -21
  321. package/src/index.ts +0 -29
  322. package/src/linkParser.tsx +0 -255
  323. package/src/logging.ts +0 -8
  324. package/src/styles.ts +0 -25
  325. package/src/types.ts +0 -25
  326. package/src/utils.ts +0 -134
@@ -1,255 +0,0 @@
1
- import React from 'react'
2
- import { Text, TextStyle, StyleProp, Linking } from 'react-native'
3
-
4
- export type LinkType = 'url' | 'email' | 'phone' | 'mention' | 'hashtag'
5
-
6
- export interface ParsedLink {
7
- type: LinkType
8
- text: string
9
- url: string
10
- index: number
11
- length: number
12
- }
13
-
14
- export interface LinkMatcher {
15
- type: LinkType
16
- pattern: RegExp
17
- getLinkUrl?: (text: string) => string
18
- getLinkText?: (text: string) => string
19
- baseUrl?: string
20
- style?: StyleProp<TextStyle>
21
- renderLink?: (text: string, url: string, index: number, type: LinkType) => React.ReactNode
22
- onPress?: (url: string, type: LinkType) => void
23
- }
24
-
25
- interface LinkParserProps {
26
- text: string
27
- matchers?: LinkMatcher[]
28
- email?: boolean
29
- phone?: boolean
30
- url?: boolean
31
- hashtag?: boolean
32
- mention?: boolean
33
- hashtagUrl?: string
34
- mentionUrl?: string
35
- linkStyle?: StyleProp<TextStyle>
36
- onPress?: (url: string, type: LinkType) => void
37
- stripPrefix?: boolean
38
- textStyle?: StyleProp<TextStyle>
39
- TextComponent?: React.ComponentType<any>
40
- }
41
-
42
- const DEFAULT_MATCHERS: LinkMatcher[] = [
43
- {
44
- type: 'url',
45
- pattern: /(?:https?:\/\/(?:www\.)?|www\.)[^\s]+|(?<![A-Za-z0-9_.@])(?![A-Za-z0-9._%+-]*@)[a-zA-Z0-9][a-zA-Z0-9-]*\.(?!@)[a-zA-Z]{2,}(?![A-Za-z0-9._%+-]*@)(?:\/[^\s]*)?/gi,
46
- getLinkUrl: (text: string) => {
47
- if (!/^https?:\/\//i.test(text))
48
- return `http://${text}`
49
-
50
- return text
51
- },
52
- },
53
- {
54
- type: 'email',
55
- pattern: /(?<![A-Za-z0-9])([a-zA-Z0-9][a-zA-Z0-9._%+-]*@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/gi,
56
- getLinkUrl: (text: string) => `mailto:${text}`,
57
- },
58
- {
59
- type: 'phone',
60
- pattern: /(?<![A-Za-z0-9_])(?:\+?\d{1,3}[\s.\-]?)?\(?\d{1,4}\)?[\s.\-]?\d{1,4}[\s.\-]?\d{1,9}(?![A-Za-z0-9_]|\.[a-z]{2,4})/gi,
61
- getLinkUrl: (text: string) => {
62
- const cleaned = text.replace(/[\s.()\-]/g, '')
63
- return `tel:${cleaned}`
64
- },
65
- },
66
- {
67
- type: 'hashtag',
68
- pattern: /#[\w]+/g,
69
- getLinkUrl: (text: string) => text,
70
- baseUrl: undefined,
71
- },
72
- {
73
- type: 'mention',
74
- pattern: /(?<![a-zA-Z0-9._%+-])@[\w-]+/g,
75
- getLinkUrl: (text: string) => text,
76
- baseUrl: undefined,
77
- },
78
- ]
79
-
80
- function parseLinks(text: string, matchers: LinkMatcher[]): ParsedLink[] {
81
- const links: ParsedLink[] = []
82
-
83
- matchers.forEach(matcher => {
84
- const matches = text.matchAll(matcher.pattern)
85
- for (const match of matches)
86
- if (match.index !== undefined) {
87
- const matchText = match[0]
88
- const url = matcher.getLinkUrl
89
- ? matcher.getLinkUrl(matchText)
90
- : matchText
91
- const linkText = matcher.getLinkText
92
- ? matcher.getLinkText(matchText)
93
- : matchText
94
-
95
- links.push({
96
- type: matcher.type,
97
- text: linkText,
98
- url,
99
- index: match.index,
100
- length: matchText.length,
101
- })
102
- }
103
-
104
- })
105
-
106
- // Sort by index to maintain order
107
- return links.sort((a, b) => a.index - b.index)
108
- }
109
-
110
- function removeOverlaps(links: ParsedLink[]): ParsedLink[] {
111
- const filtered: ParsedLink[] = []
112
-
113
- for (const link of links) {
114
- const hasOverlap = filtered.some(existing => {
115
- const existingEnd = existing.index + existing.length
116
- const linkEnd = link.index + link.length
117
-
118
- return (
119
- (link.index >= existing.index && link.index < existingEnd) ||
120
- (linkEnd > existing.index && linkEnd <= existingEnd) ||
121
- (link.index <= existing.index && linkEnd >= existingEnd)
122
- )
123
- })
124
-
125
- if (!hasOverlap)
126
- filtered.push(link)
127
-
128
- }
129
-
130
- return filtered
131
- }
132
-
133
- export function LinkParser({
134
- text,
135
- matchers: customMatchers,
136
- email = true,
137
- phone = true,
138
- url = true,
139
- hashtag = false,
140
- mention = false,
141
- hashtagUrl,
142
- mentionUrl,
143
- linkStyle,
144
- onPress,
145
- stripPrefix = true,
146
- textStyle,
147
- TextComponent = Text,
148
- }: LinkParserProps): React.ReactElement {
149
- const activeMatchers: LinkMatcher[] = []
150
-
151
- // Add custom matchers first (they take precedence)
152
- if (customMatchers)
153
- activeMatchers.push(...customMatchers)
154
-
155
-
156
- // Add default matchers based on flags
157
- if (url && !customMatchers?.some(m => m.type === 'url'))
158
- activeMatchers.push(DEFAULT_MATCHERS.find(m => m.type === 'url')!)
159
-
160
- if (email && !customMatchers?.some(m => m.type === 'email'))
161
- activeMatchers.push(DEFAULT_MATCHERS.find(m => m.type === 'email')!)
162
-
163
- if (phone && !customMatchers?.some(m => m.type === 'phone'))
164
- activeMatchers.push(DEFAULT_MATCHERS.find(m => m.type === 'phone')!)
165
-
166
- if (hashtag && !customMatchers?.some(m => m.type === 'hashtag')) {
167
- const hashtagMatcher = { ...DEFAULT_MATCHERS.find(m => m.type === 'hashtag')! }
168
- if (hashtagUrl) {
169
- hashtagMatcher.baseUrl = hashtagUrl
170
- const baseUrl = hashtagUrl.endsWith('/') ? hashtagUrl : `${hashtagUrl}/`
171
- hashtagMatcher.getLinkUrl = (text: string) => `${baseUrl}${text.substring(1)}`
172
- }
173
- activeMatchers.push(hashtagMatcher)
174
- }
175
-
176
- if (mention && !customMatchers?.some(m => m.type === 'mention')) {
177
- const mentionMatcher = { ...DEFAULT_MATCHERS.find(m => m.type === 'mention')! }
178
- if (mentionUrl) {
179
- mentionMatcher.baseUrl = mentionUrl
180
- const baseUrl = mentionUrl.endsWith('/') ? mentionUrl : `${mentionUrl}/`
181
- mentionMatcher.getLinkUrl = (text: string) => `${baseUrl}${text.substring(1)}`
182
- }
183
- activeMatchers.push(mentionMatcher)
184
- }
185
-
186
-
187
- const links = removeOverlaps(parseLinks(text, activeMatchers))
188
-
189
- if (links.length === 0)
190
- return <TextComponent style={textStyle}>{text}</TextComponent>
191
-
192
-
193
- const elements: React.ReactNode[] = []
194
- let lastIndex = 0
195
-
196
- links.forEach((link, index) => {
197
- // Add text before link
198
- if (link.index > lastIndex)
199
- elements.push(
200
- <TextComponent key={`text-${index}`} style={textStyle}>
201
- {text.substring(lastIndex, link.index)}
202
- </TextComponent>
203
- )
204
-
205
-
206
- // Find the matcher for this link
207
- const matcher = activeMatchers.find(m => m.type === link.type)
208
-
209
- // Handle link rendering
210
- if (matcher?.renderLink) {
211
- elements.push(matcher.renderLink(link.text, link.url, index, link.type))
212
- } else {
213
- const handlePress = () => {
214
- if (matcher?.onPress)
215
- matcher.onPress(link.url, link.type)
216
- else if (onPress)
217
- onPress(link.url, link.type)
218
- else
219
- // Default behavior
220
- Linking.openURL(link.url).catch(err => {
221
- console.warn('Failed to open URL:', err)
222
- })
223
-
224
- }
225
-
226
- let displayText = link.text
227
- if (stripPrefix && link.type === 'url')
228
- displayText = displayText.replace(/^https?:\/\//i, '')
229
-
230
-
231
- elements.push(
232
- <TextComponent
233
- key={`link-${index}`}
234
- style={[linkStyle, matcher?.style]}
235
- onPress={handlePress}
236
- >
237
- {displayText}
238
- </TextComponent>
239
- )
240
- }
241
-
242
- lastIndex = link.index + link.length
243
- })
244
-
245
- // Add remaining text
246
- if (lastIndex < text.length)
247
- elements.push(
248
- <TextComponent key='text-end' style={textStyle}>
249
- {text.substring(lastIndex)}
250
- </TextComponent>
251
- )
252
-
253
-
254
- return <TextComponent style={textStyle}>{elements}</TextComponent>
255
- }
package/src/logging.ts DELETED
@@ -1,8 +0,0 @@
1
- const styleString = (color: string) => `color: ${color}; font-weight: bold`
2
- const headerLog = '%c[react-native-gifted-chat]'
3
-
4
- export const warning = (...args: unknown[]) =>
5
- console.log(headerLog, styleString('orange'), ...args)
6
-
7
- export const error = (...args: unknown[]) =>
8
- console.log(headerLog, styleString('red'), ...args)
package/src/styles.ts DELETED
@@ -1,25 +0,0 @@
1
- import { StyleProp, StyleSheet, TextStyle, ViewStyle } from 'react-native'
2
-
3
- export default StyleSheet.create({
4
- fill: {
5
- flex: 1,
6
- },
7
- centerItems: {
8
- justifyContent: 'center',
9
- alignItems: 'center',
10
- },
11
- })
12
-
13
- export function getColorSchemeStyle<T>(styles: T, baseName: string, colorScheme?: string | null) {
14
- const key = `${baseName}_${colorScheme}` as keyof T
15
- return [styles[baseName as keyof T], styles[key]]
16
- }
17
-
18
- export function getStyleWithPosition<T>(styles: T, baseName: string, position?: 'left' | 'right' | null) {
19
- const stylesArray = [styles[baseName as keyof T]]
20
- if (position) {
21
- const key = `${baseName}_${position}` as keyof T
22
- stylesArray.push(styles[key])
23
- }
24
- return StyleSheet.flatten(stylesArray) as StyleProp<ViewStyle> | StyleProp<TextStyle>
25
- }
package/src/types.ts DELETED
@@ -1,25 +0,0 @@
1
- export * from './Models'
2
-
3
- export type { ActionsProps } from './Actions'
4
- export type { AvatarProps } from './Avatar'
5
- export type {
6
- BubbleProps,
7
- RenderMessageImageProps,
8
- RenderMessageVideoProps,
9
- RenderMessageAudioProps,
10
- RenderMessageTextProps
11
- } from './Bubble'
12
- export type { ComposerProps } from './Composer'
13
- export type { DayProps } from './Day'
14
- export type { GiftedAvatarProps } from './GiftedAvatar'
15
- export type { InputToolbarProps, ReplyPreviewProps } from './InputToolbar'
16
- export type { LoadEarlierMessagesProps } from './LoadEarlierMessages'
17
- export type { MessageProps } from './Message'
18
- export type { MessagesContainerProps } from './MessagesContainer'
19
- export type { MessageImageProps } from './MessageImage'
20
- export type { MessageTextProps } from './MessageText'
21
- export type { MessageReplyProps } from './components/MessageReply'
22
- export type { QuickRepliesProps } from './QuickReplies'
23
- export type { SendProps } from './Send'
24
- export type { SystemMessageProps } from './SystemMessage'
25
- export type { TimeProps } from './Time'
package/src/utils.ts DELETED
@@ -1,134 +0,0 @@
1
- import React, { useCallback, useEffect, useRef } from 'react'
2
- import dayjs from 'dayjs'
3
- import { IMessage } from './Models'
4
-
5
- export function renderComponentOrElement<TProps extends Record<string, any>>(
6
- component: React.ComponentType<TProps> | React.ReactElement | ((props: TProps) => React.ReactNode) | null | undefined,
7
- props: TProps
8
- ): React.ReactNode {
9
- if (!component)
10
- return null
11
-
12
- if (React.isValidElement(component))
13
- // If it's already a React element, clone it with props
14
- return React.cloneElement(component, props as any)
15
-
16
- if (typeof component === 'function') {
17
- // Check if it's a class component (has prototype.isReactComponent)
18
- // Class components must use React.createElement
19
- const isClassComponent = component.prototype && component.prototype.isReactComponent
20
-
21
- if (isClassComponent)
22
- return React.createElement(component as React.ComponentType<TProps>, props as any)
23
-
24
- // For function components and render functions, call directly
25
- // Using createElement with inline arrow functions causes unmount/remount
26
- // when function reference changes, this matches v2.x behavior
27
- return (component as (props: TProps) => React.ReactNode)(props)
28
- }
29
-
30
- // If it's neither, return it as-is
31
- return component
32
- }
33
-
34
- export function isSameDay (
35
- currentMessage: IMessage,
36
- diffMessage: IMessage | null | undefined
37
- ) {
38
- if (!diffMessage || !diffMessage.createdAt)
39
- return false
40
-
41
- const currentCreatedAt = dayjs(currentMessage.createdAt)
42
- const diffCreatedAt = dayjs(diffMessage.createdAt)
43
-
44
- if (!currentCreatedAt.isValid() || !diffCreatedAt.isValid())
45
- return false
46
-
47
- return currentCreatedAt.isSame(diffCreatedAt, 'day')
48
- }
49
-
50
- export function isSameUser (
51
- currentMessage: IMessage,
52
- diffMessage: IMessage | null | undefined
53
- ) {
54
- return !!(
55
- diffMessage &&
56
- diffMessage.user &&
57
- currentMessage.user &&
58
- diffMessage.user._id === currentMessage.user._id
59
- )
60
- }
61
-
62
- function processCallbackArguments (args: unknown[]): unknown[] {
63
- const [e, ...rest] = args
64
- const { nativeEvent } = (e as { nativeEvent?: unknown }) || {}
65
- let params: unknown[] = []
66
- if (e) {
67
- if (nativeEvent)
68
- params.push({ nativeEvent })
69
- else
70
- params.push(e)
71
- if (rest)
72
- params = params.concat(rest)
73
- }
74
-
75
- return params
76
- }
77
-
78
- export function useCallbackDebounced<T extends (...args: any[]) => any>(callbackFunc: T, deps: React.DependencyList = [], time: number): (...args: Parameters<T>) => void {
79
- const timeoutId = useRef<ReturnType<typeof setTimeout>>(undefined)
80
-
81
- const savedFunc = useCallback((...args: Parameters<T>) => {
82
- const params = processCallbackArguments(args)
83
- if (timeoutId.current)
84
- clearTimeout(timeoutId.current)
85
- timeoutId.current = setTimeout(() => {
86
- callbackFunc(...params as Parameters<T>)
87
- }, time)
88
- // eslint-disable-next-line react-hooks/exhaustive-deps
89
- }, [callbackFunc, time, ...deps])
90
-
91
- useEffect(() => {
92
- return () => {
93
- if (timeoutId.current)
94
- clearTimeout(timeoutId.current)
95
- }
96
- }, [])
97
-
98
- return savedFunc
99
- }
100
-
101
- export function useCallbackThrottled<T extends (...args: any[]) => any>(callbackFunc: T, deps: React.DependencyList = [], time: number): (...args: Parameters<T>) => void {
102
- const lastExecution = useRef<number>(0)
103
- const timeoutId = useRef<ReturnType<typeof setTimeout>>(undefined)
104
-
105
- // we use function instead of arrow to access arguments object
106
- const savedFunc = useCallback((...args: Parameters<T>) => {
107
- const params = processCallbackArguments(args)
108
-
109
- const now = Date.now()
110
- const timeSinceLastExecution = now - lastExecution.current
111
-
112
- if (timeSinceLastExecution >= time) {
113
- // Execute immediately if enough time has passed
114
- lastExecution.current = now
115
- callbackFunc(...params as Parameters<T>)
116
- } else {
117
- // Schedule execution for the remaining time
118
- clearTimeout(timeoutId.current)
119
- timeoutId.current = setTimeout(() => {
120
- lastExecution.current = Date.now()
121
- callbackFunc(...params as Parameters<T>)
122
- }, time - timeSinceLastExecution)
123
- }
124
- // eslint-disable-next-line react-hooks/exhaustive-deps
125
- }, [callbackFunc, time, ...deps])
126
-
127
- useEffect(() => {
128
- return () => {
129
- clearTimeout(timeoutId.current)
130
- }
131
- }, [])
132
-
133
- return savedFunc
134
- }