react-native-gifted-chat 2.8.2-alpha.0 → 2.8.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +8 -12
  2. package/package.json +20 -21
  3. package/src/Bubble/index.tsx +11 -10
  4. package/src/Bubble/types.ts +2 -2
  5. package/src/Composer.tsx +19 -26
  6. package/src/Constant.ts +0 -1
  7. package/src/GiftedAvatar.tsx +29 -36
  8. package/src/GiftedChat/index.tsx +11 -62
  9. package/src/GiftedChat/types.ts +5 -52
  10. package/src/InputToolbar.tsx +25 -8
  11. package/src/LoadEarlier.tsx +19 -17
  12. package/src/MessageAudio.tsx +19 -7
  13. package/src/MessageContainer/components/DayAnimated/index.tsx +14 -9
  14. package/src/MessageContainer/components/Item/index.tsx +7 -1
  15. package/src/MessageContainer/index.tsx +47 -28
  16. package/src/MessageContainer/types.ts +31 -6
  17. package/src/MessageImage.tsx +18 -6
  18. package/src/MessageText.tsx +18 -23
  19. package/src/MessageVideo.tsx +19 -7
  20. package/src/QuickReplies.tsx +17 -10
  21. package/src/Send.tsx +7 -1
  22. package/src/SystemMessage.tsx +9 -2
  23. package/src/Time.tsx +9 -2
  24. package/src/TypingIndicator/index.tsx +2 -1
  25. package/src/TypingIndicator/types.ts +3 -0
  26. package/src/__tests__/Actions.test.tsx +3 -4
  27. package/src/__tests__/Avatar.test.tsx +5 -6
  28. package/src/__tests__/Bubble.test.tsx +14 -19
  29. package/src/__tests__/Composer.test.tsx +3 -4
  30. package/src/__tests__/Day.test.tsx +5 -8
  31. package/src/__tests__/DayAnimated.test.tsx +11 -13
  32. package/src/__tests__/GiftedAvatar.test.tsx +3 -8
  33. package/src/__tests__/GiftedChat.test.tsx +32 -41
  34. package/src/__tests__/InputToolbar.test.tsx +3 -4
  35. package/src/__tests__/LoadEarlier.test.tsx +3 -4
  36. package/src/__tests__/Message.test.tsx +51 -58
  37. package/src/__tests__/MessageContainer.test.tsx +39 -5
  38. package/src/__tests__/MessageImage.test.tsx +12 -15
  39. package/src/__tests__/MessageText.test.tsx +7 -4
  40. package/src/__tests__/Send.test.tsx +7 -8
  41. package/src/__tests__/SystemMessage.test.tsx +12 -15
  42. package/src/__tests__/Time.test.tsx +5 -8
  43. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +48 -50
  44. package/src/__tests__/__snapshots__/Composer.test.tsx.snap +1 -2
  45. package/src/__tests__/__snapshots__/Constant.test.tsx.snap +0 -1
  46. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +2 -2
  47. package/src/__tests__/__snapshots__/Message.test.tsx.snap +146 -150
  48. package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +12 -10
  49. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +12 -8
  50. package/src/__tests__/__snapshots__/Send.test.tsx.snap +2 -0
  51. package/src/reanimatedCompat.ts +27 -0
  52. package/src/types.ts +4 -0
  53. package/lib/Actions.d.ts +0 -14
  54. package/lib/Actions.js +0 -57
  55. package/lib/Actions.js.map +0 -1
  56. package/lib/Avatar.d.ts +0 -18
  57. package/lib/Avatar.js +0 -93
  58. package/lib/Avatar.js.map +0 -1
  59. package/lib/Bubble/index.d.ts +0 -6
  60. package/lib/Bubble/index.js +0 -242
  61. package/lib/Bubble/index.js.map +0 -1
  62. package/lib/Bubble/styles.d.ts +0 -69
  63. package/lib/Bubble/styles.js +0 -72
  64. package/lib/Bubble/styles.js.map +0 -1
  65. package/lib/Bubble/types.d.ts +0 -47
  66. package/lib/Bubble/types.js +0 -2
  67. package/lib/Bubble/types.js.map +0 -1
  68. package/lib/Color.d.ts +0 -18
  69. package/lib/Color.js +0 -18
  70. package/lib/Color.js.map +0 -1
  71. package/lib/Composer.d.ts +0 -20
  72. package/lib/Composer.js +0 -60
  73. package/lib/Composer.js.map +0 -1
  74. package/lib/Constant.d.ts +0 -10
  75. package/lib/Constant.js +0 -17
  76. package/lib/Constant.js.map +0 -1
  77. package/lib/Day/index.d.ts +0 -4
  78. package/lib/Day/index.js +0 -39
  79. package/lib/Day/index.js.map +0 -1
  80. package/lib/Day/styles.d.ts +0 -20
  81. package/lib/Day/styles.js +0 -22
  82. package/lib/Day/styles.js.map +0 -1
  83. package/lib/Day/types.d.ts +0 -9
  84. package/lib/Day/types.js +0 -2
  85. package/lib/Day/types.js.map +0 -1
  86. package/lib/GiftedAvatar.d.ts +0 -11
  87. package/lib/GiftedAvatar.js +0 -104
  88. package/lib/GiftedAvatar.js.map +0 -1
  89. package/lib/GiftedChat/index.d.ts +0 -26
  90. package/lib/GiftedChat/index.js +0 -317
  91. package/lib/GiftedChat/index.js.map +0 -1
  92. package/lib/GiftedChat/styles.d.ts +0 -6
  93. package/lib/GiftedChat/styles.js +0 -7
  94. package/lib/GiftedChat/styles.js.map +0 -1
  95. package/lib/GiftedChat/types.d.ts +0 -112
  96. package/lib/GiftedChat/types.js +0 -2
  97. package/lib/GiftedChat/types.js.map +0 -1
  98. package/lib/GiftedChatContext.d.ts +0 -9
  99. package/lib/GiftedChatContext.js +0 -9
  100. package/lib/GiftedChatContext.js.map +0 -1
  101. package/lib/InputToolbar.d.ts +0 -23
  102. package/lib/InputToolbar.js +0 -56
  103. package/lib/InputToolbar.js.map +0 -1
  104. package/lib/LoadEarlier.d.ts +0 -14
  105. package/lib/LoadEarlier.js +0 -45
  106. package/lib/LoadEarlier.js.map +0 -1
  107. package/lib/Message/index.d.ts +0 -6
  108. package/lib/Message/index.js +0 -80
  109. package/lib/Message/index.js.map +0 -1
  110. package/lib/Message/styles.d.ts +0 -21
  111. package/lib/Message/styles.js +0 -22
  112. package/lib/Message/styles.js.map +0 -1
  113. package/lib/Message/types.d.ts +0 -22
  114. package/lib/Message/types.js +0 -2
  115. package/lib/Message/types.js.map +0 -1
  116. package/lib/MessageAudio.d.ts +0 -2
  117. package/lib/MessageAudio.js +0 -14
  118. package/lib/MessageAudio.js.map +0 -1
  119. package/lib/MessageContainer/components/DayAnimated/index.d.ts +0 -5
  120. package/lib/MessageContainer/components/DayAnimated/index.js +0 -85
  121. package/lib/MessageContainer/components/DayAnimated/index.js.map +0 -1
  122. package/lib/MessageContainer/components/DayAnimated/styles.d.ts +0 -11
  123. package/lib/MessageContainer/components/DayAnimated/styles.js +0 -12
  124. package/lib/MessageContainer/components/DayAnimated/styles.js.map +0 -1
  125. package/lib/MessageContainer/components/DayAnimated/types.d.ts +0 -17
  126. package/lib/MessageContainer/components/DayAnimated/types.js +0 -2
  127. package/lib/MessageContainer/components/DayAnimated/types.js.map +0 -1
  128. package/lib/MessageContainer/components/Item/index.d.ts +0 -23
  129. package/lib/MessageContainer/components/Item/index.js +0 -88
  130. package/lib/MessageContainer/components/Item/index.js.map +0 -1
  131. package/lib/MessageContainer/components/Item/types.d.ts +0 -17
  132. package/lib/MessageContainer/components/Item/types.js +0 -2
  133. package/lib/MessageContainer/components/Item/types.js.map +0 -1
  134. package/lib/MessageContainer/index.d.ts +0 -6
  135. package/lib/MessageContainer/index.js +0 -235
  136. package/lib/MessageContainer/index.js.map +0 -1
  137. package/lib/MessageContainer/styles.d.ts +0 -35
  138. package/lib/MessageContainer/styles.js +0 -32
  139. package/lib/MessageContainer/styles.js.map +0 -1
  140. package/lib/MessageContainer/types.d.ts +0 -51
  141. package/lib/MessageContainer/types.js +0 -2
  142. package/lib/MessageContainer/types.js.map +0 -1
  143. package/lib/MessageImage.d.ts +0 -13
  144. package/lib/MessageImage.js +0 -30
  145. package/lib/MessageImage.js.map +0 -1
  146. package/lib/MessageText.d.ts +0 -19
  147. package/lib/MessageText.js +0 -69
  148. package/lib/MessageText.js.map +0 -1
  149. package/lib/MessageVideo.d.ts +0 -2
  150. package/lib/MessageVideo.js +0 -14
  151. package/lib/MessageVideo.js.map +0 -1
  152. package/lib/QuickReplies.d.ts +0 -15
  153. package/lib/QuickReplies.js +0 -101
  154. package/lib/QuickReplies.js.map +0 -1
  155. package/lib/Send.d.ts +0 -15
  156. package/lib/Send.js +0 -34
  157. package/lib/Send.js.map +0 -1
  158. package/lib/SystemMessage.d.ts +0 -11
  159. package/lib/SystemMessage.js +0 -27
  160. package/lib/SystemMessage.js.map +0 -1
  161. package/lib/Time.d.ts +0 -11
  162. package/lib/Time.js +0 -56
  163. package/lib/Time.js.map +0 -1
  164. package/lib/TypingIndicator/index.d.ts +0 -5
  165. package/lib/TypingIndicator/index.js +0 -94
  166. package/lib/TypingIndicator/index.js.map +0 -1
  167. package/lib/TypingIndicator/styles.d.ts +0 -20
  168. package/lib/TypingIndicator/styles.js +0 -22
  169. package/lib/TypingIndicator/styles.js.map +0 -1
  170. package/lib/TypingIndicator/types.d.ts +0 -3
  171. package/lib/TypingIndicator/types.js +0 -2
  172. package/lib/TypingIndicator/types.js.map +0 -1
  173. package/lib/hooks/useUpdateLayoutEffect.d.ts +0 -8
  174. package/lib/hooks/useUpdateLayoutEffect.js +0 -17
  175. package/lib/hooks/useUpdateLayoutEffect.js.map +0 -1
  176. package/lib/index.d.ts +0 -4
  177. package/lib/index.js +0 -5
  178. package/lib/index.js.map +0 -1
  179. package/lib/logging.d.ts +0 -2
  180. package/lib/logging.js +0 -5
  181. package/lib/logging.js.map +0 -1
  182. package/lib/styles.d.ts +0 -10
  183. package/lib/styles.js +0 -11
  184. package/lib/styles.js.map +0 -1
  185. package/lib/types.d.ts +0 -67
  186. package/lib/types.js +0 -2
  187. package/lib/types.js.map +0 -1
  188. package/lib/utils.d.ts +0 -5
  189. package/lib/utils.js +0 -83
  190. package/lib/utils.js.map +0 -1
  191. package/src/__tests__/__snapshots__/MessageContainer.test.tsx.snap +0 -108
@@ -5,6 +5,7 @@ import {
5
5
  StyleProp,
6
6
  ViewStyle,
7
7
  TextStyle,
8
+ View,
8
9
  } from 'react-native'
9
10
 
10
11
  import Autolink, { AutolinkProps } from 'react-native-autolink'
@@ -41,15 +42,6 @@ export const MessageText: React.FC<MessageTextProps<IMessage>> = ({
41
42
  onPress: onPressProp,
42
43
  ...rest
43
44
  }) => {
44
- // TODO: React.memo
45
- // const shouldComponentUpdate = (nextProps: MessageTextProps<TMessage>) => {
46
- // return (
47
- // !!currentMessage &&
48
- // !!nextProps.currentMessage &&
49
- // currentMessage.text !== nextProps.currentMessage.text
50
- // )
51
- // }
52
-
53
45
  const onUrlPress = useCallback((url: string) => {
54
46
  if (/^www\./i.test(url))
55
47
  url = `https://${url}`
@@ -89,34 +81,37 @@ export const MessageText: React.FC<MessageTextProps<IMessage>> = ({
89
81
  }, [onUrlPress, onPhonePress, onEmailPress, onPressProp, currentMessage])
90
82
 
91
83
  const style = useMemo(() => [
92
- containerStyle?.[position],
93
84
  styles[`text_${position}`],
94
85
  textStyle?.[position],
95
86
  customTextStyle,
96
- ], [containerStyle, position, textStyle, customTextStyle])
87
+ ], [position, textStyle, customTextStyle])
97
88
 
98
89
  return (
99
- <Autolink
100
- style={style}
101
- {...rest}
102
- text={currentMessage!.text}
103
- email
104
- link
105
- linkStyle={linkStyle}
106
- onPress={handlePress}
107
- />
90
+ <View style={[styles.container, containerStyle?.[position]]}>
91
+ <Autolink
92
+ style={style}
93
+ {...rest}
94
+ text={currentMessage!.text}
95
+ email
96
+ link
97
+ linkStyle={linkStyle}
98
+ onPress={handlePress}
99
+ />
100
+ </View>
108
101
  )
109
102
  }
110
103
 
111
104
  const styles = StyleSheet.create({
112
- text: {
113
- fontSize: 16,
114
- lineHeight: 20,
105
+ container: {
115
106
  marginTop: 5,
116
107
  marginBottom: 5,
117
108
  marginLeft: 10,
118
109
  marginRight: 10,
119
110
  },
111
+ text: {
112
+ fontSize: 16,
113
+ lineHeight: 20,
114
+ },
120
115
  text_left: {
121
116
  color: 'black',
122
117
  },
@@ -1,16 +1,28 @@
1
- import React from 'react'
1
+ import React, { useMemo } from 'react'
2
2
  import Color from './Color'
3
- import { View, Text } from 'react-native'
3
+ import { View, Text, StyleSheet } from 'react-native'
4
+
5
+ const styles = StyleSheet.create({
6
+ container: {
7
+ padding: 20,
8
+ },
9
+ text: {
10
+ color: Color.alizarin,
11
+ fontWeight: '600',
12
+ },
13
+ })
4
14
 
5
15
  export function MessageVideo () {
6
- return (
7
- <View style={{ padding: 20 }}>
8
- <Text style={{ color: Color.alizarin, fontWeight: '600' }}>
16
+ const content = useMemo(() => (
17
+ <View style={styles.container}>
18
+ <Text style={styles.text}>
9
19
  {'Video is not implemented by GiftedChat.'}
10
20
  </Text>
11
- <Text style={{ color: Color.alizarin, fontWeight: '600' }}>
21
+ <Text style={styles.text}>
12
22
  {'\nYou need to provide your own implementation by using renderMessageVideo prop.'}
13
23
  </Text>
14
24
  </View>
15
- )
25
+ ), [])
26
+
27
+ return content
16
28
  }
@@ -122,6 +122,22 @@ export function QuickReplies ({
122
122
  [replies, currentMessage, handleSend]
123
123
  )
124
124
 
125
+ const renderSendButton = useMemo(() => {
126
+ if (!replies.length)
127
+ return null
128
+
129
+ return (
130
+ <TouchableOpacity
131
+ style={[stylesCommon.centerItems, styles.quickReply, styles.sendLink]}
132
+ onPress={handleSend(replies)}
133
+ >
134
+ {renderQuickReplySend?.() || (
135
+ <Text style={styles.sendLinkText}>{sendText}</Text>
136
+ )}
137
+ </TouchableOpacity>
138
+ )
139
+ }, [replies, handleSend, renderQuickReplySend, sendText])
140
+
125
141
  if (!shouldComponentDisplay)
126
142
  return null
127
143
 
@@ -159,16 +175,7 @@ export function QuickReplies ({
159
175
  )
160
176
  }
161
177
  )}
162
- {replies.length > 0 && (
163
- <TouchableOpacity
164
- style={[stylesCommon.centerItems, styles.quickReply, styles.sendLink]}
165
- onPress={handleSend(replies)}
166
- >
167
- {renderQuickReplySend?.() || (
168
- <Text style={styles.sendLinkText}>{sendText}</Text>
169
- )}
170
- </TouchableOpacity>
171
- )}
178
+ {renderSendButton}
172
179
  </View>
173
180
  )
174
181
  }
package/src/Send.tsx CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  ViewStyle,
9
9
  TextStyle,
10
10
  TouchableOpacityProps,
11
+ useColorScheme,
11
12
  } from 'react-native'
12
13
 
13
14
  import Color from './Color'
@@ -28,6 +29,9 @@ const styles = StyleSheet.create({
28
29
  marginLeft: 10,
29
30
  marginRight: 10,
30
31
  },
32
+ text_dark: {
33
+ color: '#4da6ff',
34
+ },
31
35
  })
32
36
 
33
37
  export interface SendProps<TMessage extends IMessage> {
@@ -56,6 +60,8 @@ export const Send = <TMessage extends IMessage = IMessage>({
56
60
  sendButtonProps,
57
61
  onSend,
58
62
  }: SendProps<TMessage>) => {
63
+ const colorScheme = useColorScheme()
64
+
59
65
  const handleOnPress = useCallback(() => {
60
66
  if (text && onSend)
61
67
  onSend({ text: text.trim() } as Partial<TMessage>, true)
@@ -81,7 +87,7 @@ export const Send = <TMessage extends IMessage = IMessage>({
81
87
  {...sendButtonProps}
82
88
  >
83
89
  <View>
84
- {children || <Text style={[styles.text, textStyle]}>{label}</Text>}
90
+ {children || <Text style={[styles.text, styles[`text_${colorScheme}`], textStyle]}>{label}</Text>}
85
91
  </View>
86
92
  </TouchableOpacity>
87
93
  )
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { useMemo } from 'react'
2
2
  import {
3
3
  StyleSheet,
4
4
  Text,
@@ -39,13 +39,20 @@ export function SystemMessage<TMessage extends IMessage = IMessage> ({
39
39
  textStyle,
40
40
  children,
41
41
  }: SystemMessageProps<TMessage>) {
42
+ const textContent = useMemo(() => {
43
+ if (!currentMessage?.text)
44
+ return null
45
+
46
+ return <Text style={[styles.text, textStyle]}>{currentMessage.text}</Text>
47
+ }, [currentMessage?.text, textStyle])
48
+
42
49
  if (currentMessage == null || currentMessage.system === false)
43
50
  return null
44
51
 
45
52
  return (
46
53
  <View style={[stylesCommon.fill, stylesCommon.centerItems, styles.container, containerStyle]}>
47
54
  <View style={wrapperStyle}>
48
- {!!currentMessage.text && <Text style={[styles.text, textStyle]}>{currentMessage.text}</Text>}
55
+ {textContent}
49
56
  {children}
50
57
  </View>
51
58
  </View>
package/src/Time.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React from 'react'
1
+ import React, { useMemo } from 'react'
2
2
  import { StyleSheet, Text, View, ViewStyle, TextStyle } from 'react-native'
3
3
  import dayjs from 'dayjs'
4
4
 
@@ -60,6 +60,13 @@ export function Time<TMessage extends IMessage = IMessage> ({
60
60
  }: TimeProps<TMessage>) {
61
61
  const { getLocale } = useChatContext()
62
62
 
63
+ const formattedTime = useMemo(() => {
64
+ if (currentMessage == null)
65
+ return null
66
+
67
+ return dayjs(currentMessage.createdAt).locale(getLocale()).format(timeFormat)
68
+ }, [currentMessage, getLocale, timeFormat])
69
+
63
70
  if (currentMessage == null)
64
71
  return null
65
72
 
@@ -76,7 +83,7 @@ export function Time<TMessage extends IMessage = IMessage> ({
76
83
  timeTextStyle?.[position],
77
84
  ]}
78
85
  >
79
- {dayjs(currentMessage.createdAt).locale(getLocale()).format(timeFormat)}
86
+ {formattedTime}
80
87
  </Text>
81
88
  </View>
82
89
  )
@@ -89,7 +89,7 @@ const DotsAnimation = () => {
89
89
  )
90
90
  }
91
91
 
92
- const TypingIndicator = ({ isTyping }: TypingIndicatorProps) => {
92
+ const TypingIndicator = ({ isTyping, style }: TypingIndicatorProps) => {
93
93
  const yCoords = useSharedValue(200)
94
94
  const heightScale = useSharedValue(0)
95
95
  const marginScale = useSharedValue(0)
@@ -146,6 +146,7 @@ const TypingIndicator = ({ isTyping }: TypingIndicatorProps) => {
146
146
  style={[
147
147
  styles.container,
148
148
  containerStyle,
149
+ style,
149
150
  ]}
150
151
  >
151
152
  <DotsAnimation />
@@ -1,3 +1,6 @@
1
+ import { StyleProp, ViewStyle } from 'react-native'
2
+
1
3
  export interface TypingIndicatorProps {
2
4
  isTyping?: boolean
5
+ style?: StyleProp<ViewStyle>
3
6
  }
@@ -1,10 +1,9 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { Actions } from '../GiftedChat'
6
5
 
7
6
  it('should render <Actions /> and compare with snapshot', () => {
8
- const tree = renderer.create(<Actions />).toJSON()
9
- expect(tree).toMatchSnapshot()
7
+ const { toJSON } = render(<Actions />)
8
+ expect(toJSON()).toMatchSnapshot()
10
9
  })
@@ -1,13 +1,12 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { Avatar } from '../GiftedChat'
6
5
 
7
6
  it('should render <Avatar /> and compare with snapshot', () => {
8
- const tree = renderer
9
- .create(<Avatar renderAvatar={() => 'renderAvatar'} position='left' />)
10
- .toJSON()
7
+ const { toJSON } = render(
8
+ <Avatar renderAvatar={() => 'renderAvatar'} position='left' />
9
+ )
11
10
 
12
- expect(tree).toMatchSnapshot()
11
+ expect(toJSON()).toMatchSnapshot()
13
12
  })
@@ -1,26 +1,21 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { Bubble } from '../GiftedChat'
6
5
 
7
6
  it('should render <Bubble /> and compare with snapshot', () => {
8
- let tree
7
+ const { toJSON } = render(
8
+ <Bubble
9
+ user={{ _id: 1 }}
10
+ currentMessage={{
11
+ _id: 1,
12
+ text: 'test',
13
+ createdAt: 1554744013721,
14
+ user: { _id: 1 },
15
+ }}
16
+ position='left'
17
+ />
18
+ )
9
19
 
10
- renderer.act(() => {
11
- tree = renderer.create(
12
- <Bubble
13
- user={{ _id: 1 }}
14
- currentMessage={{
15
- _id: 1,
16
- text: 'test',
17
- createdAt: 1554744013721,
18
- user: { _id: 1 },
19
- }}
20
- position='left'
21
- />
22
- )
23
- })
24
-
25
- expect(tree.toJSON()).toMatchSnapshot()
20
+ expect(toJSON()).toMatchSnapshot()
26
21
  })
@@ -1,11 +1,10 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { Composer } from '../GiftedChat'
6
5
 
7
6
  it('should render <Composer /> and compare with snapshot', () => {
8
- const tree = renderer.create(<Composer />).toJSON()
7
+ const { toJSON } = render(<Composer />)
9
8
 
10
- expect(tree).toMatchSnapshot()
9
+ expect(toJSON()).toMatchSnapshot()
11
10
  })
@@ -1,23 +1,20 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { Day } from '../GiftedChat'
6
5
  import { DEFAULT_TEST_MESSAGE } from './data'
7
6
 
8
7
  describe('Day', () => {
9
8
  it('should not render <Day /> and compare with snapshot', () => {
10
- const component = renderer.create(<Day />)
11
- const tree = component.toJSON()
9
+ const { toJSON } = render(<Day />)
12
10
 
13
- expect(tree).toMatchSnapshot()
11
+ expect(toJSON()).toMatchSnapshot()
14
12
  })
15
13
 
16
14
  it('should render <Day /> and compare with snapshot', () => {
17
- const component = renderer.create(
15
+ const { toJSON } = render(
18
16
  <Day currentMessage={DEFAULT_TEST_MESSAGE} />
19
17
  )
20
- const tree = component.toJSON()
21
- expect(tree).toMatchSnapshot()
18
+ expect(toJSON()).toMatchSnapshot()
22
19
  })
23
20
  })
@@ -1,6 +1,6 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
3
+ import { View, Text } from 'react-native'
4
4
  import DayAnimated from '../MessageContainer/components/DayAnimated'
5
5
  import { DayProps } from '../Day'
6
6
 
@@ -17,7 +17,7 @@ const mockMessage = {
17
17
 
18
18
  describe('DayAnimated', () => {
19
19
  it('should render DayAnimated with default Day component', () => {
20
- const component = renderer.create(
20
+ const { toJSON } = render(
21
21
  <DayAnimated
22
22
  scrolledY={mockScrolledY}
23
23
  daysPositions={mockDaysPositions}
@@ -26,14 +26,17 @@ describe('DayAnimated', () => {
26
26
  isLoadingEarlier={false}
27
27
  />
28
28
  )
29
- const tree = component.toJSON()
30
- expect(tree).toMatchSnapshot()
29
+ expect(toJSON()).toMatchSnapshot()
31
30
  })
32
31
 
33
32
  it('should use custom renderDay when provided', () => {
34
- const customRenderDay = jest.fn((props: DayProps) => <div data-testid='custom-day'>Custom Day: {props.createdAt}</div>)
33
+ const customRenderDay = jest.fn((props: DayProps) => (
34
+ <View testID='custom-day'>
35
+ <Text>Custom Day: {props.createdAt}</Text>
36
+ </View>
37
+ ))
35
38
 
36
- const component = renderer.create(
39
+ const { toJSON } = render(
37
40
  <DayAnimated
38
41
  scrolledY={mockScrolledY}
39
42
  daysPositions={mockDaysPositions}
@@ -44,11 +47,6 @@ describe('DayAnimated', () => {
44
47
  />
45
48
  )
46
49
 
47
- // Force render to trigger the renderDay call if there's a createdAt
48
- component.getInstance()
49
-
50
- // The custom renderDay function should be available in the component
51
- const tree = component.toJSON()
52
- expect(tree).toMatchSnapshot()
50
+ expect(toJSON()).toMatchSnapshot()
53
51
  })
54
52
  })
@@ -1,15 +1,10 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { GiftedAvatar } from '../GiftedChat'
6
5
 
7
6
  it('should render <GiftedAvatar /> and compare with snapshot', () => {
8
- let tree
7
+ const { toJSON } = render(<GiftedAvatar />)
9
8
 
10
- renderer.act(() => {
11
- tree = renderer.create(<GiftedAvatar />)
12
- })
13
-
14
- expect(tree.toJSON()).toMatchSnapshot()
9
+ expect(toJSON()).toMatchSnapshot()
15
10
  })
@@ -1,6 +1,5 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { GiftedChat } from '../GiftedChat'
6
5
  import { useReanimatedKeyboardAnimation } from 'react-native-keyboard-controller'
@@ -18,50 +17,42 @@ const messages = [
18
17
  ]
19
18
 
20
19
  it('should render <GiftedChat/> and compare with snapshot', () => {
21
- let tree
22
-
23
- renderer.act(() => {
24
- (useReanimatedKeyboardAnimation as jest.Mock).mockReturnValue({
25
- height: {
26
- value: 0,
27
- },
28
- })
29
-
30
- tree = renderer.create(
31
- <GiftedChat
32
- messages={messages}
33
- onSend={() => {}}
34
- user={{
35
- _id: 1,
36
- }}
37
- />
38
- )
20
+ (useReanimatedKeyboardAnimation as jest.Mock).mockReturnValue({
21
+ height: {
22
+ value: 0,
23
+ },
39
24
  })
40
25
 
41
- expect(tree.toJSON()).toMatchSnapshot()
26
+ const { toJSON } = render(
27
+ <GiftedChat
28
+ messages={messages}
29
+ onSend={() => {}}
30
+ user={{
31
+ _id: 1,
32
+ }}
33
+ />
34
+ )
35
+
36
+ expect(toJSON()).toMatchSnapshot()
42
37
  })
43
38
 
44
39
  it('should render <GiftedChat/> with disableKeyboardController=true', () => {
45
- let tree
46
-
47
- renderer.act(() => {
48
- (useReanimatedKeyboardAnimation as jest.Mock).mockReturnValue({
49
- height: {
50
- value: 0,
51
- },
52
- })
53
-
54
- tree = renderer.create(
55
- <GiftedChat
56
- messages={messages}
57
- onSend={() => {}}
58
- user={{
59
- _id: 1,
60
- }}
61
- disableKeyboardController={true}
62
- />
63
- )
40
+ (useReanimatedKeyboardAnimation as jest.Mock).mockReturnValue({
41
+ height: {
42
+ value: 0,
43
+ },
64
44
  })
65
45
 
66
- expect(tree.toJSON()).toMatchSnapshot()
46
+ const { toJSON } = render(
47
+ <GiftedChat
48
+ messages={messages}
49
+ onSend={() => {}}
50
+ user={{
51
+ _id: 1,
52
+ }}
53
+ disableKeyboardController={true}
54
+ />
55
+ )
56
+
57
+ expect(toJSON()).toMatchSnapshot()
67
58
  })
@@ -1,11 +1,10 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { InputToolbar } from '../GiftedChat'
6
5
 
7
6
  it('should render <InputToolbar /> and compare with snapshot', () => {
8
- const tree = renderer.create(<InputToolbar />).toJSON()
7
+ const { toJSON } = render(<InputToolbar />)
9
8
 
10
- expect(tree).toMatchSnapshot()
9
+ expect(toJSON()).toMatchSnapshot()
11
10
  })
@@ -1,11 +1,10 @@
1
- import 'react-native'
2
1
  import React from 'react'
3
- import renderer from 'react-test-renderer'
2
+ import { render } from '@testing-library/react-native'
4
3
 
5
4
  import { LoadEarlier } from '../GiftedChat'
6
5
 
7
6
  it('should render <LoadEarlier /> and compare with snapshot', () => {
8
- const tree = renderer.create(<LoadEarlier />).toJSON()
7
+ const { toJSON } = render(<LoadEarlier />)
9
8
 
10
- expect(tree).toMatchSnapshot()
9
+ expect(toJSON()).toMatchSnapshot()
11
10
  })