react-native-gifted-chat 2.4.0 → 2.5.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.
- package/README.md +16 -6
- package/lib/Actions.d.ts +5 -6
- package/lib/Actions.js +16 -13
- package/lib/Actions.js.map +1 -1
- package/lib/Avatar.d.ts +10 -24
- package/lib/Avatar.js +24 -35
- package/lib/Avatar.js.flow +1 -1
- package/lib/Avatar.js.map +1 -1
- package/lib/Bubble.d.ts +30 -29
- package/lib/Bubble.js +90 -72
- package/lib/Bubble.js.flow +3 -1
- package/lib/Bubble.js.map +1 -1
- package/lib/Composer.d.ts +1 -1
- package/lib/Composer.js +30 -32
- package/lib/Composer.js.map +1 -1
- package/lib/Constant.js +1 -0
- package/lib/Constant.js.map +1 -1
- package/lib/Day.d.ts +3 -15
- package/lib/Day.js +2 -14
- package/lib/Day.js.flow +1 -1
- package/lib/Day.js.map +1 -1
- package/lib/GiftedAvatar.d.ts +7 -7
- package/lib/GiftedAvatar.js +30 -29
- package/lib/GiftedAvatar.js.map +1 -1
- package/lib/GiftedChat.d.ts +16 -89
- package/lib/GiftedChat.js +204 -350
- package/lib/GiftedChat.js.flow +3 -3
- package/lib/GiftedChat.js.map +1 -1
- package/lib/GiftedChatContext.d.ts +2 -1
- package/lib/GiftedChatContext.js.map +1 -1
- package/lib/InputToolbar.d.ts +7 -5
- package/lib/InputToolbar.js +41 -34
- package/lib/InputToolbar.js.map +1 -1
- package/lib/LoadEarlier.d.ts +4 -4
- package/lib/LoadEarlier.js +8 -6
- package/lib/LoadEarlier.js.map +1 -1
- package/lib/Message.d.ts +8 -9
- package/lib/Message.js +47 -40
- package/lib/Message.js.flow +1 -1
- package/lib/Message.js.map +1 -1
- package/lib/MessageAudio.d.ts +2 -1
- package/lib/MessageAudio.js +4 -4
- package/lib/MessageAudio.js.flow +1 -1
- package/lib/MessageAudio.js.map +1 -1
- package/lib/MessageContainer.d.ts +17 -17
- package/lib/MessageContainer.js +33 -51
- package/lib/MessageContainer.js.map +1 -1
- package/lib/MessageImage.d.ts +8 -5
- package/lib/MessageImage.js +6 -6
- package/lib/MessageImage.js.flow +1 -1
- package/lib/MessageImage.js.map +1 -1
- package/lib/MessageText.d.ts +11 -10
- package/lib/MessageText.js +5 -10
- package/lib/MessageText.js.flow +1 -1
- package/lib/MessageText.js.map +1 -1
- package/lib/MessageVideo.d.ts +2 -1
- package/lib/MessageVideo.js +4 -4
- package/lib/MessageVideo.js.flow +1 -1
- package/lib/MessageVideo.js.map +1 -1
- package/lib/Models.d.ts +7 -7
- package/lib/QuickReplies.d.ts +4 -3
- package/lib/QuickReplies.js +10 -16
- package/lib/QuickReplies.js.flow +4 -2
- package/lib/QuickReplies.js.map +1 -1
- package/lib/Send.d.ts +4 -4
- package/lib/Send.js +6 -9
- package/lib/Send.js.map +1 -1
- package/lib/SystemMessage.d.ts +6 -5
- package/lib/SystemMessage.js +1 -2
- package/lib/SystemMessage.js.flow +1 -1
- package/lib/SystemMessage.js.map +1 -1
- package/lib/Time.d.ts +7 -6
- package/lib/Time.js +1 -3
- package/lib/Time.js.flow +1 -1
- package/lib/Time.js.map +1 -1
- package/lib/TypingIndicator.d.ts +2 -1
- package/lib/TypingIndicator.js +5 -5
- package/lib/TypingIndicator.js.map +1 -1
- package/lib/hooks/useUpdateLayoutEffect.js +2 -4
- package/lib/hooks/useUpdateLayoutEffect.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/logging.d.ts +2 -2
- package/lib/logging.js.map +1 -1
- package/lib/types.js.flow +1 -1
- package/lib/utils.d.ts +1 -1
- package/lib/utils.js +2 -4
- package/lib/utils.js.map +1 -1
- package/package.json +83 -53
- package/src/Actions.tsx +114 -0
- package/src/Avatar.tsx +178 -0
- package/src/Bubble.tsx +601 -0
- package/src/Color.ts +17 -0
- package/src/Composer.tsx +147 -0
- package/src/Constant.ts +18 -0
- package/src/Day.tsx +71 -0
- package/src/GiftedAvatar.tsx +205 -0
- package/src/GiftedChat.tsx +670 -0
- package/src/GiftedChatContext.ts +23 -0
- package/src/InputToolbar.tsx +113 -0
- package/src/LoadEarlier.tsx +108 -0
- package/src/Message.tsx +229 -0
- package/src/MessageAudio.tsx +19 -0
- package/src/MessageContainer.tsx +362 -0
- package/src/MessageImage.tsx +78 -0
- package/src/MessageText.tsx +187 -0
- package/src/MessageVideo.tsx +19 -0
- package/src/Models.ts +84 -0
- package/src/QuickReplies.tsx +186 -0
- package/src/Send.tsx +102 -0
- package/src/SystemMessage.tsx +61 -0
- package/src/Time.tsx +97 -0
- package/src/TypingIndicator.tsx +108 -0
- package/src/__tests__/Actions.test.tsx +10 -0
- package/src/__tests__/Avatar.test.tsx +13 -0
- package/src/__tests__/Bubble.test.tsx +23 -0
- package/src/__tests__/Color.test.tsx +5 -0
- package/src/__tests__/Composer.test.tsx +11 -0
- package/src/__tests__/Constant.test.tsx +5 -0
- package/src/__tests__/Day.test.tsx +23 -0
- package/src/__tests__/GiftedAvatar.test.tsx +11 -0
- package/src/__tests__/GiftedChat.test.tsx +36 -0
- package/src/__tests__/InputToolbar.test.tsx +11 -0
- package/src/__tests__/LoadEarlier.test.tsx +11 -0
- package/src/__tests__/Message.test.tsx +77 -0
- package/src/__tests__/MessageContainer.test.tsx +11 -0
- package/src/__tests__/MessageImage.test.tsx +27 -0
- package/src/__tests__/MessageText.test.tsx +11 -0
- package/src/__tests__/Send.test.tsx +22 -0
- package/src/__tests__/SystemMessage.test.tsx +27 -0
- package/src/__tests__/Time.test.tsx +29 -0
- package/src/__tests__/__snapshots__/Actions.test.tsx.snap +76 -0
- package/src/__tests__/__snapshots__/Avatar.test.tsx.snap +17 -0
- package/src/__tests__/__snapshots__/Bubble.test.tsx.snap +145 -0
- package/src/__tests__/__snapshots__/Color.test.tsx.snap +21 -0
- package/src/__tests__/__snapshots__/Composer.test.tsx.snap +35 -0
- package/src/__tests__/__snapshots__/Constant.test.tsx.snap +16 -0
- package/src/__tests__/__snapshots__/Day.test.tsx.snap +37 -0
- package/src/__tests__/__snapshots__/GiftedAvatar.test.tsx.snap +22 -0
- package/src/__tests__/__snapshots__/GiftedChat.test.tsx.snap +15 -0
- package/src/__tests__/__snapshots__/InputToolbar.test.tsx.snap +60 -0
- package/src/__tests__/__snapshots__/LoadEarlier.test.tsx.snap +74 -0
- package/src/__tests__/__snapshots__/Message.test.tsx.snap +628 -0
- package/src/__tests__/__snapshots__/MessageContainer.test.tsx.snap +127 -0
- package/src/__tests__/__snapshots__/MessageImage.test.tsx.snap +38 -0
- package/src/__tests__/__snapshots__/MessageText.test.tsx.snap +30 -0
- package/src/__tests__/__snapshots__/Send.test.tsx.snap +129 -0
- package/src/__tests__/__snapshots__/SystemMessage.test.tsx.snap +38 -0
- package/src/__tests__/__snapshots__/Time.test.tsx.snap +33 -0
- package/src/__tests__/data.ts +8 -0
- package/src/__tests__/utils.test.ts +31 -0
- package/src/hooks/useUpdateLayoutEffect.ts +21 -0
- package/src/index.ts +4 -0
- package/src/logging.ts +8 -0
- package/src/utils.ts +39 -0
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -21
- package/jest.config.js +0 -15
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React, { useMemo } from 'react'
|
|
3
|
+
import { StyleSheet, View, StyleProp, ViewStyle } from 'react-native'
|
|
4
|
+
|
|
5
|
+
import { Composer, ComposerProps } from './Composer'
|
|
6
|
+
import { Send, SendProps } from './Send'
|
|
7
|
+
import { Actions, ActionsProps } from './Actions'
|
|
8
|
+
import Color from './Color'
|
|
9
|
+
import { StylePropType } from './utils'
|
|
10
|
+
import { IMessage } from './Models'
|
|
11
|
+
|
|
12
|
+
export interface InputToolbarProps<TMessage extends IMessage> {
|
|
13
|
+
options?: { [key: string]: () => void }
|
|
14
|
+
optionTintColor?: string
|
|
15
|
+
containerStyle?: StyleProp<ViewStyle>
|
|
16
|
+
primaryStyle?: StyleProp<ViewStyle>
|
|
17
|
+
accessoryStyle?: StyleProp<ViewStyle>
|
|
18
|
+
renderAccessory?(props: InputToolbarProps<TMessage>): React.ReactNode
|
|
19
|
+
renderActions?(props: ActionsProps): React.ReactNode
|
|
20
|
+
renderSend?(props: SendProps<TMessage>): React.ReactNode
|
|
21
|
+
renderComposer?(props: ComposerProps): React.ReactNode
|
|
22
|
+
onPressActionButton?(): void
|
|
23
|
+
icon?: () => React.ReactNode
|
|
24
|
+
wrapperStyle?: StyleProp<ViewStyle>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function InputToolbar<TMessage extends IMessage = IMessage> (
|
|
28
|
+
props: InputToolbarProps<TMessage>
|
|
29
|
+
) {
|
|
30
|
+
const {
|
|
31
|
+
renderActions,
|
|
32
|
+
onPressActionButton,
|
|
33
|
+
renderComposer,
|
|
34
|
+
renderSend,
|
|
35
|
+
renderAccessory,
|
|
36
|
+
options,
|
|
37
|
+
optionTintColor,
|
|
38
|
+
icon,
|
|
39
|
+
wrapperStyle,
|
|
40
|
+
containerStyle,
|
|
41
|
+
} = props
|
|
42
|
+
|
|
43
|
+
const actionsFragment = useMemo(() => {
|
|
44
|
+
const props = {
|
|
45
|
+
options,
|
|
46
|
+
optionTintColor,
|
|
47
|
+
icon,
|
|
48
|
+
wrapperStyle,
|
|
49
|
+
containerStyle,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
renderActions?.(props) || (onPressActionButton && <Actions {...props} />)
|
|
54
|
+
)
|
|
55
|
+
}, [
|
|
56
|
+
renderActions,
|
|
57
|
+
onPressActionButton,
|
|
58
|
+
options,
|
|
59
|
+
optionTintColor,
|
|
60
|
+
icon,
|
|
61
|
+
wrapperStyle,
|
|
62
|
+
containerStyle,
|
|
63
|
+
])
|
|
64
|
+
|
|
65
|
+
const composerFragment = useMemo(() => {
|
|
66
|
+
return (
|
|
67
|
+
renderComposer?.(props as ComposerProps) || (
|
|
68
|
+
<Composer {...(props as ComposerProps)} />
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
}, [renderComposer, props])
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<View style={[styles.container, containerStyle]}>
|
|
75
|
+
<View style={[styles.primary, props.primaryStyle]}>
|
|
76
|
+
{actionsFragment}
|
|
77
|
+
{composerFragment}
|
|
78
|
+
{renderSend?.(props) || <Send {...props} />}
|
|
79
|
+
</View>
|
|
80
|
+
{renderAccessory && (
|
|
81
|
+
<View style={[styles.accessory, props.accessoryStyle]}>
|
|
82
|
+
{renderAccessory(props)}
|
|
83
|
+
</View>
|
|
84
|
+
)}
|
|
85
|
+
</View>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
InputToolbar.propTypes = {
|
|
90
|
+
renderAccessory: PropTypes.func,
|
|
91
|
+
renderActions: PropTypes.func,
|
|
92
|
+
renderSend: PropTypes.func,
|
|
93
|
+
renderComposer: PropTypes.func,
|
|
94
|
+
onPressActionButton: PropTypes.func,
|
|
95
|
+
containerStyle: StylePropType,
|
|
96
|
+
primaryStyle: StylePropType,
|
|
97
|
+
accessoryStyle: StylePropType,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const styles = StyleSheet.create({
|
|
101
|
+
container: {
|
|
102
|
+
borderTopWidth: StyleSheet.hairlineWidth,
|
|
103
|
+
borderTopColor: Color.defaultColor,
|
|
104
|
+
backgroundColor: Color.white,
|
|
105
|
+
},
|
|
106
|
+
primary: {
|
|
107
|
+
flexDirection: 'row',
|
|
108
|
+
alignItems: 'flex-end',
|
|
109
|
+
},
|
|
110
|
+
accessory: {
|
|
111
|
+
height: 44,
|
|
112
|
+
},
|
|
113
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import {
|
|
4
|
+
ActivityIndicator,
|
|
5
|
+
Platform,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
Text,
|
|
8
|
+
TouchableOpacity,
|
|
9
|
+
View,
|
|
10
|
+
StyleProp,
|
|
11
|
+
ViewStyle,
|
|
12
|
+
TextStyle,
|
|
13
|
+
} from 'react-native'
|
|
14
|
+
import Color from './Color'
|
|
15
|
+
import { StylePropType } from './utils'
|
|
16
|
+
|
|
17
|
+
const styles = StyleSheet.create({
|
|
18
|
+
container: {
|
|
19
|
+
alignItems: 'center',
|
|
20
|
+
marginTop: 5,
|
|
21
|
+
marginBottom: 10,
|
|
22
|
+
},
|
|
23
|
+
wrapper: {
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
justifyContent: 'center',
|
|
26
|
+
backgroundColor: Color.defaultColor,
|
|
27
|
+
borderRadius: 15,
|
|
28
|
+
height: 30,
|
|
29
|
+
paddingLeft: 10,
|
|
30
|
+
paddingRight: 10,
|
|
31
|
+
},
|
|
32
|
+
text: {
|
|
33
|
+
backgroundColor: Color.backgroundTransparent,
|
|
34
|
+
color: Color.white,
|
|
35
|
+
fontSize: 12,
|
|
36
|
+
},
|
|
37
|
+
activityIndicator: {
|
|
38
|
+
marginTop: Platform.select({
|
|
39
|
+
ios: -14,
|
|
40
|
+
android: -16,
|
|
41
|
+
default: -15,
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
export interface LoadEarlierProps {
|
|
47
|
+
isLoadingEarlier?: boolean
|
|
48
|
+
label?: string
|
|
49
|
+
containerStyle?: StyleProp<ViewStyle>
|
|
50
|
+
wrapperStyle?: StyleProp<ViewStyle>
|
|
51
|
+
textStyle?: StyleProp<TextStyle>
|
|
52
|
+
activityIndicatorStyle?: StyleProp<ViewStyle>
|
|
53
|
+
activityIndicatorColor?: string
|
|
54
|
+
activityIndicatorSize?: number | 'small' | 'large'
|
|
55
|
+
onLoadEarlier?(): void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function LoadEarlier ({
|
|
59
|
+
isLoadingEarlier = false,
|
|
60
|
+
onLoadEarlier = () => {},
|
|
61
|
+
label = 'Load earlier messages',
|
|
62
|
+
containerStyle,
|
|
63
|
+
wrapperStyle,
|
|
64
|
+
textStyle,
|
|
65
|
+
activityIndicatorColor = 'white',
|
|
66
|
+
activityIndicatorSize = 'small',
|
|
67
|
+
activityIndicatorStyle,
|
|
68
|
+
}: LoadEarlierProps): React.ReactElement {
|
|
69
|
+
return (
|
|
70
|
+
<TouchableOpacity
|
|
71
|
+
style={[styles.container, containerStyle]}
|
|
72
|
+
onPress={onLoadEarlier}
|
|
73
|
+
disabled={isLoadingEarlier}
|
|
74
|
+
accessibilityRole='button'
|
|
75
|
+
>
|
|
76
|
+
<View style={[styles.wrapper, wrapperStyle]}>
|
|
77
|
+
{isLoadingEarlier
|
|
78
|
+
? (
|
|
79
|
+
<View>
|
|
80
|
+
<Text style={[styles.text, textStyle, { opacity: 0 }]}>
|
|
81
|
+
{label}
|
|
82
|
+
</Text>
|
|
83
|
+
<ActivityIndicator
|
|
84
|
+
color={activityIndicatorColor!}
|
|
85
|
+
size={activityIndicatorSize!}
|
|
86
|
+
style={[styles.activityIndicator, activityIndicatorStyle]}
|
|
87
|
+
/>
|
|
88
|
+
</View>
|
|
89
|
+
)
|
|
90
|
+
: (
|
|
91
|
+
<Text style={[styles.text, textStyle]}>{label}</Text>
|
|
92
|
+
)}
|
|
93
|
+
</View>
|
|
94
|
+
</TouchableOpacity>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
LoadEarlier.propTypes = {
|
|
99
|
+
onLoadEarlier: PropTypes.func,
|
|
100
|
+
isLoadingEarlier: PropTypes.bool,
|
|
101
|
+
label: PropTypes.string,
|
|
102
|
+
containerStyle: StylePropType,
|
|
103
|
+
wrapperStyle: StylePropType,
|
|
104
|
+
textStyle: StylePropType,
|
|
105
|
+
activityIndicatorStyle: StylePropType,
|
|
106
|
+
activityIndicatorColor: PropTypes.string,
|
|
107
|
+
activityIndicatorSize: PropTypes.string,
|
|
108
|
+
}
|
package/src/Message.tsx
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import { View, StyleSheet, ViewStyle, LayoutChangeEvent } from 'react-native'
|
|
4
|
+
import isEqual from 'lodash.isequal'
|
|
5
|
+
|
|
6
|
+
import { Avatar, AvatarProps } from './Avatar'
|
|
7
|
+
import Bubble from './Bubble'
|
|
8
|
+
import { SystemMessage, SystemMessageProps } from './SystemMessage'
|
|
9
|
+
import { Day, DayProps } from './Day'
|
|
10
|
+
|
|
11
|
+
import { StylePropType, isSameUser } from './utils'
|
|
12
|
+
import { IMessage, User, LeftRightStyle } from './Models'
|
|
13
|
+
|
|
14
|
+
const styles = {
|
|
15
|
+
left: StyleSheet.create({
|
|
16
|
+
container: {
|
|
17
|
+
flexDirection: 'row',
|
|
18
|
+
alignItems: 'flex-end',
|
|
19
|
+
justifyContent: 'flex-start',
|
|
20
|
+
marginLeft: 8,
|
|
21
|
+
marginRight: 0,
|
|
22
|
+
},
|
|
23
|
+
}),
|
|
24
|
+
right: StyleSheet.create({
|
|
25
|
+
container: {
|
|
26
|
+
flexDirection: 'row',
|
|
27
|
+
alignItems: 'flex-end',
|
|
28
|
+
justifyContent: 'flex-end',
|
|
29
|
+
marginLeft: 0,
|
|
30
|
+
marginRight: 8,
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MessageProps<TMessage extends IMessage> {
|
|
36
|
+
showUserAvatar?: boolean
|
|
37
|
+
position: 'left' | 'right'
|
|
38
|
+
currentMessage: TMessage
|
|
39
|
+
nextMessage?: TMessage
|
|
40
|
+
previousMessage?: TMessage
|
|
41
|
+
user: User
|
|
42
|
+
inverted?: boolean
|
|
43
|
+
containerStyle?: LeftRightStyle<ViewStyle>
|
|
44
|
+
renderBubble?(props: Bubble['props']): React.ReactNode
|
|
45
|
+
renderDay?(props: DayProps<TMessage>): React.ReactNode
|
|
46
|
+
renderSystemMessage?(props: SystemMessageProps<TMessage>): React.ReactNode
|
|
47
|
+
renderAvatar?(props: AvatarProps<TMessage>): React.ReactNode
|
|
48
|
+
shouldUpdateMessage?(
|
|
49
|
+
props: MessageProps<IMessage>,
|
|
50
|
+
nextProps: MessageProps<IMessage>,
|
|
51
|
+
): boolean
|
|
52
|
+
onMessageLayout?(event: LayoutChangeEvent): void
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default class Message<
|
|
56
|
+
TMessage extends IMessage = IMessage,
|
|
57
|
+
> extends React.Component<MessageProps<TMessage>> {
|
|
58
|
+
static defaultProps = {
|
|
59
|
+
renderAvatar: undefined,
|
|
60
|
+
renderBubble: null,
|
|
61
|
+
renderDay: null,
|
|
62
|
+
renderSystemMessage: null,
|
|
63
|
+
position: 'left',
|
|
64
|
+
currentMessage: {},
|
|
65
|
+
nextMessage: {},
|
|
66
|
+
previousMessage: {},
|
|
67
|
+
user: {},
|
|
68
|
+
containerStyle: {},
|
|
69
|
+
showUserAvatar: false,
|
|
70
|
+
inverted: true,
|
|
71
|
+
shouldUpdateMessage: undefined,
|
|
72
|
+
onMessageLayout: undefined,
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static propTypes = {
|
|
76
|
+
renderAvatar: PropTypes.func,
|
|
77
|
+
showUserAvatar: PropTypes.bool,
|
|
78
|
+
renderBubble: PropTypes.func,
|
|
79
|
+
renderDay: PropTypes.func,
|
|
80
|
+
renderSystemMessage: PropTypes.func,
|
|
81
|
+
position: PropTypes.oneOf(['left', 'right']),
|
|
82
|
+
currentMessage: PropTypes.object,
|
|
83
|
+
nextMessage: PropTypes.object,
|
|
84
|
+
previousMessage: PropTypes.object,
|
|
85
|
+
user: PropTypes.object,
|
|
86
|
+
inverted: PropTypes.bool,
|
|
87
|
+
containerStyle: PropTypes.shape({
|
|
88
|
+
left: StylePropType,
|
|
89
|
+
right: StylePropType,
|
|
90
|
+
}),
|
|
91
|
+
shouldUpdateMessage: PropTypes.func,
|
|
92
|
+
onMessageLayout: PropTypes.func,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
shouldComponentUpdate (nextProps: MessageProps<TMessage>) {
|
|
96
|
+
const next = nextProps.currentMessage!
|
|
97
|
+
const current = this.props.currentMessage!
|
|
98
|
+
const { previousMessage, nextMessage } = this.props
|
|
99
|
+
const nextPropsMessage = nextProps.nextMessage
|
|
100
|
+
const nextPropsPreviousMessage = nextProps.previousMessage
|
|
101
|
+
|
|
102
|
+
let shouldUpdate =
|
|
103
|
+
this.props.shouldUpdateMessage?.(this.props, nextProps) || false
|
|
104
|
+
|
|
105
|
+
shouldUpdate =
|
|
106
|
+
shouldUpdate ||
|
|
107
|
+
!isEqual(current, next) ||
|
|
108
|
+
!isEqual(previousMessage, nextPropsPreviousMessage) ||
|
|
109
|
+
!isEqual(nextMessage, nextPropsMessage)
|
|
110
|
+
|
|
111
|
+
return shouldUpdate
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
renderDay () {
|
|
115
|
+
if (this.props.currentMessage && this.props.currentMessage.createdAt) {
|
|
116
|
+
const {
|
|
117
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
118
|
+
containerStyle,
|
|
119
|
+
onMessageLayout,
|
|
120
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
121
|
+
...props
|
|
122
|
+
} = this.props
|
|
123
|
+
|
|
124
|
+
if (this.props.renderDay)
|
|
125
|
+
return this.props.renderDay(props)
|
|
126
|
+
|
|
127
|
+
return <Day {...props} />
|
|
128
|
+
}
|
|
129
|
+
return null
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
renderBubble () {
|
|
133
|
+
const {
|
|
134
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
135
|
+
containerStyle,
|
|
136
|
+
onMessageLayout,
|
|
137
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
138
|
+
...props
|
|
139
|
+
} = this.props
|
|
140
|
+
|
|
141
|
+
if (this.props.renderBubble)
|
|
142
|
+
return this.props.renderBubble(props)
|
|
143
|
+
|
|
144
|
+
return <Bubble {...props} />
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
renderSystemMessage () {
|
|
148
|
+
const {
|
|
149
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
150
|
+
containerStyle,
|
|
151
|
+
onMessageLayout,
|
|
152
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
153
|
+
...props
|
|
154
|
+
} = this.props
|
|
155
|
+
|
|
156
|
+
if (this.props.renderSystemMessage)
|
|
157
|
+
return this.props.renderSystemMessage(props)
|
|
158
|
+
|
|
159
|
+
return <SystemMessage {...props} />
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
renderAvatar () {
|
|
163
|
+
const { user, currentMessage, showUserAvatar } = this.props
|
|
164
|
+
|
|
165
|
+
if (
|
|
166
|
+
user &&
|
|
167
|
+
user._id &&
|
|
168
|
+
currentMessage &&
|
|
169
|
+
currentMessage.user &&
|
|
170
|
+
user._id === currentMessage.user._id &&
|
|
171
|
+
!showUserAvatar
|
|
172
|
+
)
|
|
173
|
+
return null
|
|
174
|
+
|
|
175
|
+
if (
|
|
176
|
+
currentMessage &&
|
|
177
|
+
currentMessage.user &&
|
|
178
|
+
currentMessage.user.avatar === null
|
|
179
|
+
)
|
|
180
|
+
return null
|
|
181
|
+
|
|
182
|
+
const {
|
|
183
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
184
|
+
containerStyle,
|
|
185
|
+
onMessageLayout,
|
|
186
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
187
|
+
...props
|
|
188
|
+
} = this.props
|
|
189
|
+
|
|
190
|
+
return <Avatar {...props} />
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
render () {
|
|
194
|
+
const {
|
|
195
|
+
currentMessage,
|
|
196
|
+
onMessageLayout,
|
|
197
|
+
nextMessage,
|
|
198
|
+
position,
|
|
199
|
+
containerStyle,
|
|
200
|
+
} = this.props
|
|
201
|
+
if (currentMessage) {
|
|
202
|
+
const sameUser = isSameUser(currentMessage, nextMessage!)
|
|
203
|
+
return (
|
|
204
|
+
<View onLayout={onMessageLayout}>
|
|
205
|
+
{this.renderDay()}
|
|
206
|
+
{currentMessage.system
|
|
207
|
+
? (
|
|
208
|
+
this.renderSystemMessage()
|
|
209
|
+
)
|
|
210
|
+
: (
|
|
211
|
+
<View
|
|
212
|
+
style={[
|
|
213
|
+
styles[position].container,
|
|
214
|
+
{ marginBottom: sameUser ? 2 : 10 },
|
|
215
|
+
!this.props.inverted && { marginBottom: 2 },
|
|
216
|
+
containerStyle && containerStyle[position],
|
|
217
|
+
]}
|
|
218
|
+
>
|
|
219
|
+
{this.props.position === 'left' ? this.renderAvatar() : null}
|
|
220
|
+
{this.renderBubble()}
|
|
221
|
+
{this.props.position === 'right' ? this.renderAvatar() : null}
|
|
222
|
+
</View>
|
|
223
|
+
)}
|
|
224
|
+
</View>
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
return null
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import Color from './Color'
|
|
3
|
+
import { View, Text } from 'react-native'
|
|
4
|
+
|
|
5
|
+
export function MessageAudio () {
|
|
6
|
+
return (
|
|
7
|
+
<View style={{ padding: 20 }}>
|
|
8
|
+
<Text style={{ color: Color.alizarin, fontWeight: '600' }}>
|
|
9
|
+
{'Audio is not implemented by GiftedChat.'}
|
|
10
|
+
</Text>
|
|
11
|
+
<Text style={{ color: Color.alizarin, fontWeight: '600' }}>
|
|
12
|
+
{
|
|
13
|
+
'You need to provide your own implementation by using renderMessageAudio'
|
|
14
|
+
}
|
|
15
|
+
{'prop.'}
|
|
16
|
+
</Text>
|
|
17
|
+
</View>
|
|
18
|
+
)
|
|
19
|
+
}
|