react-native-gifted-chat 0.16.1 → 1.0.0-beta-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 (70) hide show
  1. package/README.md +69 -50
  2. package/lib/Actions.d.ts +13 -11
  3. package/lib/Actions.js +28 -34
  4. package/lib/Actions.js.map +1 -1
  5. package/lib/Avatar.d.ts +7 -7
  6. package/lib/Avatar.js +35 -40
  7. package/lib/Avatar.js.map +1 -1
  8. package/lib/Bubble.d.ts +11 -8
  9. package/lib/Bubble.js +13 -7
  10. package/lib/Bubble.js.map +1 -1
  11. package/lib/Composer.d.ts +5 -11
  12. package/lib/Composer.js +34 -40
  13. package/lib/Composer.js.map +1 -1
  14. package/lib/Day.d.ts +7 -10
  15. package/lib/Day.js +15 -19
  16. package/lib/Day.js.map +1 -1
  17. package/lib/GiftedAvatar.js +3 -3
  18. package/lib/GiftedAvatar.js.map +1 -1
  19. package/lib/GiftedChat.d.ts +47 -38
  20. package/lib/GiftedChat.js +61 -36
  21. package/lib/GiftedChat.js.flow +8 -0
  22. package/lib/GiftedChat.js.map +1 -1
  23. package/lib/GiftedChatContext.d.ts +9 -0
  24. package/lib/GiftedChatContext.js +9 -0
  25. package/lib/GiftedChatContext.js.map +1 -0
  26. package/lib/InputToolbar.d.ts +14 -28
  27. package/lib/InputToolbar.js +27 -83
  28. package/lib/InputToolbar.js.map +1 -1
  29. package/lib/LoadEarlier.d.ts +4 -5
  30. package/lib/LoadEarlier.js +12 -25
  31. package/lib/LoadEarlier.js.map +1 -1
  32. package/lib/Message.d.ts +10 -7
  33. package/lib/Message.js +11 -9
  34. package/lib/Message.js.map +1 -1
  35. package/lib/MessageAudio.d.ts +1 -3
  36. package/lib/MessageAudio.js +11 -9
  37. package/lib/MessageAudio.js.map +1 -1
  38. package/lib/MessageContainer.d.ts +3 -8
  39. package/lib/MessageContainer.js +3 -41
  40. package/lib/MessageContainer.js.map +1 -1
  41. package/lib/MessageImage.d.ts +4 -5
  42. package/lib/MessageImage.js +12 -15
  43. package/lib/MessageImage.js.map +1 -1
  44. package/lib/MessageText.d.ts +5 -13
  45. package/lib/MessageText.js +79 -82
  46. package/lib/MessageText.js.map +1 -1
  47. package/lib/MessageVideo.d.ts +1 -3
  48. package/lib/MessageVideo.js +11 -9
  49. package/lib/MessageVideo.js.map +1 -1
  50. package/lib/Models.d.ts +3 -4
  51. package/lib/Models.js +1 -0
  52. package/lib/QuickReplies.d.ts +5 -15
  53. package/lib/QuickReplies.js +67 -87
  54. package/lib/QuickReplies.js.map +1 -1
  55. package/lib/Send.d.ts +6 -7
  56. package/lib/Send.js +16 -21
  57. package/lib/Send.js.map +1 -1
  58. package/lib/SystemMessage.d.ts +4 -5
  59. package/lib/SystemMessage.js +10 -12
  60. package/lib/SystemMessage.js.map +1 -1
  61. package/lib/Time.d.ts +5 -9
  62. package/lib/Time.js +33 -33
  63. package/lib/Time.js.map +1 -1
  64. package/lib/TypingIndicator.d.ts +0 -1
  65. package/lib/TypingIndicator.js +1 -6
  66. package/lib/TypingIndicator.js.map +1 -1
  67. package/lib/hooks/useUpdateLayoutEffect.d.ts +3 -2
  68. package/lib/hooks/useUpdateLayoutEffect.js +1 -1
  69. package/lib/hooks/useUpdateLayoutEffect.js.map +1 -1
  70. package/package.json +28 -23
package/README.md CHANGED
@@ -16,7 +16,6 @@
16
16
  <a href="https://www.npmjs.com/package/react-native-gifted-chat">
17
17
  <img alt="npm downloads" src="https://img.shields.io/npm/dm/react-native-gifted-chat.svg"/></a>
18
18
  <a href="https://www.npmjs.com/package/react-native-gifted-chat"><img alt="npm version" src="https://badge.fury.io/js/react-native-gifted-chat.svg"/></a>
19
- <a href="https://greenkeeper.io/"><img src="https://badges.greenkeeper.io/FaridSafi/react-native-gifted-chat.svg" alt="build"></a>
20
19
  <a href="https://reactnative.gallery/FaridSafi/gifted-chat"><img src="https://img.shields.io/badge/reactnative.gallery-%F0%9F%8E%AC-green.svg"/></a>
21
20
 
22
21
  </p>
@@ -81,11 +80,12 @@
81
80
  </p>
82
81
  </p>
83
82
 
83
+ ## The future of GiftedChat 🎉
84
+ Please give us your advice: [Related PR](https://github.com/FaridSafi/react-native-gifted-chat/pull/1775)
85
+
84
86
  ## Please vote
85
87
 
86
88
  **GiftedChat** depends on other packages and some needs a boost, please vote for PRs will improve it, thanks:
87
-
88
- - https://github.com/taskrabbit/react-native-parsed-text/pull/58
89
89
  - https://github.com/watadarkstar/react-native-typing-animation/issues/18
90
90
 
91
91
  ## Features
@@ -132,48 +132,40 @@
132
132
  ## Example
133
133
 
134
134
  ```jsx
135
- import React from 'react'
135
+ import React, { useState, useCallback, useEffect } from 'react'
136
136
  import { GiftedChat } from 'react-native-gifted-chat'
137
137
 
138
- class Example extends React.Component {
139
- state = {
140
- messages: [],
141
- }
142
-
143
- componentDidMount() {
144
- this.setState({
145
- messages: [
146
- {
147
- _id: 1,
148
- text: 'Hello developer',
149
- createdAt: new Date(),
150
- user: {
151
- _id: 2,
152
- name: 'React Native',
153
- avatar: 'https://placeimg.com/140/140/any',
154
- },
138
+ export function Example() {
139
+ const [messages, setMessages] = useState([]);
140
+
141
+ useEffect(() => {
142
+ setMessages([
143
+ {
144
+ _id: 1,
145
+ text: 'Hello developer',
146
+ createdAt: new Date(),
147
+ user: {
148
+ _id: 2,
149
+ name: 'React Native',
150
+ avatar: 'https://placeimg.com/140/140/any',
155
151
  },
156
- ],
157
- })
158
- }
159
-
160
- onSend(messages = []) {
161
- this.setState(previousState => ({
162
- messages: GiftedChat.append(previousState.messages, messages),
163
- }))
164
- }
165
-
166
- render() {
167
- return (
168
- <GiftedChat
169
- messages={this.state.messages}
170
- onSend={messages => this.onSend(messages)}
171
- user={{
172
- _id: 1,
173
- }}
174
- />
175
- )
176
- }
152
+ },
153
+ ])
154
+ }, [])
155
+
156
+ const onSend = useCallback((messages = []) => {
157
+ setMessages(previousMessages => GiftedChat.append(previousMessages, messages))
158
+ }, [])
159
+
160
+ return (
161
+ <GiftedChat
162
+ messages={messages}
163
+ onSend={messages => onSend(messages)}
164
+ user={{
165
+ _id: 1,
166
+ }}
167
+ />
168
+ )
177
169
  }
178
170
  ```
179
171
 
@@ -189,6 +181,23 @@ See the files in [`example-slack-message`](example-slack-message) for an example
189
181
 
190
182
  > e.g. Chat Message
191
183
 
184
+ ```ts
185
+ export interface IMessage {
186
+ _id: string | number
187
+ text: string
188
+ createdAt: Date | number
189
+ user: User
190
+ image?: string
191
+ video?: string
192
+ audio?: string
193
+ system?: boolean
194
+ sent?: boolean
195
+ received?: boolean
196
+ pending?: boolean
197
+ quickReplies?: QuickReplies
198
+ }
199
+ ```
200
+
192
201
  ```js
193
202
  {
194
203
  _id: 1,
@@ -202,6 +211,12 @@ See the files in [`example-slack-message`](example-slack-message) for an example
202
211
  image: 'https://facebook.github.io/react/img/logo_og.png',
203
212
  // You can also add a video prop:
204
213
  video: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4',
214
+ // Mark the message as sent, using one tick
215
+ sent: true,
216
+ // Mark the message as received, using two tick
217
+ received: true,
218
+ // Mark the message as pending with a clock loader
219
+ pending: true,
205
220
  // Any additional custom parameters are passed through
206
221
  }
207
222
  ```
@@ -305,7 +320,7 @@ interface QuickReplies {
305
320
  - **`locale`** _(String)_ - Locale to localize the dates. You need first to import the locale you need (ie. `require('dayjs/locale/de')` or `import 'dayjs/locale/fr'`)
306
321
  - **`timeFormat`** _(String)_ - Format to use for rendering times; default is `'LT'`
307
322
  - **`dateFormat`** _(String)_ - Format to use for rendering dates; default is `'ll'`
308
- - **`loadEarlier`** _(Bool)_ - Enables the "load earlier messages" button
323
+ - **`loadEarlier`** _(Bool)_ - Enables the "load earlier messages" button, required for `infiniteScroll`
309
324
  - **`isKeyboardInternallyHandled`** _(Bool)_ - Determine whether to handle keyboard awareness inside the plugin. If you have your own keyboard handling outside the plugin set this to false; default is `true`
310
325
  - **`onLoadEarlier`** _(Function)_ - Callback when loading earlier messages
311
326
  - **`isLoadingEarlier`** _(Bool)_ - Display an `ActivityIndicator` when loading earlier messages
@@ -318,7 +333,9 @@ interface QuickReplies {
318
333
  - **`onLongPressAvatar`** _(Function(`user`))_ - Callback when a message avatar is long-pressed
319
334
  - **`renderAvatarOnTop`** _(Bool)_ - Render the message avatar at the top of consecutive messages, rather than the bottom; default is `false`
320
335
  - **`renderBubble`** _(Function)_ - Custom message bubble
336
+ - **`renderTicks`** _(Function(`message`))_ - Custom ticks indicator to display message status
321
337
  - **`renderSystemMessage`** _(Function)_ - Custom system message
338
+ - **`onPress`** _(Function(`context`, `message`))_ - Callback when a message bubble is pressed
322
339
  - **`onLongPress`** _(Function(`context`, `message`))_ - Callback when a message bubble is long-pressed; default is to show an ActionSheet with "Copy Text" (see [example using `showActionSheetWithOptions()`](https://github.com/FaridSafi/react-native-gifted-chat/blob/master@%7B2017-09-25%7D/src/Bubble.js#L96-L119))
323
340
  - **`inverted`** _(Bool)_ - Reverses display order of `messages`; default is `true`
324
341
  - **`renderUsernameOnMessage`** _(Bool)_ - Indicate whether to show the user's username inside the message bubble; default is `false`
@@ -333,7 +350,7 @@ interface QuickReplies {
333
350
  - **`renderCustomView`** _(Function)_ - Custom view inside the bubble
334
351
  - **`renderDay`** _(Function)_ - Custom day above a message
335
352
  - **`renderTime`** _(Function)_ - Custom time inside a message
336
- - **`renderFooter`** _(Function)_ - Custom footer component on the ListView, e.g. `'User is typing...'`; see [example/App.js](example/App.js) for an example. Overrides default typing indicator that triggers when `isTyping` is true.
353
+ - **`renderFooter`** _(Function)_ - Custom footer component on the ListView, e.g. `'User is typing...'`; see [App.tsx](/App.tsx) for an example. Overrides default typing indicator that triggers when `isTyping` is true.
337
354
  - **`renderChatEmpty`** _(Function)_ - Custom component to render in the ListView when messages are empty
338
355
  - **`renderChatFooter`** _(Function)_ - Custom component to render below the MessageContainer (separate from the ListView)
339
356
  - **`renderInputToolbar`** _(Function)_ - Custom message composer container
@@ -376,7 +393,7 @@ interface QuickReplies {
376
393
  * **`quickReplyStyle`** _(StyleProp<ViewStyle>)_ - Custom quick reply view style
377
394
  * **`renderQuickReplySend`** _(Function)_ - Custom quick reply **send** view
378
395
  * **`shouldUpdateMessage`** _(Function)_ - Lets the message component know when to update outside of normal cases.
379
- * **`infiniteScroll`** _(Bool)_ - infinite scroll up when reach the top of messages container, automatically call onLoadEarlier function if exist (not yet supported for the web)
396
+ * **`infiniteScroll`** _(Bool)_ - infinite scroll up when reach the top of messages container, automatically call onLoadEarlier function if exist (not yet supported for the web). You need to add `loadEarlier` prop too.
380
397
 
381
398
  ## Imperative methods
382
399
 
@@ -435,15 +452,17 @@ If you use React Navigation, additional handling may be required to account for
435
452
 
436
453
  ### Native
437
454
 
438
- 1. Install `yarn add -g expo-cli`
439
- 2. `expo start`
455
+ 1. Install `yarn global add expo-cli`
456
+ 2. Install dependencies`yarn install`
457
+ 3. `expo start`
440
458
 
441
459
  ### react-native-web
442
460
 
443
461
  #### With expo
444
462
 
445
- 1. Install `yarn add -g expo-cli`
446
- 2. `expo start -w`
463
+ 1. Install `yarn global add expo-cli`
464
+ 2. Install dependencies`yarn install`
465
+ 3. `expo start -w`
447
466
 
448
467
  [Upgrade snack version](https://snackager.expo.io/bundle/react-native-gifted-chat@0.15.0?bypassCache=true)
449
468
 
@@ -509,4 +528,4 @@ Feel free to ask me questions on Twitter [@FaridSafi](https://www.twitter.com/Fa
509
528
 
510
529
  ## Hire an expert!
511
530
 
512
- Looking for a ReactNative freelance expert with more than 12 years of experience? Contact Xavier from his [website](https://xaviercarpentier.com)!
531
+ Looking for a ReactNative freelance expert with more than 14 years of experience? Contact Xavier from his [website](https://xaviercarpentier.com)!
package/lib/Actions.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import PropTypes from 'prop-types';
2
- import React, { ReactNode } from 'react';
2
+ import { ReactNode } from 'react';
3
3
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
4
4
  export interface ActionsProps {
5
5
  options?: {
@@ -12,9 +12,17 @@ export interface ActionsProps {
12
12
  containerStyle?: StyleProp<ViewStyle>;
13
13
  onPressActionButton?(): void;
14
14
  }
15
- export default class Actions extends React.Component<ActionsProps> {
16
- static defaultProps: ActionsProps;
17
- static propTypes: {
15
+ export declare const Actions: {
16
+ ({ options, optionTintColor, icon, wrapperStyle, iconTextStyle, onPressActionButton, containerStyle, }: ActionsProps): JSX.Element;
17
+ defaultProps: {
18
+ options: {};
19
+ optionTintColor: string;
20
+ icon: undefined;
21
+ containerStyle: {};
22
+ iconTextStyle: {};
23
+ wrapperStyle: {};
24
+ };
25
+ propTypes: {
18
26
  onSend: PropTypes.Requireable<(...args: any[]) => any>;
19
27
  options: PropTypes.Requireable<object>;
20
28
  optionTintColor: PropTypes.Requireable<string>;
@@ -23,10 +31,4 @@ export default class Actions extends React.Component<ActionsProps> {
23
31
  wrapperStyle: PropTypes.Requireable<number | boolean | object>;
24
32
  containerStyle: PropTypes.Requireable<number | boolean | object>;
25
33
  };
26
- static contextTypes: {
27
- actionSheet: PropTypes.Requireable<(...args: any[]) => any>;
28
- };
29
- onActionsPress: () => void;
30
- renderIcon(): {} | null | undefined;
31
- render(): JSX.Element;
32
- }
34
+ };
package/lib/Actions.js CHANGED
@@ -3,39 +3,36 @@ import React from 'react';
3
3
  import { StyleSheet, Text, TouchableOpacity, View, } from 'react-native';
4
4
  import Color from './Color';
5
5
  import { StylePropType } from './utils';
6
- export default class Actions extends React.Component {
7
- constructor() {
8
- super(...arguments);
9
- this.onActionsPress = () => {
10
- const { options } = this.props;
11
- const optionKeys = Object.keys(options);
12
- const cancelButtonIndex = optionKeys.indexOf('Cancel');
13
- this.context.actionSheet().showActionSheetWithOptions({
14
- options: optionKeys,
15
- cancelButtonIndex,
16
- tintColor: this.props.optionTintColor,
17
- }, (buttonIndex) => {
18
- const key = optionKeys[buttonIndex];
19
- if (key) {
20
- options[key](this.props);
21
- }
22
- });
23
- };
24
- }
25
- renderIcon() {
26
- if (this.props.icon) {
27
- return this.props.icon();
6
+ import { useChatContext } from './GiftedChatContext';
7
+ import { useCallbackOne } from 'use-memo-one';
8
+ export const Actions = ({ options, optionTintColor, icon, wrapperStyle, iconTextStyle, onPressActionButton, containerStyle, }) => {
9
+ const { actionSheet } = useChatContext();
10
+ const onActionsPress = useCallbackOne(() => {
11
+ const optionKeys = Object.keys(options);
12
+ const cancelButtonIndex = optionKeys.indexOf('Cancel');
13
+ actionSheet().showActionSheetWithOptions({
14
+ options: optionKeys,
15
+ cancelButtonIndex,
16
+ tintColor: optionTintColor,
17
+ }, (buttonIndex) => {
18
+ const key = optionKeys[buttonIndex];
19
+ if (key) {
20
+ options[key]();
21
+ }
22
+ });
23
+ }, []);
24
+ const renderIcon = useCallbackOne(() => {
25
+ if (icon) {
26
+ return icon();
28
27
  }
29
- return (<View style={[styles.wrapper, this.props.wrapperStyle]}>
30
- <Text style={[styles.iconText, this.props.iconTextStyle]}>+</Text>
28
+ return (<View style={[styles.wrapper, wrapperStyle]}>
29
+ <Text style={[styles.iconText, iconTextStyle]}>+</Text>
31
30
  </View>);
32
- }
33
- render() {
34
- return (<TouchableOpacity style={[styles.container, this.props.containerStyle]} onPress={this.props.onPressActionButton || this.onActionsPress}>
35
- {this.renderIcon()}
36
- </TouchableOpacity>);
37
- }
38
- }
31
+ }, []);
32
+ return (<TouchableOpacity style={[styles.container, containerStyle]} onPress={onPressActionButton || onActionsPress}>
33
+ {renderIcon()}
34
+ </TouchableOpacity>);
35
+ };
39
36
  Actions.defaultProps = {
40
37
  options: {},
41
38
  optionTintColor: Color.optionTintColor,
@@ -53,9 +50,6 @@ Actions.propTypes = {
53
50
  wrapperStyle: StylePropType,
54
51
  containerStyle: StylePropType,
55
52
  };
56
- Actions.contextTypes = {
57
- actionSheet: PropTypes.func,
58
- };
59
53
  const styles = StyleSheet.create({
60
54
  container: {
61
55
  width: 26,
@@ -1 +1 @@
1
- {"version":3,"file":"Actions.js","sourceRoot":"","sources":["../src/Actions.tsx"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,C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AAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,SAAS,EAAE;QACT,KAAK,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,EAAE;QACd,YAAY,EAAE,EAAE;KACjB;IACD,OAAO,EAAE;QACP,YAAY,EAAE,EAAE;QAChB,WAAW,EAAE,KAAK,CAAC,YAAY;QAC/B,WAAW,EAAE,CAAC;QACd,IAAI,EAAE,CAAC;KACR;IACD,QAAQ,EAAE;QACR,KAAK,EAAE,KAAK,CAAC,YAAY;QACzB,UAAU,EAAE,MAAM;QAClB,QAAQ,EAAE,EAAE;QACZ,eAAe,EAAE,KAAK,CAAC,qBAAqB;QAC5C,SAAS,EAAE,QAAQ;KACpB;CACF,CAAC,CAAA"}
package/lib/Avatar.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import PropTypes from 'prop-types';
2
- import React, { ReactNode } from 'react';
3
- import { ImageStyle, ViewStyle } from 'react-native';
2
+ import { ReactNode } from 'react';
3
+ import { ImageStyle, TextStyle, ViewStyle } from 'react-native';
4
4
  import { Omit, IMessage, User, LeftRightStyle } from './Models';
5
5
  export interface AvatarProps<TMessage extends IMessage> {
6
6
  currentMessage?: TMessage;
@@ -11,12 +11,14 @@ export interface AvatarProps<TMessage extends IMessage> {
11
11
  showAvatarForEveryMessage?: boolean;
12
12
  imageStyle?: LeftRightStyle<ImageStyle>;
13
13
  containerStyle?: LeftRightStyle<ViewStyle>;
14
+ textStyle?: TextStyle;
14
15
  renderAvatar?(props: Omit<AvatarProps<TMessage>, 'renderAvatar'>): ReactNode;
15
16
  onPressAvatar?(user: User): void;
16
17
  onLongPressAvatar?(user: User): void;
17
18
  }
18
- export default class Avatar<TMessage extends IMessage = IMessage> extends React.Component<AvatarProps<TMessage>> {
19
- static defaultProps: {
19
+ export declare function Avatar<TMessage extends IMessage = IMessage>(props: AvatarProps<TMessage>): JSX.Element | null;
20
+ export declare namespace Avatar {
21
+ var defaultProps: {
20
22
  renderAvatarOnTop: boolean;
21
23
  showAvatarForEveryMessage: boolean;
22
24
  position: string;
@@ -30,7 +32,7 @@ export default class Avatar<TMessage extends IMessage = IMessage> extends React.
30
32
  onPressAvatar: () => void;
31
33
  onLongPressAvatar: () => void;
32
34
  };
33
- static propTypes: {
35
+ var propTypes: {
34
36
  renderAvatarOnTop: PropTypes.Requireable<boolean>;
35
37
  showAvatarForEveryMessage: PropTypes.Requireable<boolean>;
36
38
  position: PropTypes.Requireable<string>;
@@ -49,6 +51,4 @@ export default class Avatar<TMessage extends IMessage = IMessage> extends React.
49
51
  right: PropTypes.Requireable<number | boolean | object>;
50
52
  }>>;
51
53
  };
52
- renderAvatar(): {} | null | undefined;
53
- render(): JSX.Element | null;
54
54
  }
package/lib/Avatar.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import React from 'react';
3
- import { StyleSheet, View } from 'react-native';
3
+ import { StyleSheet, View, } from 'react-native';
4
4
  import GiftedAvatar from './GiftedAvatar';
5
5
  import { StylePropType, isSameUser, isSameDay } from './utils';
6
6
  const styles = {
@@ -33,53 +33,48 @@ const styles = {
33
33
  },
34
34
  }),
35
35
  };
36
- export default class Avatar extends React.Component {
37
- renderAvatar() {
38
- if (this.props.renderAvatar) {
39
- const { renderAvatar, ...avatarProps } = this.props;
40
- return this.props.renderAvatar(avatarProps);
41
- }
42
- if (this.props.currentMessage) {
43
- return (<GiftedAvatar avatarStyle={[
44
- styles[this.props.position].image,
45
- this.props.imageStyle &&
46
- this.props.imageStyle[this.props.position],
47
- ]} user={this.props.currentMessage.user} onPress={() => this.props.onPressAvatar &&
48
- this.props.onPressAvatar(this.props.currentMessage.user)} onLongPress={() => this.props.onLongPressAvatar &&
49
- this.props.onLongPressAvatar(this.props.currentMessage.user)}/>);
50
- }
36
+ export function Avatar(props) {
37
+ const { renderAvatarOnTop, showAvatarForEveryMessage, containerStyle, position, currentMessage, renderAvatar, previousMessage, nextMessage, imageStyle, } = props;
38
+ const messageToCompare = renderAvatarOnTop ? previousMessage : nextMessage;
39
+ const computedStyle = renderAvatarOnTop ? 'onTop' : 'onBottom';
40
+ if (renderAvatar === null) {
51
41
  return null;
52
42
  }
53
- render() {
54
- const { renderAvatarOnTop, showAvatarForEveryMessage, containerStyle, position, currentMessage, renderAvatar, previousMessage, nextMessage, imageStyle, } = this.props;
55
- const messageToCompare = renderAvatarOnTop ? previousMessage : nextMessage;
56
- const computedStyle = renderAvatarOnTop ? 'onTop' : 'onBottom';
57
- if (renderAvatar === null) {
58
- return null;
59
- }
60
- if (!showAvatarForEveryMessage &&
61
- currentMessage &&
62
- messageToCompare &&
63
- isSameUser(currentMessage, messageToCompare) &&
64
- isSameDay(currentMessage, messageToCompare)) {
65
- return (<View style={[
66
- styles[position].container,
67
- containerStyle && containerStyle[position],
68
- ]}>
69
- <GiftedAvatar avatarStyle={[
70
- styles[position].image,
71
- imageStyle && imageStyle[position],
72
- ]}/>
73
- </View>);
74
- }
43
+ if (!showAvatarForEveryMessage &&
44
+ currentMessage &&
45
+ messageToCompare &&
46
+ isSameUser(currentMessage, messageToCompare) &&
47
+ isSameDay(currentMessage, messageToCompare)) {
75
48
  return (<View style={[
76
49
  styles[position].container,
77
- styles[position][computedStyle],
78
50
  containerStyle && containerStyle[position],
79
51
  ]}>
80
- {this.renderAvatar()}
52
+ <GiftedAvatar avatarStyle={[
53
+ styles[position].image,
54
+ imageStyle && imageStyle[position],
55
+ ]}/>
81
56
  </View>);
82
57
  }
58
+ const renderAvatarComponent = () => {
59
+ if (props.renderAvatar) {
60
+ const { renderAvatar, ...avatarProps } = props;
61
+ return props.renderAvatar(avatarProps);
62
+ }
63
+ if (props.currentMessage) {
64
+ return (<GiftedAvatar avatarStyle={[
65
+ styles[props.position].image,
66
+ props.imageStyle && props.imageStyle[props.position],
67
+ ]} user={props.currentMessage.user} onPress={() => { var _a; return (_a = props.onPressAvatar) === null || _a === void 0 ? void 0 : _a.call(props, props.currentMessage.user); }} onLongPress={() => { var _a; return (_a = props.onLongPressAvatar) === null || _a === void 0 ? void 0 : _a.call(props, props.currentMessage.user); }}/>);
68
+ }
69
+ return null;
70
+ };
71
+ return (<View style={[
72
+ styles[position].container,
73
+ styles[position][computedStyle],
74
+ containerStyle && containerStyle[position],
75
+ ]}>
76
+ {renderAvatarComponent()}
77
+ </View>);
83
78
  }
84
79
  Avatar.defaultProps = {
85
80
  renderAvatarOnTop: false,
package/lib/Avatar.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../src/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,KAAoB,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAyB,MAAM,cAAc,CAAA;AACtE,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAG9D,MAAM,MAAM,GAAG;IACb,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;QACtB,SAAS,EAAE;YACT,WAAW,EAAE,CAAC;SACf;QACD,KAAK,EAAE;YACL,SAAS,EAAE,YAAY;SACxB;QACD,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE;YACL,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,YAAY,EAAE,EAAE;SACjB;KACF,CAAC;IACF,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE;YACT,UAAU,EAAE,CAAC;SACd;QACD,KAAK,EAAE;YACL,SAAS,EAAE,YAAY;SACxB;QACD,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE;YACL,MAAM,EAAE,EAAE;YACV,KAAK,EAAE,EAAE;YACT,YAAY,EAAE,EAAE;SACjB;KACF,CAAC;CACH,CAAA;AAgBD,MAAM,CAAC,OAAO,OAAO,MAEnB,SAAQ,KAAK,CAAC,SAAgC;IAoC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D,eAAe,EAAE,EAAE;IACnB,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,EAAE;IAClB,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;IACvB,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;CAC5B,CAAA;AAED,MAAM,CAAC,SAAS,GAAG;IACjB,iBAAiB,EAAE,SAAS,CAAC,IAAI;IACjC,yBAAyB,EAAE,SAAS,CAAC,IAAI;IACzC,QAAQ,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,cAAc,EAAE,SAAS,CAAC,MAAM;IAChC,eAAe,EAAE,SAAS,CAAC,MAAM;IACjC,WAAW,EAAE,SAAS,CAAC,MAAM;IAC7B,aAAa,EAAE,SAAS,CAAC,IAAI;IAC7B,iBAAiB,EAAE,SAAS,CAAC,IAAI;IACjC,YAAY,EAAE,SAAS,CAAC,IAAI;IAC5B,cAAc,EAAE,SAAS,CAAC,KAAK,CAAC;QAC9B,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,aAAa;KACrB,CAAC;IACF,UAAU,EAAE,SAAS,CAAC,KAAK,CAAC;QAC1B,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,aAAa;KACrB,CAAC;CACH,CAAA"}
package/lib/Bubble.d.ts CHANGED
@@ -1,15 +1,15 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import React from 'react';
3
3
  import { StyleProp, ViewStyle, TextStyle } from 'react-native';
4
- import QuickReplies from './QuickReplies';
5
- import MessageText from './MessageText';
6
- import MessageImage from './MessageImage';
7
- import Time from './Time';
4
+ import { QuickRepliesProps } from './QuickReplies';
5
+ import { MessageTextProps } from './MessageText';
6
+ import { MessageImageProps } from './MessageImage';
7
+ import { TimeProps } from './Time';
8
8
  import { User, IMessage, LeftRightStyle, Reply, Omit, MessageVideoProps, MessageAudioProps } from './Models';
9
- export declare type RenderMessageImageProps<TMessage extends IMessage> = Omit<BubbleProps<TMessage>, 'containerStyle' | 'wrapperStyle'> & MessageImage['props'];
9
+ export declare type RenderMessageImageProps<TMessage extends IMessage> = Omit<BubbleProps<TMessage>, 'containerStyle' | 'wrapperStyle'> & MessageImageProps<TMessage>;
10
10
  export declare type RenderMessageVideoProps<TMessage extends IMessage> = Omit<BubbleProps<TMessage>, 'containerStyle' | 'wrapperStyle'> & MessageVideoProps<TMessage>;
11
11
  export declare type RenderMessageAudioProps<TMessage extends IMessage> = Omit<BubbleProps<TMessage>, 'containerStyle' | 'wrapperStyle'> & MessageAudioProps<TMessage>;
12
- export declare type RenderMessageTextProps<TMessage extends IMessage> = Omit<BubbleProps<TMessage>, 'containerStyle' | 'wrapperStyle'> & MessageText['props'];
12
+ export declare type RenderMessageTextProps<TMessage extends IMessage> = Omit<BubbleProps<TMessage>, 'containerStyle' | 'wrapperStyle'> & MessageTextProps<TMessage>;
13
13
  export interface BubbleProps<TMessage extends IMessage> {
14
14
  user?: User;
15
15
  touchableProps?: object;
@@ -30,6 +30,7 @@ export interface BubbleProps<TMessage extends IMessage> {
30
30
  containerToPreviousStyle?: LeftRightStyle<ViewStyle>;
31
31
  usernameStyle?: TextStyle;
32
32
  quickReplyStyle?: StyleProp<ViewStyle>;
33
+ onPress?(context?: any, message?: any): void;
33
34
  onLongPress?(context?: any, message?: any): void;
34
35
  onQuickReply?(replies: Reply[]): void;
35
36
  renderMessageImage?(props: RenderMessageImageProps<TMessage>): React.ReactNode;
@@ -37,11 +38,11 @@ export interface BubbleProps<TMessage extends IMessage> {
37
38
  renderMessageAudio?(props: RenderMessageAudioProps<TMessage>): React.ReactNode;
38
39
  renderMessageText?(props: RenderMessageTextProps<TMessage>): React.ReactNode;
39
40
  renderCustomView?(bubbleProps: BubbleProps<TMessage>): React.ReactNode;
40
- renderTime?(timeProps: Time['props']): React.ReactNode;
41
+ renderTime?(timeProps: TimeProps<TMessage>): React.ReactNode;
41
42
  renderTicks?(currentMessage: TMessage): React.ReactNode;
42
43
  renderUsername?(): React.ReactNode;
43
44
  renderQuickReplySend?(): React.ReactNode;
44
- renderQuickReplies?(quickReplies: QuickReplies['props']): React.ReactNode;
45
+ renderQuickReplies?(quickReplies: QuickRepliesProps): React.ReactNode;
45
46
  }
46
47
  export default class Bubble<TMessage extends IMessage = IMessage> extends React.Component<BubbleProps<TMessage>> {
47
48
  static contextTypes: {
@@ -49,6 +50,7 @@ export default class Bubble<TMessage extends IMessage = IMessage> extends React.
49
50
  };
50
51
  static defaultProps: {
51
52
  touchableProps: {};
53
+ onPress: null;
52
54
  onLongPress: null;
53
55
  renderMessageImage: null;
54
56
  renderMessageVideo: null;
@@ -121,6 +123,7 @@ export default class Bubble<TMessage extends IMessage = IMessage> extends React.
121
123
  right: PropTypes.Requireable<number | boolean | object>;
122
124
  }>>;
123
125
  };
126
+ onPress: () => void;
124
127
  onLongPress: () => void;
125
128
  styledBubbleToNext(): (false | ViewStyle | import("react-native").RegisteredStyle<ViewStyle> | import("react-native").RecursiveArray<false | ViewStyle | import("react-native").RegisteredStyle<ViewStyle> | null | undefined> | {
126
129
  borderBottomLeftRadius: number;
package/lib/Bubble.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import PropTypes from 'prop-types';
2
2
  import React from 'react';
3
3
  import { Text, Clipboard, StyleSheet, TouchableWithoutFeedback, View, } from 'react-native';
4
- import QuickReplies from './QuickReplies';
5
- import MessageText from './MessageText';
6
- import MessageImage from './MessageImage';
7
- import MessageVideo from './MessageVideo';
8
- import MessageAudio from './MessageAudio';
9
- import Time from './Time';
4
+ import { QuickReplies } from './QuickReplies';
5
+ import { MessageText } from './MessageText';
6
+ import { MessageImage } from './MessageImage';
7
+ import { MessageVideo } from './MessageVideo';
8
+ import { MessageAudio } from './MessageAudio';
9
+ import { Time } from './Time';
10
10
  import Color from './Color';
11
11
  import { StylePropType, isSameUser, isSameDay } from './utils';
12
12
  const styles = {
@@ -83,6 +83,11 @@ const DEFAULT_OPTION_TITLES = ['Copy Text', 'Cancel'];
83
83
  export default class Bubble extends React.Component {
84
84
  constructor() {
85
85
  super(...arguments);
86
+ this.onPress = () => {
87
+ if (this.props.onPress) {
88
+ this.props.onPress(this.context, this.props.currentMessage);
89
+ }
90
+ };
86
91
  this.onLongPress = () => {
87
92
  const { currentMessage } = this.props;
88
93
  if (this.props.onLongPress) {
@@ -272,7 +277,7 @@ export default class Bubble extends React.Component {
272
277
  this.styledBubbleToPrevious(),
273
278
  wrapperStyle && wrapperStyle[position],
274
279
  ]}>
275
- <TouchableWithoutFeedback onLongPress={this.onLongPress} accessibilityTraits='text' {...this.props.touchableProps}>
280
+ <TouchableWithoutFeedback onPress={this.onPress} onLongPress={this.onLongPress} accessibilityRole='text' {...this.props.touchableProps}>
276
281
  <View>
277
282
  {this.renderBubbleContent()}
278
283
  <View style={[
@@ -295,6 +300,7 @@ Bubble.contextTypes = {
295
300
  };
296
301
  Bubble.defaultProps = {
297
302
  touchableProps: {},
303
+ onPress: null,
298
304
  onLongPress: null,
299
305
  renderMessageImage: null,
300
306
  renderMessageVideo: null,