stream-chat-react-native-core 4.7.0-beta.5 → 4.7.1-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 (222) hide show
  1. package/lib/commonjs/components/Attachment/Attachment.js +23 -13
  2. package/lib/commonjs/components/Attachment/Attachment.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/Card.js +63 -30
  4. package/lib/commonjs/components/Attachment/Card.js.map +1 -1
  5. package/lib/commonjs/components/Attachment/FileAttachment.js +10 -17
  6. package/lib/commonjs/components/Attachment/FileAttachment.js.map +1 -1
  7. package/lib/commonjs/components/Attachment/Gallery.js +22 -10
  8. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  9. package/lib/commonjs/components/Attachment/utils/openUrlSafely.js +54 -0
  10. package/lib/commonjs/components/Attachment/utils/openUrlSafely.js.map +1 -0
  11. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js +90 -56
  12. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  13. package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
  14. package/lib/commonjs/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
  15. package/lib/commonjs/components/ImageGallery/ImageGallery.js +23 -22
  16. package/lib/commonjs/components/ImageGallery/ImageGallery.js.map +1 -1
  17. package/lib/commonjs/components/ImageGallery/components/AnimatedGalleryVideo.js +8 -8
  18. package/lib/commonjs/components/ImageGallery/components/AnimatedGalleryVideo.js.map +1 -1
  19. package/lib/commonjs/components/Message/Message.js +10 -7
  20. package/lib/commonjs/components/Message/Message.js.map +1 -1
  21. package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
  22. package/lib/commonjs/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
  23. package/lib/commonjs/components/Reply/Reply.js +12 -12
  24. package/lib/commonjs/components/Reply/Reply.js.map +1 -1
  25. package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
  26. package/lib/commonjs/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
  27. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
  28. package/lib/commonjs/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  29. package/lib/commonjs/contexts/channelContext/ChannelContext.js +14 -4
  30. package/lib/commonjs/contexts/channelContext/ChannelContext.js.map +1 -1
  31. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js +14 -4
  32. package/lib/commonjs/contexts/channelsContext/ChannelsContext.js.map +1 -1
  33. package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
  34. package/lib/commonjs/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
  35. package/lib/commonjs/contexts/chatContext/ChatContext.js +14 -4
  36. package/lib/commonjs/contexts/chatContext/ChatContext.js.map +1 -1
  37. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
  38. package/lib/commonjs/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  39. package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js +2 -2
  40. package/lib/commonjs/contexts/keyboardContext/KeyboardContext.js.map +1 -1
  41. package/lib/commonjs/contexts/messageContext/MessageContext.js +14 -4
  42. package/lib/commonjs/contexts/messageContext/MessageContext.js.map +1 -1
  43. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js +14 -4
  44. package/lib/commonjs/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  45. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
  46. package/lib/commonjs/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  47. package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
  48. package/lib/commonjs/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
  49. package/lib/commonjs/contexts/messagesContext/MessagesContext.js +14 -4
  50. package/lib/commonjs/contexts/messagesContext/MessagesContext.js.map +1 -1
  51. package/lib/commonjs/contexts/overlayContext/OverlayContext.js +13 -3
  52. package/lib/commonjs/contexts/overlayContext/OverlayContext.js.map +1 -1
  53. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js +12 -12
  54. package/lib/commonjs/contexts/overlayContext/OverlayProvider.js.map +1 -1
  55. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
  56. package/lib/commonjs/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  57. package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
  58. package/lib/commonjs/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
  59. package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js +14 -4
  60. package/lib/commonjs/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
  61. package/lib/commonjs/contexts/themeContext/ThemeContext.js +13 -7
  62. package/lib/commonjs/contexts/themeContext/ThemeContext.js.map +1 -1
  63. package/lib/commonjs/contexts/themeContext/utils/theme.js +9 -0
  64. package/lib/commonjs/contexts/themeContext/utils/theme.js.map +1 -1
  65. package/lib/commonjs/contexts/threadContext/ThreadContext.js +14 -4
  66. package/lib/commonjs/contexts/threadContext/ThreadContext.js.map +1 -1
  67. package/lib/commonjs/contexts/translationContext/TranslationContext.js +15 -6
  68. package/lib/commonjs/contexts/translationContext/TranslationContext.js.map +1 -1
  69. package/lib/commonjs/contexts/typingContext/TypingContext.js +14 -4
  70. package/lib/commonjs/contexts/typingContext/TypingContext.js.map +1 -1
  71. package/lib/commonjs/contexts/utils/defaultBaseContextValue.js +7 -0
  72. package/lib/commonjs/contexts/utils/defaultBaseContextValue.js.map +1 -0
  73. package/lib/commonjs/contexts/utils/isTestEnvironment.js +11 -0
  74. package/lib/commonjs/contexts/utils/isTestEnvironment.js.map +1 -0
  75. package/lib/commonjs/mock-builders/mock.js +30 -5
  76. package/lib/commonjs/mock-builders/mock.js.map +1 -1
  77. package/lib/commonjs/native.js +8 -2
  78. package/lib/commonjs/native.js.map +1 -1
  79. package/lib/commonjs/version.json +1 -1
  80. package/lib/module/components/Attachment/Attachment.js +23 -13
  81. package/lib/module/components/Attachment/Attachment.js.map +1 -1
  82. package/lib/module/components/Attachment/Card.js +63 -30
  83. package/lib/module/components/Attachment/Card.js.map +1 -1
  84. package/lib/module/components/Attachment/FileAttachment.js +10 -17
  85. package/lib/module/components/Attachment/FileAttachment.js.map +1 -1
  86. package/lib/module/components/Attachment/Gallery.js +22 -10
  87. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  88. package/lib/module/components/Attachment/utils/openUrlSafely.js +54 -0
  89. package/lib/module/components/Attachment/utils/openUrlSafely.js.map +1 -0
  90. package/lib/module/components/AttachmentPicker/AttachmentPicker.js +90 -56
  91. package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  92. package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js +1 -1
  93. package/lib/module/components/AutoCompleteInput/AutoCompleteSuggestionList.js.map +1 -1
  94. package/lib/module/components/ImageGallery/ImageGallery.js +23 -22
  95. package/lib/module/components/ImageGallery/ImageGallery.js.map +1 -1
  96. package/lib/module/components/ImageGallery/components/AnimatedGalleryVideo.js +8 -8
  97. package/lib/module/components/ImageGallery/components/AnimatedGalleryVideo.js.map +1 -1
  98. package/lib/module/components/Message/Message.js +10 -7
  99. package/lib/module/components/Message/Message.js.map +1 -1
  100. package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js +2 -2
  101. package/lib/module/components/MessageInput/SendMessageDisallowedIndicator.js.map +1 -1
  102. package/lib/module/components/Reply/Reply.js +12 -12
  103. package/lib/module/components/Reply/Reply.js.map +1 -1
  104. package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js +2 -2
  105. package/lib/module/contexts/activeChannelsRefContext/ActiveChannelsRefContext.js.map +1 -1
  106. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js +14 -4
  107. package/lib/module/contexts/attachmentPickerContext/AttachmentPickerContext.js.map +1 -1
  108. package/lib/module/contexts/channelContext/ChannelContext.js +14 -4
  109. package/lib/module/contexts/channelContext/ChannelContext.js.map +1 -1
  110. package/lib/module/contexts/channelsContext/ChannelsContext.js +14 -4
  111. package/lib/module/contexts/channelsContext/ChannelsContext.js.map +1 -1
  112. package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js +15 -9
  113. package/lib/module/contexts/channelsStateContext/ChannelsStateContext.js.map +1 -1
  114. package/lib/module/contexts/chatContext/ChatContext.js +14 -4
  115. package/lib/module/contexts/chatContext/ChatContext.js.map +1 -1
  116. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js +14 -4
  117. package/lib/module/contexts/imageGalleryContext/ImageGalleryContext.js.map +1 -1
  118. package/lib/module/contexts/keyboardContext/KeyboardContext.js +2 -2
  119. package/lib/module/contexts/keyboardContext/KeyboardContext.js.map +1 -1
  120. package/lib/module/contexts/messageContext/MessageContext.js +14 -4
  121. package/lib/module/contexts/messageContext/MessageContext.js.map +1 -1
  122. package/lib/module/contexts/messageInputContext/MessageInputContext.js +14 -4
  123. package/lib/module/contexts/messageInputContext/MessageInputContext.js.map +1 -1
  124. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js +14 -4
  125. package/lib/module/contexts/messageOverlayContext/MessageOverlayContext.js.map +1 -1
  126. package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js +4 -4
  127. package/lib/module/contexts/messageOverlayContext/hooks/useResettableState.test.js.map +1 -1
  128. package/lib/module/contexts/messagesContext/MessagesContext.js +14 -4
  129. package/lib/module/contexts/messagesContext/MessagesContext.js.map +1 -1
  130. package/lib/module/contexts/overlayContext/OverlayContext.js +13 -3
  131. package/lib/module/contexts/overlayContext/OverlayContext.js.map +1 -1
  132. package/lib/module/contexts/overlayContext/OverlayProvider.js +12 -12
  133. package/lib/module/contexts/overlayContext/OverlayProvider.js.map +1 -1
  134. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js +13 -3
  135. package/lib/module/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.js.map +1 -1
  136. package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js +14 -4
  137. package/lib/module/contexts/paginatedMessageListContext/PaginatedMessageListContext.js.map +1 -1
  138. package/lib/module/contexts/suggestionsContext/SuggestionsContext.js +14 -4
  139. package/lib/module/contexts/suggestionsContext/SuggestionsContext.js.map +1 -1
  140. package/lib/module/contexts/themeContext/ThemeContext.js +13 -7
  141. package/lib/module/contexts/themeContext/ThemeContext.js.map +1 -1
  142. package/lib/module/contexts/themeContext/utils/theme.js +9 -0
  143. package/lib/module/contexts/themeContext/utils/theme.js.map +1 -1
  144. package/lib/module/contexts/threadContext/ThreadContext.js +14 -4
  145. package/lib/module/contexts/threadContext/ThreadContext.js.map +1 -1
  146. package/lib/module/contexts/translationContext/TranslationContext.js +15 -6
  147. package/lib/module/contexts/translationContext/TranslationContext.js.map +1 -1
  148. package/lib/module/contexts/typingContext/TypingContext.js +14 -4
  149. package/lib/module/contexts/typingContext/TypingContext.js.map +1 -1
  150. package/lib/module/contexts/utils/defaultBaseContextValue.js +7 -0
  151. package/lib/module/contexts/utils/defaultBaseContextValue.js.map +1 -0
  152. package/lib/module/contexts/utils/isTestEnvironment.js +11 -0
  153. package/lib/module/contexts/utils/isTestEnvironment.js.map +1 -0
  154. package/lib/module/mock-builders/mock.js +30 -5
  155. package/lib/module/mock-builders/mock.js.map +1 -1
  156. package/lib/module/native.js +8 -2
  157. package/lib/module/native.js.map +1 -1
  158. package/lib/module/version.json +1 -1
  159. package/lib/typescript/components/Attachment/__tests__/openUrlSafely.test.d.ts +1 -0
  160. package/lib/typescript/components/Attachment/utils/openUrlSafely.d.ts +1 -0
  161. package/lib/typescript/contexts/__tests__/index.test.d.ts +1 -0
  162. package/lib/typescript/contexts/keyboardContext/KeyboardContext.d.ts +6 -2
  163. package/lib/typescript/contexts/themeContext/ThemeContext.d.ts +5 -2
  164. package/lib/typescript/contexts/themeContext/utils/theme.d.ts +6 -0
  165. package/lib/typescript/contexts/utils/defaultBaseContextValue.d.ts +1 -0
  166. package/lib/typescript/contexts/utils/isTestEnvironment.d.ts +1 -0
  167. package/lib/typescript/mock-builders/mock.d.ts +2 -2
  168. package/lib/typescript/native.d.ts +1 -0
  169. package/package.json +1 -1
  170. package/src/components/Attachment/Attachment.tsx +4 -1
  171. package/src/components/Attachment/Card.tsx +30 -9
  172. package/src/components/Attachment/FileAttachment.tsx +2 -4
  173. package/src/components/Attachment/Gallery.tsx +17 -4
  174. package/src/components/Attachment/__tests__/Attachment.test.js +0 -53
  175. package/src/components/Attachment/__tests__/Giphy.test.js +9 -5
  176. package/src/components/Attachment/__tests__/openUrlSafely.test.ts +48 -0
  177. package/src/components/Attachment/utils/openUrlSafely.ts +17 -0
  178. package/src/components/AttachmentPicker/AttachmentPicker.tsx +5 -3
  179. package/src/components/AutoCompleteInput/AutoCompleteSuggestionList.tsx +1 -0
  180. package/src/components/ImageGallery/ImageGallery.tsx +7 -3
  181. package/src/components/ImageGallery/components/AnimatedGalleryVideo.tsx +16 -13
  182. package/src/components/ImageGallery/components/__tests__/ImageGalleryHeader.test.tsx +5 -3
  183. package/src/components/Message/Message.tsx +5 -2
  184. package/src/components/MessageInput/SendMessageDisallowedIndicator.tsx +1 -0
  185. package/src/components/MessageInput/__tests__/FileUploadPreview.test.js +1 -1
  186. package/src/components/Reply/Reply.tsx +6 -3
  187. package/src/contexts/__tests__/index.test.tsx +103 -0
  188. package/src/contexts/activeChannelsRefContext/ActiveChannelsRefContext.tsx +1 -0
  189. package/src/contexts/attachmentPickerContext/AttachmentPickerContext.tsx +18 -4
  190. package/src/contexts/channelContext/ChannelContext.tsx +18 -2
  191. package/src/contexts/channelsContext/ChannelsContext.tsx +18 -2
  192. package/src/contexts/channelsStateContext/ChannelsStateContext.tsx +19 -10
  193. package/src/contexts/chatContext/ChatContext.tsx +15 -2
  194. package/src/contexts/imageGalleryContext/ImageGalleryContext.tsx +18 -3
  195. package/src/contexts/keyboardContext/KeyboardContext.tsx +2 -1
  196. package/src/contexts/messageContext/MessageContext.tsx +19 -2
  197. package/src/contexts/messageInputContext/MessageInputContext.tsx +20 -2
  198. package/src/contexts/messageOverlayContext/MessageOverlayContext.tsx +19 -3
  199. package/src/contexts/messageOverlayContext/hooks/useResettableState.test.tsx +1 -0
  200. package/src/contexts/messagesContext/MessagesContext.tsx +19 -2
  201. package/src/contexts/overlayContext/OverlayContext.tsx +17 -2
  202. package/src/contexts/overlayContext/OverlayProvider.tsx +1 -0
  203. package/src/contexts/ownCapabilitiesContext/OwnCapabilitiesContext.tsx +18 -3
  204. package/src/contexts/paginatedMessageListContext/PaginatedMessageListContext.tsx +15 -3
  205. package/src/contexts/suggestionsContext/SuggestionsContext.tsx +19 -2
  206. package/src/contexts/suggestionsContext/__tests__/Suggestions.test.js +1 -0
  207. package/src/contexts/themeContext/ThemeContext.tsx +19 -5
  208. package/src/contexts/themeContext/utils/theme.ts +15 -0
  209. package/src/contexts/threadContext/ThreadContext.tsx +16 -2
  210. package/src/contexts/translationContext/TranslationContext.tsx +18 -4
  211. package/src/contexts/typingContext/TypingContext.tsx +17 -2
  212. package/src/contexts/utils/defaultBaseContextValue.ts +1 -0
  213. package/src/contexts/utils/isTestEnvironment.ts +1 -0
  214. package/src/mock-builders/mock.js +16 -3
  215. package/src/native.ts +3 -1
  216. package/src/version.json +1 -1
  217. package/lib/commonjs/components/Attachment/hooks/useGoToURL.js +0 -42
  218. package/lib/commonjs/components/Attachment/hooks/useGoToURL.js.map +0 -1
  219. package/lib/module/components/Attachment/hooks/useGoToURL.js +0 -42
  220. package/lib/module/components/Attachment/hooks/useGoToURL.js.map +0 -1
  221. package/lib/typescript/components/Attachment/hooks/useGoToURL.d.ts +0 -2
  222. package/src/components/Attachment/hooks/useGoToURL.ts +0 -27
@@ -4,7 +4,10 @@ import type { ChannelState } from 'stream-chat';
4
4
 
5
5
  import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
6
6
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
7
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
8
+
7
9
  import { getDisplayName } from '../utils/getDisplayName';
10
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
8
11
 
9
12
  export type ThreadContextValue<
10
13
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -21,7 +24,7 @@ export type ThreadContextValue<
21
24
  threadMessages: ChannelState<StreamChatGenerics>['threads'][string];
22
25
  };
23
26
 
24
- export const ThreadContext = React.createContext({} as ThreadContextValue);
27
+ export const ThreadContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as ThreadContextValue);
25
28
 
26
29
  export const ThreadProvider = <
27
30
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -38,8 +41,19 @@ export const ThreadProvider = <
38
41
 
39
42
  export const useThreadContext = <
40
43
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
41
- >() => useContext(ThreadContext) as unknown as ThreadContextValue<StreamChatGenerics>;
44
+ >() => {
45
+ const contextValue = useContext(
46
+ ThreadContext,
47
+ ) as unknown as ThreadContextValue<StreamChatGenerics>;
48
+
49
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
50
+ throw new Error(
51
+ `The useThreadContext hook was called outside of the ThreadContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
52
+ );
53
+ }
42
54
 
55
+ return contextValue;
56
+ };
43
57
  /**
44
58
  * Typescript currently does not support partial inference so if ThreadContext
45
59
  * typing is desired while using the HOC withThreadContextContext the Props for the
@@ -6,8 +6,8 @@ import type { TFunction } from 'i18next';
6
6
  import type { Moment } from 'moment';
7
7
 
8
8
  import type { DefaultStreamChatGenerics } from '../../types/types';
9
-
10
9
  import { getDisplayName } from '../utils/getDisplayName';
10
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
11
11
 
12
12
  export const isDayOrMoment = (output: TDateTimeParserOutput): output is Dayjs.Dayjs | Moment =>
13
13
  (output as Dayjs.Dayjs | Moment).isSame != null;
@@ -23,10 +23,14 @@ export type TranslationContextValue = {
23
23
  tDateTimeParser: TDateTimeParser;
24
24
  };
25
25
 
26
- export const TranslationContext = React.createContext<TranslationContextValue>({
26
+ const defaultTranslationContextValue: TranslationContextValue = {
27
27
  t: (key: string) => key,
28
28
  tDateTimeParser: (input) => Dayjs(input),
29
- });
29
+ };
30
+
31
+ export const TranslationContext = React.createContext<TranslationContextValue>(
32
+ defaultTranslationContextValue,
33
+ );
30
34
 
31
35
  export const TranslationProvider: React.FC<{
32
36
  value: TranslationContextValue;
@@ -34,7 +38,17 @@ export const TranslationProvider: React.FC<{
34
38
  <TranslationContext.Provider value={value}>{children}</TranslationContext.Provider>
35
39
  );
36
40
 
37
- export const useTranslationContext = () => useContext(TranslationContext);
41
+ export const useTranslationContext = () => {
42
+ const contextValue = useContext(TranslationContext);
43
+
44
+ if (contextValue === defaultTranslationContextValue && !isTestEnvironment()) {
45
+ throw new Error(
46
+ `The useTranslationContext hook was called outside the TranslationContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider)(https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
47
+ );
48
+ }
49
+
50
+ return contextValue;
51
+ };
38
52
 
39
53
  export const withTranslationContext = <
40
54
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -3,7 +3,10 @@ import React, { PropsWithChildren, useContext } from 'react';
3
3
  import type { ChannelState } from 'stream-chat';
4
4
 
5
5
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
6
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
7
+
6
8
  import { getDisplayName } from '../utils/getDisplayName';
9
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
7
10
 
8
11
  export type TypingContextValue<
9
12
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -11,7 +14,7 @@ export type TypingContextValue<
11
14
  typing: ChannelState<StreamChatGenerics>['typing'];
12
15
  };
13
16
 
14
- export const TypingContext = React.createContext({} as TypingContextValue);
17
+ export const TypingContext = React.createContext(DEFAULT_BASE_CONTEXT_VALUE as TypingContextValue);
15
18
 
16
19
  export const TypingProvider = <
17
20
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -28,7 +31,19 @@ export const TypingProvider = <
28
31
 
29
32
  export const useTypingContext = <
30
33
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
31
- >() => useContext(TypingContext) as unknown as TypingContextValue<StreamChatGenerics>;
34
+ >() => {
35
+ const contextValue = useContext(
36
+ TypingContext,
37
+ ) as unknown as TypingContextValue<StreamChatGenerics>;
38
+
39
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
40
+ throw new Error(
41
+ `The useTypingContext hook was called outside of the TypingContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
42
+ );
43
+ }
44
+
45
+ return contextValue;
46
+ };
32
47
 
33
48
  /**
34
49
  * Typescript currently does not support partial inference so if TypingContext
@@ -0,0 +1 @@
1
+ export const DEFAULT_BASE_CONTEXT_VALUE = {};
@@ -0,0 +1 @@
1
+ export const isTestEnvironment = () => process.env.NODE_ENV === 'test';
@@ -17,7 +17,9 @@ const setUser = (client, user) =>
17
17
  resolve();
18
18
  });
19
19
 
20
- function mockClient(client) {
20
+ function mockClient(client, options = {}) {
21
+ const { disableAppSettings = true } = options;
22
+
21
23
  jest.spyOn(client, '_setToken').mockImplementation();
22
24
  jest.spyOn(client, '_setupConnection').mockImplementation();
23
25
  client.tokenManager = {
@@ -25,15 +27,26 @@ function mockClient(client) {
25
27
  tokenReady: jest.fn(() => true),
26
28
  };
27
29
  client.setUser = setUser.bind(null, client);
30
+
31
+ if (disableAppSettings) {
32
+ client.getAppSettings = jest.fn(() => ({}));
33
+ }
34
+
28
35
  return client;
29
36
  }
30
37
 
31
- export const getTestClient = () => mockClient(new StreamChat(apiKey));
38
+ export const getTestClient = (options = {}) => mockClient(new StreamChat(apiKey), options);
32
39
 
33
- export const getTestClientWithUser = async (user) => {
40
+ export const getTestClientWithUser = async (user, options = {}) => {
41
+ const { disableAppSettings = true } = options;
34
42
  const client = mockClient(new StreamChat(apiKey));
35
43
  await setUser(client, user);
36
44
  client.wsPromise = Promise.resolve();
45
+
46
+ if (disableAppSettings) {
47
+ client.getAppSettings = jest.fn(() => ({}));
48
+ }
49
+
37
50
  return client;
38
51
  };
39
52
 
package/src/native.ts CHANGED
@@ -145,7 +145,7 @@ export type VideoType = {
145
145
  style?: StyleProp<ViewStyle>;
146
146
  };
147
147
 
148
- export let Video: React.ComponentType<VideoType> = fail;
148
+ export let Video: React.ComponentType<VideoType>;
149
149
 
150
150
  type Handlers = {
151
151
  compressImage?: CompressImage;
@@ -219,3 +219,5 @@ export const registerNativeHandlers = (handlers: Handlers) => {
219
219
  Video = handlers.Video;
220
220
  }
221
221
  };
222
+
223
+ export const isVideoPackageAvailable = () => !!Video;
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "4.7.0-beta.5"
2
+ "version": "4.7.1-beta.1"
3
3
  }
@@ -1,42 +0,0 @@
1
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useGoToURL = void 0;
7
-
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
-
10
- var _react = require("react");
11
-
12
- var _reactNative = require("react-native");
13
-
14
- var useGoToURL = function useGoToURL(url) {
15
- var _useState = (0, _react.useState)(false),
16
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
17
- error = _useState2[0],
18
- setError = _useState2[1];
19
-
20
- var finalUrl = url;
21
- var pattern = new RegExp(/^\S+:\/\//);
22
-
23
- if (!pattern.test(finalUrl)) {
24
- finalUrl = 'http://' + url;
25
- }
26
-
27
- var openURL = function openURL() {
28
- return _reactNative.Linking.canOpenURL(finalUrl).then(function (supported) {
29
- if (supported) {
30
- _reactNative.Linking.openURL(finalUrl);
31
- } else {
32
- setError(true);
33
- console.warn("Don't know how to open URI: " + finalUrl);
34
- }
35
- });
36
- };
37
-
38
- return [error, openURL];
39
- };
40
-
41
- exports.useGoToURL = useGoToURL;
42
- //# sourceMappingURL=useGoToURL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useGoToURL.ts"],"names":["useGoToURL","url","error","setError","finalUrl","pattern","RegExp","test","openURL","Linking","canOpenURL","then","supported","console","warn"],"mappings":";;;;;;;;;AAAA;;AACA;;AAIO,IAAMA,UAA0B,GAAG,SAA7BA,UAA6B,CAACC,GAAD,EAAkB;AAC1D,kBAA0B,qBAAkB,KAAlB,CAA1B;AAAA;AAAA,MAAOC,KAAP;AAAA,MAAcC,QAAd;;AAEA,MAAIC,QAAQ,GAAGH,GAAf;AACA,MAAMI,OAAO,GAAG,IAAIC,MAAJ,CAAW,WAAX,CAAhB;;AAEA,MAAI,CAACD,OAAO,CAACE,IAAR,CAAaH,QAAb,CAAL,EAA6B;AAC3BA,IAAAA,QAAQ,GAAG,YAAYH,GAAvB;AACD;;AAED,MAAMO,OAAO,GAAG,SAAVA,OAAU;AAAA,WACdC,qBAAQC,UAAR,CAAmBN,QAAnB,EAA6BO,IAA7B,CAAkC,UAACC,SAAD,EAAe;AAC/C,UAAIA,SAAJ,EAAe;AACbH,6BAAQD,OAAR,CAAgBJ,QAAhB;AACD,OAFD,MAEO;AACLD,QAAAA,QAAQ,CAAC,IAAD,CAAR;AACAU,QAAAA,OAAO,CAACC,IAAR,kCAA4CV,QAA5C;AACD;AACF,KAPD,CADc;AAAA,GAAhB;;AAUA,SAAO,CAACF,KAAD,EAAQM,OAAR,CAAP;AACD,CArBM","sourcesContent":["import { useState } from 'react';\nimport { Linking } from 'react-native';\n\nexport type UseGoToURLType = (url?: string) => [boolean, () => Promise<void>];\n\nexport const useGoToURL: UseGoToURLType = (url?: string) => {\n const [error, setError] = useState<boolean>(false);\n\n let finalUrl = url as string;\n const pattern = new RegExp(/^\\S+:\\/\\//);\n\n if (!pattern.test(finalUrl)) {\n finalUrl = 'http://' + url;\n }\n\n const openURL = () =>\n Linking.canOpenURL(finalUrl).then((supported) => {\n if (supported) {\n Linking.openURL(finalUrl);\n } else {\n setError(true);\n console.warn(`Don't know how to open URI: ${finalUrl}`);\n }\n });\n\n return [error, openURL];\n};\n"]}
@@ -1,42 +0,0 @@
1
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useGoToURL = void 0;
7
-
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
-
10
- var _react = require("react");
11
-
12
- var _reactNative = require("react-native");
13
-
14
- var useGoToURL = function useGoToURL(url) {
15
- var _useState = (0, _react.useState)(false),
16
- _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
17
- error = _useState2[0],
18
- setError = _useState2[1];
19
-
20
- var finalUrl = url;
21
- var pattern = new RegExp(/^\S+:\/\//);
22
-
23
- if (!pattern.test(finalUrl)) {
24
- finalUrl = 'http://' + url;
25
- }
26
-
27
- var openURL = function openURL() {
28
- return _reactNative.Linking.canOpenURL(finalUrl).then(function (supported) {
29
- if (supported) {
30
- _reactNative.Linking.openURL(finalUrl);
31
- } else {
32
- setError(true);
33
- console.warn("Don't know how to open URI: " + finalUrl);
34
- }
35
- });
36
- };
37
-
38
- return [error, openURL];
39
- };
40
-
41
- exports.useGoToURL = useGoToURL;
42
- //# sourceMappingURL=useGoToURL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useGoToURL.ts"],"names":["useGoToURL","url","error","setError","finalUrl","pattern","RegExp","test","openURL","Linking","canOpenURL","then","supported","console","warn"],"mappings":";;;;;;;;;AAAA;;AACA;;AAIO,IAAMA,UAA0B,GAAG,SAA7BA,UAA6B,CAACC,GAAD,EAAkB;AAC1D,kBAA0B,qBAAkB,KAAlB,CAA1B;AAAA;AAAA,MAAOC,KAAP;AAAA,MAAcC,QAAd;;AAEA,MAAIC,QAAQ,GAAGH,GAAf;AACA,MAAMI,OAAO,GAAG,IAAIC,MAAJ,CAAW,WAAX,CAAhB;;AAEA,MAAI,CAACD,OAAO,CAACE,IAAR,CAAaH,QAAb,CAAL,EAA6B;AAC3BA,IAAAA,QAAQ,GAAG,YAAYH,GAAvB;AACD;;AAED,MAAMO,OAAO,GAAG,SAAVA,OAAU;AAAA,WACdC,qBAAQC,UAAR,CAAmBN,QAAnB,EAA6BO,IAA7B,CAAkC,UAACC,SAAD,EAAe;AAC/C,UAAIA,SAAJ,EAAe;AACbH,6BAAQD,OAAR,CAAgBJ,QAAhB;AACD,OAFD,MAEO;AACLD,QAAAA,QAAQ,CAAC,IAAD,CAAR;AACAU,QAAAA,OAAO,CAACC,IAAR,kCAA4CV,QAA5C;AACD;AACF,KAPD,CADc;AAAA,GAAhB;;AAUA,SAAO,CAACF,KAAD,EAAQM,OAAR,CAAP;AACD,CArBM","sourcesContent":["import { useState } from 'react';\nimport { Linking } from 'react-native';\n\nexport type UseGoToURLType = (url?: string) => [boolean, () => Promise<void>];\n\nexport const useGoToURL: UseGoToURLType = (url?: string) => {\n const [error, setError] = useState<boolean>(false);\n\n let finalUrl = url as string;\n const pattern = new RegExp(/^\\S+:\\/\\//);\n\n if (!pattern.test(finalUrl)) {\n finalUrl = 'http://' + url;\n }\n\n const openURL = () =>\n Linking.canOpenURL(finalUrl).then((supported) => {\n if (supported) {\n Linking.openURL(finalUrl);\n } else {\n setError(true);\n console.warn(`Don't know how to open URI: ${finalUrl}`);\n }\n });\n\n return [error, openURL];\n};\n"]}
@@ -1,2 +0,0 @@
1
- export declare type UseGoToURLType = (url?: string) => [boolean, () => Promise<void>];
2
- export declare const useGoToURL: UseGoToURLType;
@@ -1,27 +0,0 @@
1
- import { useState } from 'react';
2
- import { Linking } from 'react-native';
3
-
4
- export type UseGoToURLType = (url?: string) => [boolean, () => Promise<void>];
5
-
6
- export const useGoToURL: UseGoToURLType = (url?: string) => {
7
- const [error, setError] = useState<boolean>(false);
8
-
9
- let finalUrl = url as string;
10
- const pattern = new RegExp(/^\S+:\/\//);
11
-
12
- if (!pattern.test(finalUrl)) {
13
- finalUrl = 'http://' + url;
14
- }
15
-
16
- const openURL = () =>
17
- Linking.canOpenURL(finalUrl).then((supported) => {
18
- if (supported) {
19
- Linking.openURL(finalUrl);
20
- } else {
21
- setError(true);
22
- console.warn(`Don't know how to open URI: ${finalUrl}`);
23
- }
24
- });
25
-
26
- return [error, openURL];
27
- };