react-native-gifted-chat 2.9.0-alpha.0 → 3.0.0-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 (38) hide show
  1. package/README.md +234 -319
  2. package/package.json +2 -2
  3. package/src/Avatar.tsx +12 -12
  4. package/src/Bubble/index.tsx +2 -2
  5. package/src/Bubble/types.ts +22 -22
  6. package/src/Composer.tsx +0 -3
  7. package/src/GiftedAvatar.tsx +1 -1
  8. package/src/GiftedChat/index.tsx +56 -145
  9. package/src/GiftedChat/types.ts +40 -52
  10. package/src/InputToolbar.tsx +6 -6
  11. package/src/Message/index.tsx +5 -6
  12. package/src/Message/types.ts +8 -12
  13. package/src/MessageContainer/components/DayAnimated/types.ts +1 -1
  14. package/src/MessageContainer/components/Item/index.tsx +2 -2
  15. package/src/MessageContainer/components/Item/types.ts +1 -1
  16. package/src/MessageContainer/index.tsx +30 -30
  17. package/src/MessageContainer/styles.ts +12 -5
  18. package/src/MessageContainer/types.ts +12 -16
  19. package/src/MessageImage.tsx +100 -67
  20. package/src/MessageText.tsx +1 -1
  21. package/src/Models.ts +63 -0
  22. package/src/QuickReplies.tsx +1 -1
  23. package/src/Send.tsx +30 -31
  24. package/src/SystemMessage.tsx +1 -1
  25. package/src/Time.tsx +1 -1
  26. package/src/__tests__/GiftedChat.test.tsx +0 -28
  27. package/src/__tests__/Message.test.tsx +2 -2
  28. package/src/__tests__/Send.test.tsx +1 -1
  29. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +2 -86
  30. package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +31 -54
  31. package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +3 -89
  32. package/src/__tests__/__snapshots__/Message.test.tsx.snap +2 -2
  33. package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +1 -1
  34. package/src/__tests__/__snapshots__/Send.test.tsx.snap +10 -142
  35. package/src/__tests__/data.ts +1 -1
  36. package/src/components/TouchableOpacity.tsx +19 -8
  37. package/src/types.ts +1 -63
  38. package/src/utils.ts +1 -1
@@ -1,48 +1,16 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`should render <GiftedChat/> and compare with snapshot 1`] = `
4
- <KeyboardProvider>
5
- <View
6
- style={
7
- {
8
- "flex": 1,
9
- }
10
- }
11
- >
12
- <View
13
- style={
14
- {
15
- "flex": 1,
16
- }
17
- }
18
- >
19
- <View
20
- onLayout={[Function]}
21
- style={
22
- [
23
- {
24
- "flex": 1,
25
- },
26
- {
27
- "overflow": "hidden",
28
- },
29
- ]
30
- }
31
- testID="GC_WRAPPER"
32
- />
33
- </View>
34
- </View>
35
- </KeyboardProvider>
36
- `;
37
-
38
- exports[`should render <GiftedChat/> with isKeyboardInternallyHandled=false 1`] = `
39
- <KeyboardProvider>
40
- <View
41
- style={
42
- {
43
- "flex": 1,
44
- }
4
+ <View
5
+ style={
6
+ {
7
+ "flex": 1,
45
8
  }
9
+ }
10
+ >
11
+ <KeyboardProvider
12
+ navigationBarTranslucent={true}
13
+ statusBarTranslucent={true}
46
14
  >
47
15
  <View
48
16
  style={
@@ -52,20 +20,29 @@ exports[`should render <GiftedChat/> with isKeyboardInternallyHandled=false 1`]
52
20
  }
53
21
  >
54
22
  <View
55
- onLayout={[Function]}
23
+ behavior="padding"
56
24
  style={
57
- [
58
- {
59
- "flex": 1,
60
- },
61
- {
62
- "overflow": "hidden",
63
- },
64
- ]
25
+ {
26
+ "flex": 1,
27
+ }
65
28
  }
66
- testID="GC_WRAPPER"
67
- />
29
+ >
30
+ <View
31
+ onLayout={[Function]}
32
+ style={
33
+ [
34
+ {
35
+ "flex": 1,
36
+ },
37
+ {
38
+ "overflow": "hidden",
39
+ },
40
+ ]
41
+ }
42
+ testID="GC_WRAPPER"
43
+ />
44
+ </View>
68
45
  </View>
69
- </View>
70
- </KeyboardProvider>
46
+ </KeyboardProvider>
47
+ </View>
71
48
  `;
@@ -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
  {
@@ -511,7 +511,7 @@ exports[`Message component should render null if user has no Avatar 1`] = `
511
511
  }
512
512
  >
513
513
  <Text
514
- showUserAvatar={true}
514
+ isUserAvatarVisible={true}
515
515
  style={
516
516
  [
517
517
  {
@@ -38,6 +38,7 @@ exports[`MessageImage should render <MessageImage /> and compare with snapshot
38
38
  >
39
39
  <Image
40
40
  onLayout={[Function]}
41
+ resizeMode="cover"
41
42
  source={
42
43
  {
43
44
  "uri": "url://to/image.png",
@@ -49,7 +50,6 @@ exports[`MessageImage should render <MessageImage /> and compare with snapshot
49
50
  "borderRadius": 13,
50
51
  "height": 100,
51
52
  "margin": 3,
52
- "resizeMode": "cover",
53
53
  "width": 150,
54
54
  },
55
55
  undefined,
@@ -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,4 +1,4 @@
1
- import { IMessage } from '../types'
1
+ import { IMessage } from '../Models'
2
2
 
3
3
  export const DEFAULT_TEST_MESSAGE: IMessage = {
4
4
  _id: 'test',
@@ -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
  }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { StyleProp, ViewStyle } from 'react-native'
1
+ export * from './Models'
2
2
 
3
3
  export { ActionsProps } from './Actions'
4
4
  export { AvatarProps } from './Avatar'
@@ -22,65 +22,3 @@ export { QuickRepliesProps } from './QuickReplies'
22
22
  export { SendProps } from './Send'
23
23
  export { SystemMessageProps } from './SystemMessage'
24
24
  export { TimeProps } from './Time'
25
-
26
- export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
27
-
28
- export interface LeftRightStyle<T> {
29
- left?: StyleProp<T>
30
- right?: StyleProp<T>
31
- }
32
-
33
- type renderFunction = (x: unknown) => React.ReactNode
34
-
35
- export interface User {
36
- _id: string | number
37
- name?: string
38
- avatar?: string | number | renderFunction
39
- }
40
-
41
- export interface Reply {
42
- title: string
43
- value: string
44
- messageId?: number | string
45
- }
46
-
47
- export interface QuickReplies {
48
- type: 'radio' | 'checkbox'
49
- values: Reply[]
50
- keepIt?: boolean
51
- }
52
-
53
- export interface IMessage {
54
- _id: string | number
55
- text: string
56
- createdAt: Date | number
57
- user: User
58
- image?: string
59
- video?: string
60
- audio?: string
61
- system?: boolean
62
- sent?: boolean
63
- received?: boolean
64
- pending?: boolean
65
- quickReplies?: QuickReplies
66
- location?: {
67
- latitude: number
68
- longitude: number
69
- }
70
- }
71
-
72
- export type IChatMessage = IMessage
73
-
74
- export interface MessageVideoProps<TMessage extends IMessage> {
75
- currentMessage: TMessage
76
- containerStyle?: StyleProp<ViewStyle>
77
- videoStyle?: StyleProp<ViewStyle>
78
- videoProps?: object
79
- }
80
-
81
- export interface MessageAudioProps<TMessage extends IMessage> {
82
- currentMessage: TMessage
83
- containerStyle?: StyleProp<ViewStyle>
84
- audioStyle?: StyleProp<ViewStyle>
85
- audioProps?: object
86
- }
package/src/utils.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useEffect, useRef } from 'react'
2
2
  import dayjs from 'dayjs'
3
- import { IMessage } from './types'
3
+ import { IMessage } from './Models'
4
4
 
5
5
  export function renderComponentOrElement<TProps extends Record<string, any>>(
6
6
  component: React.ComponentType<TProps> | React.ReactElement | ((props: TProps) => React.ReactNode) | null | undefined,