react-native-gifted-chat 3.0.0-alpha.1 → 3.0.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 (31) hide show
  1. package/CHANGELOG.md +295 -0
  2. package/README.md +12 -30
  3. package/package.json +1 -1
  4. package/src/Actions.tsx +27 -18
  5. package/src/Composer.tsx +21 -84
  6. package/src/Constant.ts +0 -9
  7. package/src/GiftedChat/index.tsx +13 -38
  8. package/src/GiftedChat/types.ts +8 -6
  9. package/src/InputToolbar.tsx +6 -11
  10. package/src/MessageImage.tsx +94 -57
  11. package/src/{MessageContainer → MessagesContainer}/components/Item/index.tsx +21 -17
  12. package/src/{MessageContainer → MessagesContainer}/components/Item/types.ts +3 -2
  13. package/src/{MessageContainer → MessagesContainer}/index.tsx +16 -14
  14. package/src/{MessageContainer → MessagesContainer}/types.ts +4 -2
  15. package/src/Send.tsx +40 -22
  16. package/src/__tests__/DayAnimated.test.tsx +1 -1
  17. package/src/__tests__/{MessageContainer.test.tsx → MessagesContainer.test.tsx} +7 -7
  18. package/src/__tests__/__snapshots__/Actions.test.tsx.snap +31 -23
  19. package/src/__tests__/__snapshots__/Composer.test.tsx.snap +29 -30
  20. package/src/__tests__/__snapshots__/Constant.test.tsx.snap +0 -2
  21. package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +102 -31
  22. package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +251 -0
  23. package/src/__tests__/__snapshots__/Send.test.tsx.snap +189 -49
  24. package/src/index.ts +1 -1
  25. package/src/styles.ts +5 -0
  26. package/src/types.ts +1 -1
  27. package/CHANGELOG_2.8.1_to_2.8.2-alpha.5.md +0 -374
  28. /package/src/{MessageContainer → MessagesContainer}/components/DayAnimated/index.tsx +0 -0
  29. /package/src/{MessageContainer → MessagesContainer}/components/DayAnimated/styles.ts +0 -0
  30. /package/src/{MessageContainer → MessagesContainer}/components/DayAnimated/types.ts +0 -0
  31. /package/src/{MessageContainer → MessagesContainer}/styles.ts +0 -0
package/src/Send.tsx CHANGED
@@ -1,18 +1,19 @@
1
- import React, { useMemo, useCallback } from 'react'
1
+ import React, { useMemo, useCallback, useEffect } from 'react'
2
2
  import {
3
3
  StyleSheet,
4
4
  Text,
5
- View,
6
5
  StyleProp,
7
6
  ViewStyle,
8
7
  TextStyle,
9
8
  useColorScheme,
10
9
  } from 'react-native'
10
+ import Animated, { useSharedValue, useAnimatedStyle, withTiming } from 'react-native-reanimated'
11
11
  import { Color } from './Color'
12
12
 
13
13
  import { TouchableOpacity, TouchableOpacityProps } from './components/TouchableOpacity'
14
14
  import { TEST_ID } from './Constant'
15
15
  import { IMessage } from './Models'
16
+ import { getColorSchemeStyle } from './styles'
16
17
 
17
18
  export interface SendProps<TMessage extends IMessage> {
18
19
  text?: string
@@ -39,6 +40,7 @@ export const Send = <TMessage extends IMessage = IMessage>({
39
40
  onSend,
40
41
  }: SendProps<TMessage>) => {
41
42
  const colorScheme = useColorScheme()
43
+ const opacity = useSharedValue(0)
42
44
 
43
45
  const handleOnPress = useCallback(() => {
44
46
  const message = { text: text?.trim() } as Partial<TMessage>
@@ -47,34 +49,51 @@ export const Send = <TMessage extends IMessage = IMessage>({
47
49
  onSend(message, true)
48
50
  }, [text, onSend])
49
51
 
50
- const showSend = useMemo(
52
+ const isVisible = useMemo(
51
53
  () => isSendButtonAlwaysVisible || !!text?.trim().length,
52
54
  [isSendButtonAlwaysVisible, text]
53
55
  )
54
56
 
55
- if (!showSend)
56
- return null
57
+ useEffect(() => {
58
+ opacity.value = withTiming(isVisible ? 1 : 0, { duration: 200 })
59
+ }, [isVisible, opacity])
60
+
61
+ const animatedStyle = useAnimatedStyle(() => ({
62
+ opacity: opacity.value,
63
+ }), [opacity])
57
64
 
58
65
  return (
59
- <TouchableOpacity
60
- testID={TEST_ID.SEND_TOUCHABLE}
61
- style={[styles.container, containerStyle]}
62
- onPress={handleOnPress}
63
- accessible
64
- accessibilityLabel='send'
65
- accessibilityRole='button'
66
- {...sendButtonProps}
67
- >
68
- <View>
69
- {children || <Text style={[styles.text, styles[`text_${colorScheme}`], textStyle]}>{label}</Text>}
70
- </View>
71
- </TouchableOpacity>
66
+ <Animated.View style={[styles.container, containerStyle, animatedStyle]} pointerEvents={isVisible ? 'auto' : 'none'}>
67
+ <TouchableOpacity
68
+ testID={TEST_ID.SEND_TOUCHABLE}
69
+ style={styles.touchable}
70
+ onPress={handleOnPress}
71
+ accessible
72
+ accessibilityLabel='send'
73
+ accessibilityRole='button'
74
+ {...sendButtonProps}
75
+ >
76
+ {
77
+ children ||
78
+ <Text
79
+ style={[
80
+ getColorSchemeStyle(styles, 'text', colorScheme),
81
+ textStyle,
82
+ ]}
83
+ >
84
+ {label}
85
+ </Text>
86
+ }
87
+ </TouchableOpacity>
88
+ </Animated.View>
72
89
  )
73
90
  }
74
91
 
75
92
  const styles = StyleSheet.create({
76
93
  container: {
77
- height: 44,
94
+ justifyContent: 'flex-end',
95
+ },
96
+ touchable: {
78
97
  justifyContent: 'flex-end',
79
98
  },
80
99
  text: {
@@ -82,9 +101,8 @@ const styles = StyleSheet.create({
82
101
  fontWeight: '600',
83
102
  fontSize: 17,
84
103
  backgroundColor: Color.backgroundTransparent,
85
- marginBottom: 12,
86
- marginLeft: 10,
87
- marginRight: 10,
104
+ paddingVertical: 10,
105
+ paddingHorizontal: 10,
88
106
  },
89
107
  text_dark: {
90
108
  color: '#4da6ff',
@@ -2,7 +2,7 @@ import React from 'react'
2
2
  import { View, Text } from 'react-native'
3
3
  import { render } from '@testing-library/react-native'
4
4
  import { DayProps } from '../Day'
5
- import { DayAnimated } from '../MessageContainer/components/DayAnimated'
5
+ import { DayAnimated } from '../MessagesContainer/components/DayAnimated'
6
6
  import { DEFAULT_TEST_MESSAGE } from './data'
7
7
 
8
8
  const mockDaysPositions = { value: {} }
@@ -1,36 +1,36 @@
1
1
  import React from 'react'
2
2
  import { render } from '@testing-library/react-native'
3
3
 
4
- import { MessageContainer } from '..'
4
+ import { MessagesContainer } from '..'
5
5
  import { DEFAULT_TEST_MESSAGE } from './data'
6
6
 
7
- it('should render <MessageContainer /> without crashing', () => {
7
+ it('should render <MessagesContainer /> without crashing', () => {
8
8
  // Just verify it renders without throwing
9
9
  expect(() => render(
10
- <MessageContainer
10
+ <MessagesContainer
11
11
  messages={[DEFAULT_TEST_MESSAGE]}
12
12
  user={{ _id: 1 }}
13
13
  />
14
14
  )).not.toThrow()
15
15
  })
16
16
 
17
- it('should render <MessageContainer /> with multiple messages', () => {
17
+ it('should render <MessagesContainer /> with multiple messages', () => {
18
18
  const messages = [
19
19
  { ...DEFAULT_TEST_MESSAGE, _id: 'test1' },
20
20
  { ...DEFAULT_TEST_MESSAGE, _id: 'test2' },
21
21
  ]
22
22
 
23
23
  expect(() => render(
24
- <MessageContainer
24
+ <MessagesContainer
25
25
  messages={messages}
26
26
  user={{ _id: 1 }}
27
27
  />
28
28
  )).not.toThrow()
29
29
  })
30
30
 
31
- it('should render <MessageContainer /> with empty messages', () => {
31
+ it('should render <MessagesContainer /> with empty messages', () => {
32
32
  expect(() => render(
33
- <MessageContainer
33
+ <MessagesContainer
34
34
  messages={[]}
35
35
  user={{ _id: 1 }}
36
36
  />
@@ -2,31 +2,39 @@
2
2
 
3
3
  exports[`should render <Actions /> and compare with snapshot 1`] = `
4
4
  <View
5
- accessibilityState={
5
+ style={
6
6
  {
7
- "busy": undefined,
8
- "checked": undefined,
9
- "disabled": false,
10
- "expanded": undefined,
11
- "selected": undefined,
7
+ "alignItems": "flex-end",
12
8
  }
13
9
  }
14
- accessibilityValue={
15
- {
16
- "max": undefined,
17
- "min": undefined,
18
- "now": undefined,
19
- "text": undefined,
10
+ >
11
+ <View
12
+ accessibilityState={
13
+ {
14
+ "busy": undefined,
15
+ "checked": undefined,
16
+ "disabled": false,
17
+ "expanded": undefined,
18
+ "selected": undefined,
19
+ }
20
20
  }
21
- }
22
- accessible={true}
23
- focusable={true}
24
- onClick={[Function]}
25
- onResponderGrant={[Function]}
26
- onResponderMove={[Function]}
27
- onResponderRelease={[Function]}
28
- onResponderTerminate={[Function]}
29
- onResponderTerminationRequest={[Function]}
30
- onStartShouldSetResponder={[Function]}
31
- />
21
+ accessibilityValue={
22
+ {
23
+ "max": undefined,
24
+ "min": undefined,
25
+ "now": undefined,
26
+ "text": undefined,
27
+ }
28
+ }
29
+ accessible={true}
30
+ focusable={true}
31
+ onClick={[Function]}
32
+ onResponderGrant={[Function]}
33
+ onResponderMove={[Function]}
34
+ onResponderRelease={[Function]}
35
+ onResponderTerminate={[Function]}
36
+ onResponderTerminationRequest={[Function]}
37
+ onStartShouldSetResponder={[Function]}
38
+ />
39
+ </View>
32
40
  `;
@@ -1,36 +1,35 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`should render <Composer /> and compare with snapshot 1`] = `
4
- <TextInput
5
- accessibilityLabel="Type a message..."
6
- accessible={true}
7
- enablesReturnKeyAutomatically={true}
8
- keyboardAppearance="default"
9
- multiline={true}
10
- onContentSizeChange={[Function]}
11
- placeholder="Type a message..."
12
- placeholderTextColor="#b2b2b2"
4
+ <View
13
5
  style={
14
- [
15
- {
16
- "flex": 1,
17
- },
18
- {
19
- "fontSize": 16,
20
- "lineHeight": 22,
21
- "marginBottom": 5,
22
- "marginLeft": 10,
23
- "marginTop": 6,
24
- },
25
- undefined,
26
- undefined,
27
- {
28
- "height": 33,
29
- },
30
- ]
6
+ {
7
+ "flex": 1,
8
+ }
31
9
  }
32
- testID="Type a message..."
33
- underlineColorAndroid="transparent"
34
- value=""
35
- />
10
+ >
11
+ <TextInput
12
+ accessibilityLabel="Type a message..."
13
+ accessible={true}
14
+ enablesReturnKeyAutomatically={true}
15
+ keyboardAppearance="default"
16
+ multiline={true}
17
+ placeholder="Type a message..."
18
+ placeholderTextColor="#b2b2b2"
19
+ style={
20
+ [
21
+ {
22
+ "fontSize": 16,
23
+ "lineHeight": 22,
24
+ "paddingBottom": 10,
25
+ "paddingTop": 8,
26
+ },
27
+ undefined,
28
+ ]
29
+ }
30
+ testID="Type a message..."
31
+ underlineColorAndroid="transparent"
32
+ value=""
33
+ />
34
+ </View>
36
35
  `;
@@ -3,8 +3,6 @@
3
3
  exports[`should compare Constant with snapshot 1`] = `
4
4
  {
5
5
  "DATE_FORMAT": "D MMMM",
6
- "MAX_COMPOSER_HEIGHT": 200,
7
- "MIN_COMPOSER_HEIGHT": 33,
8
6
  "TEST_ID": {
9
7
  "LOADING_WRAPPER": "GC_LOADING_CONTAINER",
10
8
  "SEND_TOUCHABLE": "GC_SEND_TOUCHABLE",
@@ -4,12 +4,14 @@ exports[`should render <InputToolbar /> and compare with snapshot 1`] = `
4
4
  <View
5
5
  style={
6
6
  [
7
- {
8
- "backgroundColor": "#fff",
9
- "borderTopColor": "#b2b2b2",
10
- "borderTopWidth": 0.5,
11
- },
12
- false,
7
+ [
8
+ {
9
+ "backgroundColor": "#fff",
10
+ "borderTopColor": "#b2b2b2",
11
+ "borderTopWidth": 0.5,
12
+ },
13
+ undefined,
14
+ ],
13
15
  undefined,
14
16
  ]
15
17
  }
@@ -17,46 +19,115 @@ exports[`should render <InputToolbar /> and compare with snapshot 1`] = `
17
19
  <View
18
20
  style={
19
21
  [
20
- {
21
- "alignItems": "flex-end",
22
- "flexDirection": "row",
23
- },
22
+ [
23
+ {
24
+ "alignItems": "flex-end",
25
+ "flexDirection": "row",
26
+ },
27
+ undefined,
28
+ ],
24
29
  undefined,
25
30
  ]
26
31
  }
27
32
  >
28
- <TextInput
29
- accessibilityLabel="Type a message..."
30
- accessible={true}
31
- enablesReturnKeyAutomatically={true}
32
- keyboardAppearance="default"
33
- multiline={true}
34
- onContentSizeChange={[Function]}
35
- placeholder="Type a message..."
36
- placeholderTextColor="#b2b2b2"
33
+ <View
37
34
  style={
35
+ {
36
+ "flex": 1,
37
+ }
38
+ }
39
+ >
40
+ <TextInput
41
+ accessibilityLabel="Type a message..."
42
+ accessible={true}
43
+ enablesReturnKeyAutomatically={true}
44
+ keyboardAppearance="default"
45
+ multiline={true}
46
+ placeholder="Type a message..."
47
+ placeholderTextColor="#b2b2b2"
48
+ style={
49
+ [
50
+ {
51
+ "fontSize": 16,
52
+ "lineHeight": 22,
53
+ "paddingBottom": 10,
54
+ "paddingTop": 8,
55
+ },
56
+ undefined,
57
+ ]
58
+ }
59
+ testID="Type a message..."
60
+ underlineColorAndroid="transparent"
61
+ value=""
62
+ />
63
+ </View>
64
+ <View
65
+ collapsable={false}
66
+ jestAnimatedProps={
67
+ {
68
+ "value": {},
69
+ }
70
+ }
71
+ jestAnimatedStyle={
72
+ {
73
+ "value": {
74
+ "opacity": 0,
75
+ },
76
+ }
77
+ }
78
+ jestInlineStyle={
38
79
  [
39
80
  {
40
- "flex": 1,
81
+ "justifyContent": "flex-end",
41
82
  },
83
+ undefined,
84
+ ]
85
+ }
86
+ pointerEvents="none"
87
+ style={
88
+ [
42
89
  {
43
- "fontSize": 16,
44
- "lineHeight": 22,
45
- "marginBottom": 5,
46
- "marginLeft": 10,
47
- "marginTop": 6,
90
+ "justifyContent": "flex-end",
48
91
  },
49
92
  undefined,
50
- undefined,
51
93
  {
52
- "height": 33,
94
+ "opacity": 0,
53
95
  },
54
96
  ]
55
97
  }
56
- testID="Type a message..."
57
- underlineColorAndroid="transparent"
58
- value=""
59
- />
98
+ >
99
+ <View
100
+ accessibilityLabel="send"
101
+ accessibilityRole="button"
102
+ accessibilityState={
103
+ {
104
+ "busy": undefined,
105
+ "checked": undefined,
106
+ "disabled": false,
107
+ "expanded": undefined,
108
+ "selected": undefined,
109
+ }
110
+ }
111
+ accessibilityValue={
112
+ {
113
+ "max": undefined,
114
+ "min": undefined,
115
+ "now": undefined,
116
+ "text": undefined,
117
+ }
118
+ }
119
+ accessible={true}
120
+ focusable={true}
121
+ onClick={[Function]}
122
+ onResponderGrant={[Function]}
123
+ onResponderMove={[Function]}
124
+ onResponderRelease={[Function]}
125
+ onResponderTerminate={[Function]}
126
+ onResponderTerminationRequest={[Function]}
127
+ onStartShouldSetResponder={[Function]}
128
+ testID="GC_SEND_TOUCHABLE"
129
+ />
130
+ </View>
60
131
  </View>
61
132
  </View>
62
133
  `;