stream-chat-react-native-core 4.1.3 → 4.2.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 (46) hide show
  1. package/lib/commonjs/components/Attachment/Attachment.js +16 -10
  2. package/lib/commonjs/components/Attachment/Attachment.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/Giphy.js +61 -40
  4. package/lib/commonjs/components/Attachment/Giphy.js.map +1 -1
  5. package/lib/commonjs/components/Channel/Channel.js +16 -13
  6. package/lib/commonjs/components/Channel/Channel.js.map +1 -1
  7. package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js +2 -0
  8. package/lib/commonjs/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
  9. package/lib/commonjs/components/Message/MessageSimple/MessageContent.js +42 -20
  10. package/lib/commonjs/components/Message/MessageSimple/MessageContent.js.map +1 -1
  11. package/lib/commonjs/contexts/messagesContext/MessagesContext.js +2 -2
  12. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  13. package/lib/commonjs/contexts/themeContext/utils/theme.js +1 -0
  14. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  15. package/lib/commonjs/version.json +1 -1
  16. package/lib/module/components/Attachment/Attachment.js +16 -10
  17. package/lib/module/components/Attachment/Attachment.js.map +1 -1
  18. package/lib/module/components/Attachment/Giphy.js +61 -40
  19. package/lib/module/components/Attachment/Giphy.js.map +1 -1
  20. package/lib/module/components/Channel/Channel.js +16 -13
  21. package/lib/module/components/Channel/Channel.js.map +1 -1
  22. package/lib/module/components/Channel/hooks/useCreateMessagesContext.js +2 -0
  23. package/lib/module/components/Channel/hooks/useCreateMessagesContext.js.map +1 -1
  24. package/lib/module/components/Message/MessageSimple/MessageContent.js +42 -20
  25. package/lib/module/components/Message/MessageSimple/MessageContent.js.map +1 -1
  26. package/lib/module/contexts/messagesContext/MessagesContext.js +2 -2
  27. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  28. package/lib/module/contexts/themeContext/utils/theme.js +1 -0
  29. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  30. package/lib/module/version.json +1 -1
  31. package/lib/typescript/components/Attachment/Attachment.d.ts +2 -2
  32. package/lib/typescript/components/Attachment/Giphy.d.ts +2 -2
  33. package/lib/typescript/components/Channel/Channel.d.ts +2 -2
  34. package/lib/typescript/components/Channel/hooks/useCreateMessagesContext.d.ts +1 -1
  35. package/lib/typescript/contexts/messagesContext/MessagesContext.d.ts +5 -1
  36. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +1 -0
  37. package/package.json +2 -2
  38. package/src/components/Attachment/Attachment.tsx +29 -4
  39. package/src/components/Attachment/Giphy.tsx +55 -22
  40. package/src/components/Attachment/__tests__/Attachment.test.js +41 -0
  41. package/src/components/Channel/Channel.tsx +4 -1
  42. package/src/components/Channel/hooks/useCreateMessagesContext.ts +2 -0
  43. package/src/components/Message/MessageSimple/MessageContent.tsx +20 -13
  44. package/src/contexts/messagesContext/MessagesContext.tsx +5 -2
  45. package/src/contexts/themeContext/utils/theme.ts +1 -0
  46. package/src/version.json +1 -1
@@ -71,6 +71,47 @@ describe('Attachment', () => {
71
71
  });
72
72
  });
73
73
 
74
+ it('"giphy" attachment size should be customisable', async () => {
75
+ const attachment = generateGiphyAttachment();
76
+ attachment.giphy = {
77
+ fixed_height: {
78
+ height: '200',
79
+ url: 'https://media1.giphy.com/media/test/fixed_height.gif',
80
+ width: '375',
81
+ },
82
+ original: {
83
+ height: '256',
84
+ url: 'https://media1.giphy.com/media/test/original.gif',
85
+ width: '480',
86
+ },
87
+ };
88
+ const { getByTestId: getByTestIdFixedHeight } = render(
89
+ getAttachmentComponent({ attachment, giphyVersion: 'fixed_height' }),
90
+ );
91
+ const { getByTestId: getByTestIdOriginal } = render(
92
+ getAttachmentComponent({ attachment, giphyVersion: 'original' }),
93
+ );
94
+ await waitFor(() => {
95
+ const checkImageProps = (imageProps, specificSizedGiphyData) => {
96
+ let imageStyle = imageProps.style;
97
+ if (Array.isArray(imageStyle)) {
98
+ imageStyle = Object.assign({}, ...imageStyle);
99
+ }
100
+ expect(imageStyle.height).toBe(parseFloat(specificSizedGiphyData.height));
101
+ expect(imageStyle.width).toBe(parseFloat(specificSizedGiphyData.width));
102
+ expect(imageProps.source.uri).toBe(specificSizedGiphyData.url);
103
+ };
104
+ checkImageProps(
105
+ getByTestIdFixedHeight('giphy-attachment-image').props,
106
+ attachment.giphy.fixed_height,
107
+ );
108
+ checkImageProps(
109
+ getByTestIdOriginal('giphy-attachment-image').props,
110
+ attachment.giphy.original,
111
+ );
112
+ });
113
+ });
114
+
74
115
  it('should render UrlPreview component if attachment has title_link or og_scrape_url', async () => {
75
116
  const attachment = generateImageAttachment({
76
117
  og_scrape_url: uuidv4(),
@@ -238,6 +238,7 @@ export type ChannelPropsWithContext<
238
238
  | 'formatDate'
239
239
  | 'Gallery'
240
240
  | 'Giphy'
241
+ | 'giphyVersion'
241
242
  | 'handleBlock'
242
243
  | 'handleCopy'
243
244
  | 'handleDelete'
@@ -366,7 +367,7 @@ export type ChannelPropsWithContext<
366
367
  maxMessageLength?: number;
367
368
  messageId?: string;
368
369
  newMessageStateUpdateThrottleInterval?: number;
369
- overrideOwnCapabilities?: OwnCapabilitiesContextValue;
370
+ overrideOwnCapabilities?: Partial<OwnCapabilitiesContextValue>;
370
371
  stateUpdateThrottleInterval?: number;
371
372
  /**
372
373
  * Tells if channel is rendering a thread list
@@ -426,6 +427,7 @@ const ChannelWithContext = <
426
427
  Gallery = GalleryDefault,
427
428
  Giphy = GiphyDefault,
428
429
  giphyEnabled,
430
+ giphyVersion = 'fixed_height',
429
431
  globalUnreadCountLimit = 255,
430
432
  handleBlock,
431
433
  handleCopy,
@@ -1672,6 +1674,7 @@ const ChannelWithContext = <
1672
1674
  formatDate,
1673
1675
  Gallery,
1674
1676
  Giphy,
1677
+ giphyVersion,
1675
1678
  handleBlock,
1676
1679
  handleCopy,
1677
1680
  handleDelete,
@@ -27,6 +27,7 @@ export const useCreateMessagesContext = <
27
27
  formatDate,
28
28
  Gallery,
29
29
  Giphy,
30
+ giphyVersion,
30
31
  handleBlock,
31
32
  handleCopy,
32
33
  handleDelete,
@@ -111,6 +112,7 @@ export const useCreateMessagesContext = <
111
112
  formatDate,
112
113
  Gallery,
113
114
  Giphy,
115
+ giphyVersion,
114
116
  handleBlock,
115
117
  handleCopy,
116
118
  handleDelete,
@@ -185,7 +185,14 @@ const MessageContentWithContext = <
185
185
 
186
186
  const hasThreadReplies = !!message?.reply_count;
187
187
 
188
- const noBorder = (onlyEmojis && !message.quoted_message) || !!otherAttachments.length;
188
+ let noBorder = onlyEmojis && !message.quoted_message;
189
+ if (otherAttachments.length) {
190
+ if (otherAttachments[0].type === 'giphy' && !isMyMessage) {
191
+ noBorder = false;
192
+ } else {
193
+ noBorder = true;
194
+ }
195
+ }
189
196
 
190
197
  const isMessageTypeDeleted = message.type === 'deleted';
191
198
 
@@ -200,18 +207,18 @@ const MessageContentWithContext = <
200
207
  );
201
208
  }
202
209
 
203
- const backgroundColor =
204
- onlyEmojis && !message.quoted_message
205
- ? transparent
206
- : otherAttachments.length
207
- ? otherAttachments[0].type === 'giphy'
208
- ? !message.quoted_message
209
- ? transparent
210
- : grey_gainsboro
211
- : blue_alice
212
- : alignment === 'left' || error
213
- ? white
214
- : grey_gainsboro;
210
+ let backgroundColor = grey_gainsboro;
211
+ if (onlyEmojis && !message.quoted_message) {
212
+ backgroundColor = transparent;
213
+ } else if (otherAttachments.length) {
214
+ if (otherAttachments[0].type === 'giphy') {
215
+ backgroundColor = message.quoted_message || isMyMessage ? grey_gainsboro : white;
216
+ } else {
217
+ backgroundColor = blue_alice;
218
+ }
219
+ } else if (alignment === 'left' || error) {
220
+ backgroundColor = white;
221
+ }
215
222
 
216
223
  const repliesCurveColor = isMyMessage && !error ? backgroundColor : grey_whisper;
217
224
 
@@ -4,7 +4,7 @@ import type { TouchableOpacityProps } from 'react-native';
4
4
 
5
5
  import type { MessagePinnedHeaderProps } from 'src/components/Message/MessageSimple/MessagePinnedHeader';
6
6
 
7
- import type { ChannelState, MessageResponse } from 'stream-chat';
7
+ import type { Attachment, ChannelState, MessageResponse } from 'stream-chat';
8
8
 
9
9
  import type { AttachmentProps } from '../../components/Attachment/Attachment';
10
10
  import type { AttachmentActionsProps } from '../../components/Attachment/AttachmentActions';
@@ -107,7 +107,10 @@ export type MessagesContextValue<
107
107
  * Defaults to: [Giphy](https://github.com/GetStream/stream-chat-react-native/blob/master/src/components/Attachment/Giphy.tsx)
108
108
  */
109
109
  Giphy: React.ComponentType<GiphyProps<StreamChatGenerics>>;
110
-
110
+ /**
111
+ * The giphy version to render - check the keys of the [Image Object](https://developers.giphy.com/docs/api/schema#image-object) for possible values. Uses 'fixed_height' by default
112
+ * */
113
+ giphyVersion: keyof NonNullable<Attachment['giphy']>;
111
114
  /**
112
115
  * When true, messageList will be scrolled at first unread message, when opened.
113
116
  */
@@ -20,6 +20,7 @@ export const Colors = {
20
20
  grey_gainsboro: '#DBDBDB',
21
21
  grey_whisper: '#ECEBEB',
22
22
  icon_background: '#FFFFFF',
23
+ label_bg_transparent: '#00000033', // 33 = 20% opacity
23
24
  modal_shadow: '#00000099', // 99 = 60% opacity; x=0, y= 1, radius=4
24
25
  overlay: '#000000CC', // CC = 80% opacity
25
26
  shadow_icon: '#00000040', // 40 = 25% opacity; x=0, y=0, radius=4
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.1.3"
2
+ "version": "4.2.0-beta.1"
3
3
  }