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,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,139 +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
- // Check for React.memo or React.forwardRef wrapped components
31
- // These have $$typeof property and should be rendered with createElement
32
- if (typeof component === 'object' && component !== null && '$$typeof' in component)
33
- return React.createElement(component as React.ComponentType<TProps>, props as any)
34
-
35
- // If it's neither, return it as-is
36
- return component
37
- }
38
-
39
- export function isSameDay (
40
- currentMessage: IMessage,
41
- diffMessage: IMessage | null | undefined
42
- ) {
43
- if (!diffMessage || !diffMessage.createdAt)
44
- return false
45
-
46
- const currentCreatedAt = dayjs(currentMessage.createdAt)
47
- const diffCreatedAt = dayjs(diffMessage.createdAt)
48
-
49
- if (!currentCreatedAt.isValid() || !diffCreatedAt.isValid())
50
- return false
51
-
52
- return currentCreatedAt.isSame(diffCreatedAt, 'day')
53
- }
54
-
55
- export function isSameUser (
56
- currentMessage: IMessage,
57
- diffMessage: IMessage | null | undefined
58
- ) {
59
- return !!(
60
- diffMessage &&
61
- diffMessage.user &&
62
- currentMessage.user &&
63
- diffMessage.user._id === currentMessage.user._id
64
- )
65
- }
66
-
67
- function processCallbackArguments (args: unknown[]): unknown[] {
68
- const [e, ...rest] = args
69
- const { nativeEvent } = (e as { nativeEvent?: unknown }) || {}
70
- let params: unknown[] = []
71
- if (e) {
72
- if (nativeEvent)
73
- params.push({ nativeEvent })
74
- else
75
- params.push(e)
76
- if (rest)
77
- params = params.concat(rest)
78
- }
79
-
80
- return params
81
- }
82
-
83
- export function useCallbackDebounced<T extends (...args: any[]) => any>(callbackFunc: T, deps: React.DependencyList = [], time: number): (...args: Parameters<T>) => void {
84
- const timeoutId = useRef<ReturnType<typeof setTimeout>>(undefined)
85
-
86
- const savedFunc = useCallback((...args: Parameters<T>) => {
87
- const params = processCallbackArguments(args)
88
- if (timeoutId.current)
89
- clearTimeout(timeoutId.current)
90
- timeoutId.current = setTimeout(() => {
91
- callbackFunc(...params as Parameters<T>)
92
- }, time)
93
- // eslint-disable-next-line react-hooks/exhaustive-deps
94
- }, [callbackFunc, time, ...deps])
95
-
96
- useEffect(() => {
97
- return () => {
98
- if (timeoutId.current)
99
- clearTimeout(timeoutId.current)
100
- }
101
- }, [])
102
-
103
- return savedFunc
104
- }
105
-
106
- export function useCallbackThrottled<T extends (...args: any[]) => any>(callbackFunc: T, deps: React.DependencyList = [], time: number): (...args: Parameters<T>) => void {
107
- const lastExecution = useRef<number>(0)
108
- const timeoutId = useRef<ReturnType<typeof setTimeout>>(undefined)
109
-
110
- // we use function instead of arrow to access arguments object
111
- const savedFunc = useCallback((...args: Parameters<T>) => {
112
- const params = processCallbackArguments(args)
113
-
114
- const now = Date.now()
115
- const timeSinceLastExecution = now - lastExecution.current
116
-
117
- if (timeSinceLastExecution >= time) {
118
- // Execute immediately if enough time has passed
119
- lastExecution.current = now
120
- callbackFunc(...params as Parameters<T>)
121
- } else {
122
- // Schedule execution for the remaining time
123
- clearTimeout(timeoutId.current)
124
- timeoutId.current = setTimeout(() => {
125
- lastExecution.current = Date.now()
126
- callbackFunc(...params as Parameters<T>)
127
- }, time - timeSinceLastExecution)
128
- }
129
- // eslint-disable-next-line react-hooks/exhaustive-deps
130
- }, [callbackFunc, time, ...deps])
131
-
132
- useEffect(() => {
133
- return () => {
134
- clearTimeout(timeoutId.current)
135
- }
136
- }, [])
137
-
138
- return savedFunc
139
- }