stream-chat-react-native-core 4.9.0-beta.2 → 4.9.0-beta.3

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 (30) hide show
  1. package/lib/commonjs/components/MessageInput/FileUploadPreview.js +24 -18
  2. package/lib/commonjs/components/MessageInput/FileUploadPreview.js.map +1 -1
  3. package/lib/commonjs/components/MessageInput/ImageUploadPreview.js +2 -2
  4. package/lib/commonjs/components/MessageInput/ImageUploadPreview.js.map +1 -1
  5. package/lib/commonjs/components/RTLComponents/WritingDirectionAwareText.js +43 -0
  6. package/lib/commonjs/components/RTLComponents/WritingDirectionAwareText.js.map +1 -0
  7. package/lib/commonjs/components/Reply/Reply.js +7 -2
  8. package/lib/commonjs/components/Reply/Reply.js.map +1 -1
  9. package/lib/commonjs/version.json +1 -1
  10. package/lib/module/components/MessageInput/FileUploadPreview.js +24 -18
  11. package/lib/module/components/MessageInput/FileUploadPreview.js.map +1 -1
  12. package/lib/module/components/MessageInput/ImageUploadPreview.js +2 -2
  13. package/lib/module/components/MessageInput/ImageUploadPreview.js.map +1 -1
  14. package/lib/module/components/RTLComponents/WritingDirectionAwareText.js +43 -0
  15. package/lib/module/components/RTLComponents/WritingDirectionAwareText.js.map +1 -0
  16. package/lib/module/components/Reply/Reply.js +7 -2
  17. package/lib/module/components/Reply/Reply.js.map +1 -1
  18. package/lib/module/version.json +1 -1
  19. package/lib/typescript/components/RTLComponents/WritingDirectionAwareText.d.ts +4 -0
  20. package/lib/typescript/components/Reply/__tests__/Reply.test.d.ts +1 -0
  21. package/lib/typescript/mock-builders/api/getOrCreateChannel.d.ts +7 -0
  22. package/lib/typescript/mock-builders/api/useMockedApis.d.ts +1 -0
  23. package/lib/typescript/mock-builders/generator/channel.d.ts +116 -0
  24. package/package.json +3 -2
  25. package/src/components/MessageInput/FileUploadPreview.tsx +7 -5
  26. package/src/components/MessageInput/ImageUploadPreview.tsx +2 -2
  27. package/src/components/RTLComponents/WritingDirectionAwareText.tsx +17 -0
  28. package/src/components/Reply/Reply.tsx +19 -3
  29. package/src/components/Reply/__tests__/Reply.test.tsx +48 -0
  30. package/src/version.json +1 -1
@@ -0,0 +1,116 @@
1
+ export function generateChannel(customValues: any): {
2
+ _client: {};
3
+ data: {
4
+ cid: string;
5
+ config: {
6
+ name: string;
7
+ type: string;
8
+ automod: string;
9
+ automod_behavior: string;
10
+ commands: {
11
+ args: string;
12
+ description: string;
13
+ name: string;
14
+ set: string;
15
+ }[];
16
+ connect_events: boolean;
17
+ created_at: string;
18
+ max_message_length: number;
19
+ message_retention: string;
20
+ mutes: boolean;
21
+ reactions: boolean;
22
+ read_events: boolean;
23
+ replies: boolean;
24
+ search: boolean;
25
+ typing_events: boolean;
26
+ updated_at: string;
27
+ uploads: boolean;
28
+ url_enrichment: boolean;
29
+ };
30
+ created_at: string;
31
+ created_by: {
32
+ banned: boolean;
33
+ created_at: string;
34
+ id: any;
35
+ image: any;
36
+ name: any;
37
+ online: boolean;
38
+ role: string;
39
+ updated_at: string;
40
+ };
41
+ frozen: boolean;
42
+ id: any;
43
+ own_capabilities: string[];
44
+ type: string;
45
+ updated_at: string;
46
+ };
47
+ id: any;
48
+ state: {
49
+ members: {};
50
+ messages: never[];
51
+ setIsUpToDate: jest.Mock<any, any>;
52
+ };
53
+ type: string;
54
+ };
55
+ export function generateChannelResponse(customValues?: {
56
+ channel: {};
57
+ id: any;
58
+ type: string;
59
+ }): {
60
+ channel: {
61
+ id: any;
62
+ type: string;
63
+ user: {
64
+ banned: boolean;
65
+ created_at: string;
66
+ id: any;
67
+ image: any;
68
+ name: any;
69
+ online: boolean;
70
+ role: string;
71
+ updated_at: string;
72
+ };
73
+ cid: string;
74
+ config: {
75
+ name: string;
76
+ type: string;
77
+ automod: string;
78
+ automod_behavior: string;
79
+ commands: {
80
+ args: string;
81
+ description: string;
82
+ name: string;
83
+ set: string;
84
+ }[];
85
+ connect_events: boolean;
86
+ created_at: string;
87
+ max_message_length: number;
88
+ message_retention: string;
89
+ mutes: boolean;
90
+ reactions: boolean;
91
+ read_events: boolean;
92
+ replies: boolean;
93
+ search: boolean;
94
+ typing_events: boolean;
95
+ updated_at: string;
96
+ uploads: boolean;
97
+ url_enrichment: boolean;
98
+ };
99
+ created_at: string;
100
+ created_by: {
101
+ banned: boolean;
102
+ created_at: string;
103
+ id: any;
104
+ image: any;
105
+ name: any;
106
+ online: boolean;
107
+ role: string;
108
+ updated_at: string;
109
+ };
110
+ frozen: boolean;
111
+ own_capabilities: string[];
112
+ updated_at: string;
113
+ };
114
+ members: never[];
115
+ messages: never[];
116
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "stream-chat-react-native-core",
3
3
  "description": "The official React Native and Expo components for Stream Chat, a service for building chat applications",
4
- "version": "4.9.0-beta.2",
4
+ "version": "4.9.0-beta.3",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -34,7 +34,8 @@
34
34
  "prepare-distribution": "cd examples/SampleApp && npm version patch && react-native-version && git add ./ && git commit -m 'Bump build version' --no-verify",
35
35
  "prettier": "prettier --list-different '**/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc",
36
36
  "prettier-fix": "prettier --write '**/*.{js,ts,tsx,md,json}' .eslintrc.json ../.prettierrc .babelrc",
37
- "test:unit": "TZ=UTC jest --coverage",
37
+ "test:coverage": "yarn test:unit --coverage",
38
+ "test:unit": "TZ=UTC jest",
38
39
  "validate-translations": "node bin/validate-translations.js",
39
40
  "get-version": "echo $npm_package_version",
40
41
  "version": "bash ./bin/before-tag.sh",
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
- import { FlatList, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
2
+ import { FlatList, I18nManager, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
3
3
 
4
4
  import { UploadProgressIndicator } from './UploadProgressIndicator';
5
5
 
@@ -19,6 +19,7 @@ import { Warning } from '../../icons/Warning';
19
19
  import type { DefaultStreamChatGenerics } from '../../types/types';
20
20
  import { getIndicatorTypeForFileState, ProgressIndicatorTypes } from '../../utils/utils';
21
21
  import { getFileSizeDisplayText } from '../Attachment/FileAttachment';
22
+ import { WritingDirectionAwareText } from '../RTLComponents/WritingDirectionAwareText';
22
23
 
23
24
  const FILE_PREVIEW_HEIGHT = 60;
24
25
  const WARNING_ICON_SIZE = 16;
@@ -71,7 +72,7 @@ const styles = StyleSheet.create({
71
72
  },
72
73
  warningIconStyle: {
73
74
  borderRadius: 24,
74
- marginTop: 3,
75
+ marginTop: 2,
75
76
  },
76
77
  });
77
78
 
@@ -105,9 +106,9 @@ const UnsupportedFileTypeOrFileSizeIndicator = ({
105
106
  </Text>
106
107
  </View>
107
108
  ) : (
108
- <Text style={[styles.fileSizeText, { color: grey }, fileSizeText]}>
109
- {item.file.duration ? item.file.duration : getFileSizeDisplayText(item.file.size)}
110
- </Text>
109
+ <WritingDirectionAwareText style={[styles.fileSizeText, { color: grey }, fileSizeText]}>
110
+ {item.file.duration || getFileSizeDisplayText(item.file.size)}
111
+ </WritingDirectionAwareText>
111
112
  );
112
113
  };
113
114
 
@@ -188,6 +189,7 @@ const FileUploadPreviewWithContext = <
188
189
  24 - // 24 = close icon size
189
190
  24, // 24 = internal padding
190
191
  },
192
+ I18nManager.isRTL ? { writingDirection: 'rtl' } : { writingDirection: 'ltr' },
191
193
  filenameText,
192
194
  ]}
193
195
  >
@@ -27,7 +27,7 @@ const styles = StyleSheet.create({
27
27
  },
28
28
  fileSizeText: {
29
29
  fontSize: 12,
30
- paddingLeft: 10,
30
+ paddingHorizontal: 10,
31
31
  },
32
32
  flatList: { paddingBottom: 12 },
33
33
  iconContainer: {
@@ -54,7 +54,7 @@ const styles = StyleSheet.create({
54
54
  },
55
55
  warningIconStyle: {
56
56
  borderRadius: 24,
57
- marginTop: 4,
57
+ marginTop: 6,
58
58
  },
59
59
  warningText: {
60
60
  alignItems: 'center',
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { I18nManager, StyleSheet, Text, ViewProps } from 'react-native';
3
+
4
+ const styles = StyleSheet.create({
5
+ defaultStyle: { writingDirection: I18nManager.isRTL ? 'rtl' : 'ltr' },
6
+ });
7
+
8
+ export type WritingDirectionAwareTextProps = ViewProps;
9
+
10
+ export const WritingDirectionAwareText: React.FC<WritingDirectionAwareTextProps> = (props) => {
11
+ const { children, style, ...rest } = props;
12
+ return (
13
+ <Text {...rest} style={[style, styles.defaultStyle]}>
14
+ {children}
15
+ </Text>
16
+ );
17
+ };
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useContext, useState } from 'react';
2
2
  import { Image, ImageStyle, StyleSheet, View, ViewStyle } from 'react-native';
3
3
 
4
4
  import merge from 'lodash/merge';
@@ -7,8 +7,8 @@ import type { Attachment } from 'stream-chat';
7
7
 
8
8
  import { useMessageContext } from '../../contexts/messageContext/MessageContext';
9
9
  import {
10
+ MessageInputContext,
10
11
  MessageInputContextValue,
11
- useMessageInputContext,
12
12
  } from '../../contexts/messageInputContext/MessageInputContext';
13
13
  import {
14
14
  MessagesContextValue,
@@ -267,6 +267,22 @@ const ReplyWithContext = <
267
267
  );
268
268
  };
269
269
 
270
+ /**
271
+ * When a reply is rendered in a MessageSimple, it does
272
+ * not have a MessageInputContext. As this is deliberate,
273
+ * this function exists to avoid the error thrown when
274
+ * using a context outside of its provider.
275
+ * */
276
+ const useMessageInputContextIfAvailable = <
277
+ StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
278
+ >() => {
279
+ const contextValue = useContext(
280
+ MessageInputContext,
281
+ ) as unknown as MessageInputContextValue<StreamChatGenerics>;
282
+
283
+ return contextValue;
284
+ };
285
+
270
286
  const areEqual = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>(
271
287
  prevProps: ReplyPropsWithContext<StreamChatGenerics>,
272
288
  nextProps: ReplyPropsWithContext<StreamChatGenerics>,
@@ -307,7 +323,7 @@ export const Reply = <
307
323
  const { FileAttachmentIcon = FileIconDefault, MessageAvatar = MessageAvatarDefault } =
308
324
  useMessagesContext<StreamChatGenerics>();
309
325
 
310
- const { editing, quotedMessage } = useMessageInputContext<StreamChatGenerics>();
326
+ const { editing, quotedMessage } = useMessageInputContextIfAvailable<StreamChatGenerics>();
311
327
 
312
328
  const quotedEditingMessage = (
313
329
  typeof editing !== 'boolean' ? editing?.quoted_message || false : false
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+
3
+ import { render, waitFor } from '@testing-library/react-native';
4
+
5
+ import { OverlayProvider } from '../../../contexts/overlayContext/OverlayProvider';
6
+ import { getOrCreateChannelApi } from '../../../mock-builders/api/getOrCreateChannel';
7
+ import { useMockedApis } from '../../../mock-builders/api/useMockedApis';
8
+ import { generateChannelResponse } from '../../../mock-builders/generator/channel';
9
+ import { getTestClientWithUser } from '../../../mock-builders/mock';
10
+ import { Channel } from '../../Channel/Channel';
11
+ import { Chat } from '../../Chat/Chat';
12
+ import { Reply } from '../Reply';
13
+
14
+ describe('<Reply/>', () => {
15
+ it('can be rendered outside of a MessageInputProvider', async () => {
16
+ const oldEnvironment = process.env;
17
+ process.env.NODE_ENV = 'not_test';
18
+
19
+ const chatClient = await getTestClientWithUser({ id: 'neil' });
20
+
21
+ const mockedChannel = generateChannelResponse();
22
+ useMockedApis(chatClient, [getOrCreateChannelApi(mockedChannel)]);
23
+ const channel = chatClient.channel('messaging', 'some-chat');
24
+ await channel.watch();
25
+
26
+ const TestComponent = () => (
27
+ <OverlayProvider>
28
+ <Chat client={chatClient}>
29
+ <Channel channel={channel} client={chatClient}>
30
+ <Reply />
31
+ </Channel>
32
+ </Chat>
33
+ </OverlayProvider>
34
+ );
35
+
36
+ try {
37
+ const { toJSON } = render(<TestComponent />);
38
+
39
+ await waitFor(() => {
40
+ expect(toJSON()).not.toBeNull();
41
+ });
42
+ } catch (error: unknown) {
43
+ throw new Error(`Error thrown while rendering Reply: ${error}`);
44
+ }
45
+
46
+ process.env = oldEnvironment;
47
+ });
48
+ });
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.9.0-beta.2"
2
+ "version": "4.9.0-beta.3"
3
3
  }