react-native-gifted-chat 2.8.2-alpha.6 → 3.0.0-alpha.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 (66) hide show
  1. package/README.md +190 -269
  2. package/package.json +2 -1
  3. package/src/Actions.tsx +1 -1
  4. package/src/Avatar.tsx +12 -12
  5. package/src/Bubble/index.tsx +14 -16
  6. package/src/Bubble/styles.ts +1 -1
  7. package/src/Bubble/types.ts +26 -27
  8. package/src/Color.ts +1 -1
  9. package/src/Composer.tsx +1 -4
  10. package/src/Day/styles.ts +1 -1
  11. package/src/GiftedAvatar.tsx +2 -2
  12. package/src/GiftedChat/index.tsx +26 -61
  13. package/src/GiftedChat/types.ts +40 -49
  14. package/src/InputToolbar.tsx +28 -19
  15. package/src/LoadEarlierMessages.tsx +1 -1
  16. package/src/Message/index.tsx +11 -14
  17. package/src/Message/types.ts +8 -12
  18. package/src/MessageAudio.tsx +1 -1
  19. package/src/MessageContainer/components/DayAnimated/index.tsx +1 -3
  20. package/src/MessageContainer/components/DayAnimated/types.ts +1 -1
  21. package/src/MessageContainer/components/Item/index.tsx +9 -11
  22. package/src/MessageContainer/components/Item/types.ts +1 -1
  23. package/src/MessageContainer/index.tsx +32 -36
  24. package/src/MessageContainer/styles.ts +1 -1
  25. package/src/MessageContainer/types.ts +12 -16
  26. package/src/MessageImage.tsx +1 -1
  27. package/src/MessageText.tsx +1 -1
  28. package/src/MessageVideo.tsx +1 -1
  29. package/src/Models.ts +63 -0
  30. package/src/QuickReplies.tsx +2 -2
  31. package/src/Send.tsx +31 -32
  32. package/src/SystemMessage.tsx +2 -2
  33. package/src/Time.tsx +6 -6
  34. package/src/TypingIndicator/index.tsx +1 -3
  35. package/src/TypingIndicator/styles.ts +1 -1
  36. package/src/__tests__/Actions.test.tsx +1 -1
  37. package/src/__tests__/Avatar.test.tsx +7 -2
  38. package/src/__tests__/Bubble.test.tsx +3 -7
  39. package/src/__tests__/Color.test.tsx +1 -1
  40. package/src/__tests__/Composer.test.tsx +1 -1
  41. package/src/__tests__/Day.test.tsx +3 -3
  42. package/src/__tests__/DayAnimated.test.tsx +5 -11
  43. package/src/__tests__/GiftedAvatar.test.tsx +1 -1
  44. package/src/__tests__/GiftedChat.test.tsx +1 -1
  45. package/src/__tests__/InputToolbar.test.tsx +1 -1
  46. package/src/__tests__/LoadEarlier.test.tsx +2 -2
  47. package/src/__tests__/Message.test.tsx +7 -13
  48. package/src/__tests__/MessageContainer.test.tsx +4 -4
  49. package/src/__tests__/MessageImage.test.tsx +2 -2
  50. package/src/__tests__/MessageText.test.tsx +3 -2
  51. package/src/__tests__/Send.test.tsx +2 -2
  52. package/src/__tests__/SystemMessage.test.tsx +1 -1
  53. package/src/__tests__/Time.test.tsx +1 -1
  54. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +2 -86
  55. package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +1 -1
  56. package/src/__tests__/__snapshots__/Day.test.tsx.snap +96 -2
  57. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +1 -1
  58. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +3 -89
  59. package/src/__tests__/__snapshots__/Message.test.tsx.snap +43 -4
  60. package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +1 -1
  61. package/src/__tests__/__snapshots__/Send.test.tsx.snap +10 -142
  62. package/src/__tests__/data.ts +2 -2
  63. package/src/components/TouchableOpacity.tsx +19 -8
  64. package/src/index.ts +19 -1
  65. package/src/types.ts +1 -63
  66. package/src/utils.ts +23 -2
@@ -6,7 +6,7 @@ exports[`should render <Actions /> and compare with snapshot 1`] = `
6
6
  {
7
7
  "busy": undefined,
8
8
  "checked": undefined,
9
- "disabled": undefined,
9
+ "disabled": false,
10
10
  "expanded": undefined,
11
11
  "selected": undefined,
12
12
  }
@@ -20,97 +20,13 @@ exports[`should render <Actions /> and compare with snapshot 1`] = `
20
20
  }
21
21
  }
22
22
  accessible={true}
23
- collapsable={false}
24
23
  focusable={true}
25
- onBlur={[Function]}
26
24
  onClick={[Function]}
27
- onFocus={[Function]}
28
25
  onResponderGrant={[Function]}
29
26
  onResponderMove={[Function]}
30
27
  onResponderRelease={[Function]}
31
28
  onResponderTerminate={[Function]}
32
29
  onResponderTerminationRequest={[Function]}
33
30
  onStartShouldSetResponder={[Function]}
34
- >
35
- <View
36
- collapsable={false}
37
- jestAnimatedProps={
38
- {
39
- "value": {},
40
- }
41
- }
42
- jestAnimatedStyle={
43
- {
44
- "value": {
45
- "opacity": 1,
46
- },
47
- }
48
- }
49
- jestInlineStyle={
50
- [
51
- [
52
- {
53
- "height": 26,
54
- "marginBottom": 10,
55
- "marginLeft": 10,
56
- "width": 26,
57
- },
58
- undefined,
59
- ],
60
- ]
61
- }
62
- style={
63
- [
64
- {
65
- "height": 26,
66
- "marginBottom": 10,
67
- "marginLeft": 10,
68
- "width": 26,
69
- },
70
- undefined,
71
- {
72
- "opacity": 1,
73
- },
74
- ]
75
- }
76
- >
77
- <View
78
- style={
79
- [
80
- {
81
- "flex": 1,
82
- },
83
- {
84
- "alignItems": "center",
85
- "justifyContent": "center",
86
- },
87
- {
88
- "borderColor": "#b2b2b2",
89
- "borderRadius": 13,
90
- "borderWidth": 2,
91
- },
92
- undefined,
93
- ]
94
- }
95
- >
96
- <Text
97
- style={
98
- [
99
- {
100
- "backgroundColor": "transparent",
101
- "color": "#b2b2b2",
102
- "fontSize": 16,
103
- "fontWeight": "bold",
104
- "lineHeight": 16,
105
- "textAlign": "center",
106
- },
107
- undefined,
108
- ]
109
- }
110
- >
111
- +
112
- </Text>
113
- </View>
114
- </View>
115
- </View>
31
+ />
116
32
  `;
@@ -133,7 +133,7 @@ exports[`should render <Bubble /> and compare with snapshot 1`] = `
133
133
  ]
134
134
  }
135
135
  >
136
- 7:20 PM
136
+ 12:00 AM
137
137
  </Text>
138
138
  </View>
139
139
  </View>
@@ -1,5 +1,99 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`Day should not render <Day /> and compare with snapshot 1`] = `null`;
3
+ exports[`Day should not render <Day /> and compare with snapshot 1`] = `
4
+ <View
5
+ style={
6
+ [
7
+ {
8
+ "alignItems": "center",
9
+ "justifyContent": "center",
10
+ },
11
+ {
12
+ "marginBottom": 10,
13
+ "marginTop": 5,
14
+ },
15
+ undefined,
16
+ ]
17
+ }
18
+ >
19
+ <View
20
+ style={
21
+ [
22
+ {
23
+ "backgroundColor": "rgba(0, 0, 0, 0.75)",
24
+ "borderRadius": 15,
25
+ "paddingBottom": 6,
26
+ "paddingLeft": 10,
27
+ "paddingRight": 10,
28
+ "paddingTop": 6,
29
+ },
30
+ undefined,
31
+ ]
32
+ }
33
+ >
34
+ <Text
35
+ style={
36
+ [
37
+ {
38
+ "color": "#fff",
39
+ "fontSize": 12,
40
+ "fontWeight": "600",
41
+ },
42
+ undefined,
43
+ ]
44
+ }
45
+ >
46
+ 17 April 2022
47
+ </Text>
48
+ </View>
49
+ </View>
50
+ `;
4
51
 
5
- exports[`Day should render <Day /> and compare with snapshot 1`] = `null`;
52
+ exports[`Day should render <Day /> and compare with snapshot 1`] = `
53
+ <View
54
+ style={
55
+ [
56
+ {
57
+ "alignItems": "center",
58
+ "justifyContent": "center",
59
+ },
60
+ {
61
+ "marginBottom": 10,
62
+ "marginTop": 5,
63
+ },
64
+ undefined,
65
+ ]
66
+ }
67
+ >
68
+ <View
69
+ style={
70
+ [
71
+ {
72
+ "backgroundColor": "rgba(0, 0, 0, 0.75)",
73
+ "borderRadius": 15,
74
+ "paddingBottom": 6,
75
+ "paddingLeft": 10,
76
+ "paddingRight": 10,
77
+ "paddingTop": 6,
78
+ },
79
+ undefined,
80
+ ]
81
+ }
82
+ >
83
+ <Text
84
+ style={
85
+ [
86
+ {
87
+ "color": "#fff",
88
+ "fontSize": 12,
89
+ "fontWeight": "600",
90
+ },
91
+ undefined,
92
+ ]
93
+ }
94
+ >
95
+ 17 April 2022
96
+ </Text>
97
+ </View>
98
+ </View>
99
+ `;
@@ -9,7 +9,7 @@ exports[`should render <InputToolbar /> and compare with snapshot 1`] = `
9
9
  "borderTopColor": "#b2b2b2",
10
10
  "borderTopWidth": 0.5,
11
11
  },
12
- undefined,
12
+ false,
13
13
  undefined,
14
14
  ]
15
15
  }
@@ -2,11 +2,12 @@
2
2
 
3
3
  exports[`should render <LoadEarlierMessages /> and compare with snapshot 1`] = `
4
4
  <View
5
+ accessibilityRole="button"
5
6
  accessibilityState={
6
7
  {
7
8
  "busy": undefined,
8
9
  "checked": undefined,
9
- "disabled": undefined,
10
+ "disabled": false,
10
11
  "expanded": undefined,
11
12
  "selected": undefined,
12
13
  }
@@ -20,100 +21,13 @@ exports[`should render <LoadEarlierMessages /> and compare with snapshot 1`] = `
20
21
  }
21
22
  }
22
23
  accessible={true}
23
- collapsable={false}
24
24
  focusable={true}
25
- onBlur={[Function]}
26
25
  onClick={[Function]}
27
- onFocus={[Function]}
28
26
  onResponderGrant={[Function]}
29
27
  onResponderMove={[Function]}
30
28
  onResponderRelease={[Function]}
31
29
  onResponderTerminate={[Function]}
32
30
  onResponderTerminationRequest={[Function]}
33
31
  onStartShouldSetResponder={[Function]}
34
- >
35
- <View
36
- accessibilityRole="button"
37
- collapsable={false}
38
- disabled={false}
39
- jestAnimatedProps={
40
- {
41
- "value": {},
42
- }
43
- }
44
- jestAnimatedStyle={
45
- {
46
- "value": {
47
- "opacity": 1,
48
- },
49
- }
50
- }
51
- jestInlineStyle={
52
- [
53
- [
54
- {
55
- "alignItems": "center",
56
- "marginVertical": 10,
57
- },
58
- undefined,
59
- ],
60
- ]
61
- }
62
- style={
63
- [
64
- {
65
- "alignItems": "center",
66
- "marginVertical": 10,
67
- },
68
- undefined,
69
- {
70
- "opacity": 1,
71
- },
72
- ]
73
- }
74
- >
75
- <View
76
- style={
77
- [
78
- {
79
- "alignItems": "center",
80
- "justifyContent": "center",
81
- },
82
- {
83
- "backgroundColor": "#b2b2b2",
84
- "borderRadius": 15,
85
- "paddingHorizontal": 10,
86
- "paddingVertical": 5,
87
- },
88
- undefined,
89
- ]
90
- }
91
- >
92
- <View
93
- style={
94
- {
95
- "paddingBottom": 4,
96
- "paddingTop": 3,
97
- }
98
- }
99
- >
100
- <Text
101
- style={
102
- [
103
- {
104
- "backgroundColor": "transparent",
105
- "color": "#fff",
106
- "fontSize": 12,
107
- "lineHeight": 13,
108
- },
109
- undefined,
110
- ]
111
- }
112
- >
113
- Load earlier messages
114
- </Text>
115
- </View>
116
- </View>
117
- </View>
118
- </View>
32
+ />
119
33
  `;
@@ -305,7 +305,7 @@ exports[`Message component should render <Message /> with Avatar 1`] = `
305
305
  }
306
306
  >
307
307
  <Text
308
- showUserAvatar={true}
308
+ isUserAvatarVisible={true}
309
309
  style={
310
310
  [
311
311
  {
@@ -362,7 +362,7 @@ exports[`Message component should render <Message /> with Avatar 1`] = `
362
362
  ]
363
363
  }
364
364
  >
365
- 7:20 PM
365
+ 12:00 AM
366
366
  </Text>
367
367
  </View>
368
368
  </View>
@@ -396,6 +396,45 @@ exports[`Message component should render null if user has no Avatar 1`] = `
396
396
  ]
397
397
  }
398
398
  >
399
+ <View
400
+ style={
401
+ [
402
+ {
403
+ "marginRight": 8,
404
+ },
405
+ undefined,
406
+ undefined,
407
+ ]
408
+ }
409
+ >
410
+ <View
411
+ accessibilityRole="image"
412
+ style={
413
+ [
414
+ {
415
+ "alignItems": "center",
416
+ "justifyContent": "center",
417
+ },
418
+ {
419
+ "borderRadius": 20,
420
+ "height": 40,
421
+ "width": 40,
422
+ },
423
+ {
424
+ "backgroundColor": "transparent",
425
+ },
426
+ [
427
+ {
428
+ "borderRadius": 18,
429
+ "height": 36,
430
+ "width": 36,
431
+ },
432
+ undefined,
433
+ ],
434
+ ]
435
+ }
436
+ />
437
+ </View>
399
438
  <View
400
439
  style={
401
440
  [
@@ -472,7 +511,7 @@ exports[`Message component should render null if user has no Avatar 1`] = `
472
511
  }
473
512
  >
474
513
  <Text
475
- showUserAvatar={true}
514
+ isUserAvatarVisible={true}
476
515
  style={
477
516
  [
478
517
  {
@@ -529,7 +568,7 @@ exports[`Message component should render null if user has no Avatar 1`] = `
529
568
  ]
530
569
  }
531
570
  >
532
- 7:20 PM
571
+ 12:00 AM
533
572
  </Text>
534
573
  </View>
535
574
  </View>
@@ -26,7 +26,7 @@ exports[`should render <MessageText /> and compare with snapshot 1`] = `
26
26
  }
27
27
  >
28
28
  <Text>
29
- test message
29
+ test
30
30
  </Text>
31
31
  </Text>
32
32
  </View>
@@ -2,11 +2,13 @@
2
2
 
3
3
  exports[`Send should always render <Send /> and compare with snapshot 1`] = `
4
4
  <View
5
+ accessibilityLabel="send"
6
+ accessibilityRole="button"
5
7
  accessibilityState={
6
8
  {
7
9
  "busy": undefined,
8
10
  "checked": undefined,
9
- "disabled": undefined,
11
+ "disabled": false,
10
12
  "expanded": undefined,
11
13
  "selected": undefined,
12
14
  }
@@ -20,95 +22,29 @@ exports[`Send should always render <Send /> and compare with snapshot 1`] = `
20
22
  }
21
23
  }
22
24
  accessible={true}
23
- collapsable={false}
24
25
  focusable={true}
25
- onBlur={[Function]}
26
26
  onClick={[Function]}
27
- onFocus={[Function]}
28
27
  onResponderGrant={[Function]}
29
28
  onResponderMove={[Function]}
30
29
  onResponderRelease={[Function]}
31
30
  onResponderTerminate={[Function]}
32
31
  onResponderTerminationRequest={[Function]}
33
32
  onStartShouldSetResponder={[Function]}
34
- >
35
- <View
36
- accessibilityLabel="send"
37
- accessibilityRole="button"
38
- accessible={true}
39
- collapsable={false}
40
- disabled={false}
41
- jestAnimatedProps={
42
- {
43
- "value": {},
44
- }
45
- }
46
- jestAnimatedStyle={
47
- {
48
- "value": {
49
- "opacity": 1,
50
- },
51
- }
52
- }
53
- jestInlineStyle={
54
- [
55
- [
56
- {
57
- "height": 44,
58
- "justifyContent": "flex-end",
59
- },
60
- undefined,
61
- ],
62
- ]
63
- }
64
- style={
65
- [
66
- {
67
- "height": 44,
68
- "justifyContent": "flex-end",
69
- },
70
- undefined,
71
- {
72
- "opacity": 1,
73
- },
74
- ]
75
- }
76
- testID="GC_SEND_TOUCHABLE"
77
- >
78
- <View>
79
- <Text
80
- style={
81
- [
82
- {
83
- "backgroundColor": "transparent",
84
- "color": "#0084ff",
85
- "fontSize": 17,
86
- "fontWeight": "600",
87
- "marginBottom": 12,
88
- "marginLeft": 10,
89
- "marginRight": 10,
90
- },
91
- undefined,
92
- undefined,
93
- ]
94
- }
95
- >
96
- Send
97
- </Text>
98
- </View>
99
- </View>
100
- </View>
33
+ testID="GC_SEND_TOUCHABLE"
34
+ />
101
35
  `;
102
36
 
103
37
  exports[`Send should not render <Send /> and compare with snapshot 1`] = `null`;
104
38
 
105
39
  exports[`Send should render <Send /> where there is input and compare with snapshot 1`] = `
106
40
  <View
41
+ accessibilityLabel="send"
42
+ accessibilityRole="button"
107
43
  accessibilityState={
108
44
  {
109
45
  "busy": undefined,
110
46
  "checked": undefined,
111
- "disabled": undefined,
47
+ "disabled": false,
112
48
  "expanded": undefined,
113
49
  "selected": undefined,
114
50
  }
@@ -122,82 +58,14 @@ exports[`Send should render <Send /> where there is input and compare with snaps
122
58
  }
123
59
  }
124
60
  accessible={true}
125
- collapsable={false}
126
61
  focusable={true}
127
- onBlur={[Function]}
128
62
  onClick={[Function]}
129
- onFocus={[Function]}
130
63
  onResponderGrant={[Function]}
131
64
  onResponderMove={[Function]}
132
65
  onResponderRelease={[Function]}
133
66
  onResponderTerminate={[Function]}
134
67
  onResponderTerminationRequest={[Function]}
135
68
  onStartShouldSetResponder={[Function]}
136
- >
137
- <View
138
- accessibilityLabel="send"
139
- accessibilityRole="button"
140
- accessible={true}
141
- collapsable={false}
142
- disabled={false}
143
- jestAnimatedProps={
144
- {
145
- "value": {},
146
- }
147
- }
148
- jestAnimatedStyle={
149
- {
150
- "value": {
151
- "opacity": 1,
152
- },
153
- }
154
- }
155
- jestInlineStyle={
156
- [
157
- [
158
- {
159
- "height": 44,
160
- "justifyContent": "flex-end",
161
- },
162
- undefined,
163
- ],
164
- ]
165
- }
166
- style={
167
- [
168
- {
169
- "height": 44,
170
- "justifyContent": "flex-end",
171
- },
172
- undefined,
173
- {
174
- "opacity": 1,
175
- },
176
- ]
177
- }
178
- testID="GC_SEND_TOUCHABLE"
179
- >
180
- <View>
181
- <Text
182
- style={
183
- [
184
- {
185
- "backgroundColor": "transparent",
186
- "color": "#0084ff",
187
- "fontSize": 17,
188
- "fontWeight": "600",
189
- "marginBottom": 12,
190
- "marginLeft": 10,
191
- "marginRight": 10,
192
- },
193
- undefined,
194
- undefined,
195
- ]
196
- }
197
- >
198
- Send
199
- </Text>
200
- </View>
201
- </View>
202
- </View>
69
+ testID="GC_SEND_TOUCHABLE"
70
+ />
203
71
  `;
@@ -1,8 +1,8 @@
1
- import { IMessage } from '../types'
1
+ import { IMessage } from '../Models'
2
2
 
3
3
  export const DEFAULT_TEST_MESSAGE: IMessage = {
4
4
  _id: 'test',
5
5
  text: 'test',
6
6
  user: { _id: 'test' },
7
- createdAt: new Date(2022, 3, 17),
7
+ createdAt: new Date(2022, 3, 17).getTime(),
8
8
  }
@@ -1,13 +1,14 @@
1
1
  import React, { useCallback } from 'react'
2
- import { Pressable } from 'react-native-gesture-handler'
2
+ import { BaseButton } from 'react-native-gesture-handler'
3
3
  import Animated, {
4
4
  useAnimatedStyle,
5
5
  useSharedValue,
6
6
  withTiming,
7
7
  } from 'react-native-reanimated'
8
8
 
9
- export type TouchableOpacityProps = React.ComponentProps<typeof Pressable> & {
9
+ export type TouchableOpacityProps = Omit<React.ComponentProps<typeof BaseButton>, 'onPress'> & {
10
10
  activeOpacity?: number
11
+ onPress?: () => void
11
12
  } & React.ComponentProps<typeof Animated.View>
12
13
 
13
14
  export const TouchableOpacity: React.FC<TouchableOpacityProps> = ({
@@ -35,22 +36,32 @@ export const TouchableOpacity: React.FC<TouchableOpacityProps> = ({
35
36
  }, isAnimationInFinished.value ? 0 : 150)
36
37
  }, [opacity, isAnimationInFinished])
37
38
 
39
+ const handleActiveStateChange = useCallback((isActive: boolean) => {
40
+ if (isActive)
41
+ handlePressIn()
42
+ else
43
+ handlePressOut()
44
+ }, [handlePressIn, handlePressOut])
45
+
38
46
  const animatedStyle = useAnimatedStyle(() => ({
39
47
  opacity: opacity.value,
40
48
  }))
41
49
 
50
+ const handlePress = useCallback(() => {
51
+ onPress?.()
52
+ }, [onPress])
53
+
42
54
  return (
43
- <Pressable
44
- onPressIn={handlePressIn}
45
- onPressOut={handlePressOut}
46
- onPress={onPress}
55
+ <BaseButton
56
+ {...rest}
57
+ onPress={handlePress}
58
+ onActiveStateChange={handleActiveStateChange}
47
59
  >
48
60
  <Animated.View
49
- {...rest}
50
61
  style={[style, animatedStyle]}
51
62
  >
52
63
  {children}
53
64
  </Animated.View>
54
- </Pressable>
65
+ </BaseButton>
55
66
  )
56
67
  }