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.
- package/CHANGELOG.md +295 -0
- package/README.md +12 -30
- package/package.json +1 -1
- package/src/Actions.tsx +27 -18
- package/src/Composer.tsx +21 -84
- package/src/Constant.ts +0 -9
- package/src/GiftedChat/index.tsx +13 -38
- package/src/GiftedChat/types.ts +8 -6
- package/src/InputToolbar.tsx +6 -11
- package/src/MessageImage.tsx +94 -57
- package/src/{MessageContainer → MessagesContainer}/components/Item/index.tsx +21 -17
- package/src/{MessageContainer → MessagesContainer}/components/Item/types.ts +3 -2
- package/src/{MessageContainer → MessagesContainer}/index.tsx +16 -14
- package/src/{MessageContainer → MessagesContainer}/types.ts +4 -2
- package/src/Send.tsx +40 -22
- package/src/__tests__/DayAnimated.test.tsx +1 -1
- package/src/__tests__/{MessageContainer.test.tsx → MessagesContainer.test.tsx} +7 -7
- package/src/__tests__/__snapshots__/Actions.test.tsx.snap +31 -23
- package/src/__tests__/__snapshots__/Composer.test.tsx.snap +29 -30
- package/src/__tests__/__snapshots__/Constant.test.tsx.snap +0 -2
- package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +102 -31
- package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +251 -0
- package/src/__tests__/__snapshots__/Send.test.tsx.snap +189 -49
- package/src/index.ts +1 -1
- package/src/styles.ts +5 -0
- package/src/types.ts +1 -1
- package/CHANGELOG_2.8.1_to_2.8.2-alpha.5.md +0 -374
- /package/src/{MessageContainer → MessagesContainer}/components/DayAnimated/index.tsx +0 -0
- /package/src/{MessageContainer → MessagesContainer}/components/DayAnimated/styles.ts +0 -0
- /package/src/{MessageContainer → MessagesContainer}/components/DayAnimated/types.ts +0 -0
- /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
|
|
52
|
+
const isVisible = useMemo(
|
|
51
53
|
() => isSendButtonAlwaysVisible || !!text?.trim().length,
|
|
52
54
|
[isSendButtonAlwaysVisible, text]
|
|
53
55
|
)
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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 '../
|
|
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 {
|
|
4
|
+
import { MessagesContainer } from '..'
|
|
5
5
|
import { DEFAULT_TEST_MESSAGE } from './data'
|
|
6
6
|
|
|
7
|
-
it('should render <
|
|
7
|
+
it('should render <MessagesContainer /> without crashing', () => {
|
|
8
8
|
// Just verify it renders without throwing
|
|
9
9
|
expect(() => render(
|
|
10
|
-
<
|
|
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 <
|
|
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
|
-
<
|
|
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 <
|
|
31
|
+
it('should render <MessagesContainer /> with empty messages', () => {
|
|
32
32
|
expect(() => render(
|
|
33
|
-
<
|
|
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
|
-
|
|
5
|
+
style={
|
|
6
6
|
{
|
|
7
|
-
"
|
|
8
|
-
"checked": undefined,
|
|
9
|
-
"disabled": false,
|
|
10
|
-
"expanded": undefined,
|
|
11
|
-
"selected": undefined,
|
|
7
|
+
"alignItems": "flex-end",
|
|
12
8
|
}
|
|
13
9
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
<
|
|
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
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
`;
|
|
@@ -4,12 +4,14 @@ exports[`should render <InputToolbar /> and compare with snapshot 1`] = `
|
|
|
4
4
|
<View
|
|
5
5
|
style={
|
|
6
6
|
[
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
[
|
|
23
|
+
{
|
|
24
|
+
"alignItems": "flex-end",
|
|
25
|
+
"flexDirection": "row",
|
|
26
|
+
},
|
|
27
|
+
undefined,
|
|
28
|
+
],
|
|
24
29
|
undefined,
|
|
25
30
|
]
|
|
26
31
|
}
|
|
27
32
|
>
|
|
28
|
-
<
|
|
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
|
-
"
|
|
81
|
+
"justifyContent": "flex-end",
|
|
41
82
|
},
|
|
83
|
+
undefined,
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
pointerEvents="none"
|
|
87
|
+
style={
|
|
88
|
+
[
|
|
42
89
|
{
|
|
43
|
-
"
|
|
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
|
-
"
|
|
94
|
+
"opacity": 0,
|
|
53
95
|
},
|
|
54
96
|
]
|
|
55
97
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
`;
|