react-native-gifted-chat 3.0.1 → 3.1.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/README.md +1 -1
- package/package.json +1 -1
- package/src/Actions.tsx +2 -2
- package/src/Bubble/index.tsx +37 -42
- package/src/Bubble/styles.ts +54 -68
- package/src/Bubble/types.ts +3 -2
- package/src/Composer.tsx +1 -1
- package/src/Day/index.tsx +2 -2
- package/src/GiftedAvatar.tsx +2 -2
- package/src/GiftedChat/index.tsx +1 -2
- package/src/LoadEarlierMessages.tsx +2 -2
- package/src/Message/index.tsx +4 -3
- package/src/Message/styles.ts +16 -20
- package/src/MessageAudio.tsx +3 -2
- package/src/MessageImage.tsx +1 -1
- package/src/MessageText.tsx +3 -5
- package/src/MessageVideo.tsx +3 -2
- package/src/MessagesContainer/index.tsx +1 -2
- package/src/QuickReplies.tsx +1 -1
- package/src/Send.tsx +2 -2
- package/src/SystemMessage.tsx +23 -18
- package/src/Time.tsx +13 -39
- package/src/__tests__/GiftedChat.test.tsx +1 -1
- package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +46 -65
- package/src/__tests__/__snapshots__/Composer.test.tsx.snap +5 -0
- package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +5 -0
- package/src/__tests__/__snapshots__/Message.test.tsx.snap +143 -200
- package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +2 -29
- package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +2 -4
- package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +39 -42
- package/src/__tests__/__snapshots__/Time.test.tsx.snap +1 -12
- package/src/styles.ts +11 -2
package/src/SystemMessage.tsx
CHANGED
|
@@ -14,48 +14,53 @@ import stylesCommon from './styles'
|
|
|
14
14
|
export interface SystemMessageProps<TMessage extends IMessage> {
|
|
15
15
|
currentMessage: TMessage
|
|
16
16
|
containerStyle?: StyleProp<ViewStyle>
|
|
17
|
-
|
|
17
|
+
messageContainerStyle?: StyleProp<ViewStyle>
|
|
18
18
|
textStyle?: StyleProp<TextStyle>
|
|
19
19
|
children?: React.ReactNode
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export function SystemMessage<TMessage extends IMessage
|
|
22
|
+
export function SystemMessage<TMessage extends IMessage> ({
|
|
23
23
|
currentMessage,
|
|
24
24
|
containerStyle,
|
|
25
|
-
|
|
25
|
+
messageContainerStyle,
|
|
26
26
|
textStyle,
|
|
27
27
|
children,
|
|
28
28
|
}: SystemMessageProps<TMessage>) {
|
|
29
|
-
if (currentMessage == null
|
|
29
|
+
if (currentMessage == null)
|
|
30
30
|
return null
|
|
31
31
|
|
|
32
32
|
return (
|
|
33
|
-
<View style={[stylesCommon.fill,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
<View style={[stylesCommon.fill, styles.container, containerStyle]}>
|
|
34
|
+
{
|
|
35
|
+
!!currentMessage.text && (
|
|
36
|
+
<MessageText
|
|
37
|
+
currentMessage={currentMessage}
|
|
38
|
+
customTextStyle={[styles.text, textStyle]}
|
|
39
|
+
position='left'
|
|
40
|
+
containerStyle={{ left: [styles.messageContainer, messageContainerStyle] }}
|
|
41
|
+
/>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
{children}
|
|
42
45
|
</View>
|
|
43
46
|
)
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
const styles = StyleSheet.create({
|
|
47
50
|
container: {
|
|
48
|
-
marginTop: 5,
|
|
49
|
-
marginBottom: 10,
|
|
50
|
-
marginHorizontal: 20,
|
|
51
|
-
},
|
|
52
|
-
messageContainer: {
|
|
53
51
|
borderRadius: 20,
|
|
54
52
|
borderWidth: 1,
|
|
55
53
|
borderColor: 'rgba(0,0,0,0.1)',
|
|
56
54
|
paddingHorizontal: 10,
|
|
57
55
|
paddingVertical: 10,
|
|
58
56
|
backgroundColor: 'rgba(0,0,0,0.05)',
|
|
57
|
+
marginVertical: 5,
|
|
58
|
+
marginHorizontal: 10,
|
|
59
|
+
alignItems: 'flex-end',
|
|
60
|
+
},
|
|
61
|
+
messageContainer: {
|
|
62
|
+
marginVertical: 0,
|
|
63
|
+
marginHorizontal: 0,
|
|
59
64
|
},
|
|
60
65
|
text: {
|
|
61
66
|
backgroundColor: Color.backgroundTransparent,
|
package/src/Time.tsx
CHANGED
|
@@ -1,48 +1,27 @@
|
|
|
1
1
|
import React, { useMemo } from 'react'
|
|
2
|
-
import { StyleSheet,
|
|
2
|
+
import { StyleSheet, View, ViewStyle, TextStyle } from 'react-native'
|
|
3
3
|
import dayjs from 'dayjs'
|
|
4
4
|
|
|
5
|
+
import { Text } from 'react-native-gesture-handler'
|
|
5
6
|
import { Color } from './Color'
|
|
6
7
|
import { TIME_FORMAT } from './Constant'
|
|
7
8
|
import { useChatContext } from './GiftedChatContext'
|
|
8
9
|
import { LeftRightStyle, IMessage } from './Models'
|
|
10
|
+
import { getStyleWithPosition } from './styles'
|
|
9
11
|
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
marginLeft: 10,
|
|
13
|
-
marginRight: 10,
|
|
14
|
-
marginBottom: 5,
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const { textStyle } = StyleSheet.create({
|
|
19
|
-
textStyle: {
|
|
12
|
+
const styles = StyleSheet.create({
|
|
13
|
+
text: {
|
|
20
14
|
fontSize: 10,
|
|
21
15
|
textAlign: 'right',
|
|
22
16
|
},
|
|
17
|
+
text_left: {
|
|
18
|
+
color: Color.timeTextColor,
|
|
19
|
+
},
|
|
20
|
+
text_right: {
|
|
21
|
+
color: Color.white,
|
|
22
|
+
},
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
const styles = {
|
|
26
|
-
left: StyleSheet.create({
|
|
27
|
-
container: {
|
|
28
|
-
...containerStyle,
|
|
29
|
-
},
|
|
30
|
-
text: {
|
|
31
|
-
color: Color.timeTextColor,
|
|
32
|
-
...textStyle,
|
|
33
|
-
},
|
|
34
|
-
}),
|
|
35
|
-
right: StyleSheet.create({
|
|
36
|
-
container: {
|
|
37
|
-
...containerStyle,
|
|
38
|
-
},
|
|
39
|
-
text: {
|
|
40
|
-
color: Color.white,
|
|
41
|
-
...textStyle,
|
|
42
|
-
},
|
|
43
|
-
}),
|
|
44
|
-
}
|
|
45
|
-
|
|
46
25
|
export interface TimeProps<TMessage extends IMessage> {
|
|
47
26
|
position?: 'left' | 'right'
|
|
48
27
|
currentMessage: TMessage
|
|
@@ -71,15 +50,10 @@ export const Time = <TMessage extends IMessage = IMessage>({
|
|
|
71
50
|
return null
|
|
72
51
|
|
|
73
52
|
return (
|
|
74
|
-
<View
|
|
75
|
-
style={[
|
|
76
|
-
styles[position].container,
|
|
77
|
-
containerStyle?.[position],
|
|
78
|
-
]}
|
|
79
|
-
>
|
|
53
|
+
<View style={containerStyle?.[position]}>
|
|
80
54
|
<Text
|
|
81
55
|
style={[
|
|
82
|
-
styles
|
|
56
|
+
getStyleWithPosition(styles, 'text', position),
|
|
83
57
|
timeTextStyle?.[position],
|
|
84
58
|
]}
|
|
85
59
|
>
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`should render <Bubble /> and compare with snapshot 1`] = `
|
|
4
|
-
<View
|
|
5
|
-
style={
|
|
6
|
-
[
|
|
7
|
-
{
|
|
8
|
-
"flex": 1,
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"alignItems": "flex-start",
|
|
12
|
-
},
|
|
13
|
-
undefined,
|
|
14
|
-
]
|
|
15
|
-
}
|
|
16
|
-
>
|
|
4
|
+
<View>
|
|
17
5
|
<View
|
|
18
6
|
style={
|
|
19
7
|
[
|
|
@@ -21,7 +9,6 @@ exports[`should render <Bubble /> and compare with snapshot 1`] = `
|
|
|
21
9
|
"backgroundColor": "#f0f0f0",
|
|
22
10
|
"borderRadius": 15,
|
|
23
11
|
"justifyContent": "flex-end",
|
|
24
|
-
"marginRight": 60,
|
|
25
12
|
"minHeight": 20,
|
|
26
13
|
},
|
|
27
14
|
null,
|
|
@@ -61,66 +48,60 @@ exports[`should render <Bubble /> and compare with snapshot 1`] = `
|
|
|
61
48
|
onResponderTerminationRequest={[Function]}
|
|
62
49
|
onStartShouldSetResponder={[Function]}
|
|
63
50
|
>
|
|
64
|
-
<View
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
>
|
|
79
|
-
<Text
|
|
80
|
-
style={
|
|
81
|
-
[
|
|
82
|
-
{
|
|
83
|
-
"color": "black",
|
|
84
|
-
},
|
|
85
|
-
undefined,
|
|
86
|
-
undefined,
|
|
87
|
-
]
|
|
88
|
-
}
|
|
89
|
-
user={
|
|
90
|
-
{
|
|
91
|
-
"_id": 1,
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
>
|
|
95
|
-
<Text>
|
|
96
|
-
test
|
|
97
|
-
</Text>
|
|
98
|
-
</Text>
|
|
99
|
-
</View>
|
|
100
|
-
</View>
|
|
101
|
-
<View
|
|
51
|
+
<View
|
|
52
|
+
style={
|
|
53
|
+
[
|
|
54
|
+
{
|
|
55
|
+
"marginHorizontal": 10,
|
|
56
|
+
"marginVertical": 5,
|
|
57
|
+
},
|
|
58
|
+
undefined,
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
<Text
|
|
102
63
|
style={
|
|
103
64
|
[
|
|
104
65
|
{
|
|
105
|
-
"
|
|
106
|
-
"justifyContent": "flex-start",
|
|
66
|
+
"color": "black",
|
|
107
67
|
},
|
|
108
68
|
undefined,
|
|
69
|
+
undefined,
|
|
109
70
|
]
|
|
110
71
|
}
|
|
72
|
+
user={
|
|
73
|
+
{
|
|
74
|
+
"_id": 1,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
111
77
|
>
|
|
112
|
-
<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
78
|
+
<Text>
|
|
79
|
+
test
|
|
80
|
+
</Text>
|
|
81
|
+
</Text>
|
|
82
|
+
</View>
|
|
83
|
+
<View
|
|
84
|
+
style={
|
|
85
|
+
[
|
|
86
|
+
{
|
|
87
|
+
"alignItems": "flex-end",
|
|
88
|
+
"flexDirection": "row",
|
|
89
|
+
"justifyContent": "space-between",
|
|
90
|
+
"paddingBottom": 5,
|
|
91
|
+
"paddingHorizontal": 10,
|
|
92
|
+
},
|
|
93
|
+
undefined,
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
>
|
|
97
|
+
<View
|
|
98
|
+
style={
|
|
99
|
+
{
|
|
100
|
+
"flex": 1,
|
|
122
101
|
}
|
|
123
|
-
|
|
102
|
+
}
|
|
103
|
+
>
|
|
104
|
+
<View>
|
|
124
105
|
<Text
|
|
125
106
|
style={
|
|
126
107
|
[
|
|
@@ -11,10 +11,15 @@ exports[`should render <Composer /> and compare with snapshot 1`] = `
|
|
|
11
11
|
<TextInput
|
|
12
12
|
accessibilityLabel="Type a message..."
|
|
13
13
|
accessible={true}
|
|
14
|
+
collapsable={false}
|
|
14
15
|
enablesReturnKeyAutomatically={true}
|
|
16
|
+
handlerTag={-1}
|
|
17
|
+
handlerType="NativeViewGestureHandler"
|
|
15
18
|
keyboardAppearance="default"
|
|
16
19
|
multiline={true}
|
|
17
20
|
onChange={[Function]}
|
|
21
|
+
onGestureHandlerEvent={[Function]}
|
|
22
|
+
onGestureHandlerStateChange={[Function]}
|
|
18
23
|
placeholder="Type a message..."
|
|
19
24
|
placeholderTextColor="#b2b2b2"
|
|
20
25
|
style={
|
|
@@ -40,10 +40,15 @@ exports[`should render <InputToolbar /> and compare with snapshot 1`] = `
|
|
|
40
40
|
<TextInput
|
|
41
41
|
accessibilityLabel="Type a message..."
|
|
42
42
|
accessible={true}
|
|
43
|
+
collapsable={false}
|
|
43
44
|
enablesReturnKeyAutomatically={true}
|
|
45
|
+
handlerTag={-1}
|
|
46
|
+
handlerType="NativeViewGestureHandler"
|
|
44
47
|
keyboardAppearance="default"
|
|
45
48
|
multiline={true}
|
|
46
49
|
onChange={[Function]}
|
|
50
|
+
onGestureHandlerEvent={[Function]}
|
|
51
|
+
onGestureHandlerStateChange={[Function]}
|
|
47
52
|
placeholder="Type a message..."
|
|
48
53
|
placeholderTextColor="#b2b2b2"
|
|
49
54
|
style={
|