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
@@ -5,6 +5,8 @@ import { buildGallery } from './utils/buildGallery/buildGallery';
5
5
 
6
6
  import { getGalleryImageBorderRadius } from './utils/getGalleryImageBorderRadius';
7
7
 
8
+ import { openUrlSafely } from './utils/openUrlSafely';
9
+
8
10
  import type { MessageType } from '../../components/MessageList/hooks/useMessageList';
9
11
  import {
10
12
  ImageGalleryContextValue,
@@ -23,6 +25,7 @@ import {
23
25
  useOverlayContext,
24
26
  } from '../../contexts/overlayContext/OverlayContext';
25
27
  import { useTheme } from '../../contexts/themeContext/ThemeContext';
28
+ import { isVideoPackageAvailable } from '../../native';
26
29
  import type { DefaultStreamChatGenerics } from '../../types/types';
27
30
  import { getUrlWithoutParams, makeImageCompatibleUrl } from '../../utils/utils';
28
31
 
@@ -205,11 +208,11 @@ const GalleryWithContext = <
205
208
  testID={`gallery-${invertedDirections ? 'row' : 'column'}-${colIndex}`}
206
209
  >
207
210
  {rows.map(({ height, resizeMode, type, url, width }, rowIndex) => {
208
- const defaultOnPress = () => {
209
- // Added if-else to keep the logic readable, instead of DRY.
210
- // if - legacyImageViewerSwipeBehaviour is disabled
211
- // else - legacyImageViewerSwipeBehaviour is enabled
211
+ const openImageViewer = () => {
212
212
  if (!legacyImageViewerSwipeBehaviour && message) {
213
+ // Added if-else to keep the logic readable, instead of DRY.
214
+ // if - legacyImageViewerSwipeBehaviour is disabled
215
+ // else - legacyImageViewerSwipeBehaviour is enabled
213
216
  setImages([message]);
214
217
  setImage({ messageId: message.id, url });
215
218
  setOverlay('gallery');
@@ -219,6 +222,16 @@ const GalleryWithContext = <
219
222
  }
220
223
  };
221
224
 
225
+ const defaultOnPress = () => {
226
+ if (type === 'video' && !isVideoPackageAvailable()) {
227
+ // This condition is kinda unreachable, since we render videos as file attachment if the video
228
+ // library is not installed. But doesn't hurt to have extra safeguard, in case of some customizations.
229
+ openUrlSafely(url);
230
+ } else {
231
+ openImageViewer();
232
+ }
233
+ };
234
+
222
235
  const borderRadius = getGalleryImageBorderRadius({
223
236
  alignment,
224
237
  colIndex,
@@ -1,8 +1,5 @@
1
1
  import React from 'react';
2
2
 
3
- import { Linking } from 'react-native';
4
-
5
- import { act, renderHook } from '@testing-library/react-hooks';
6
3
  import { fireEvent, render, waitFor } from '@testing-library/react-native';
7
4
  import { v4 as uuidv4 } from 'uuid';
8
5
 
@@ -11,14 +8,12 @@ import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
11
8
  import {
12
9
  generateAttachmentAction,
13
10
  generateAudioAttachment,
14
- generateCardAttachment,
15
11
  generateFileAttachment,
16
12
  generateImageAttachment,
17
13
  } from '../../../mock-builders/generator/attachment';
18
14
  import { generateMessage } from '../../../mock-builders/generator/message';
19
15
  import { Attachment } from '../Attachment';
20
16
  import { AttachmentActions } from '../AttachmentActions';
21
- import { useGoToURL } from '../hooks/useGoToURL';
22
17
 
23
18
  const getAttachmentComponent = (props) => {
24
19
  const message = generateMessage();
@@ -111,52 +106,4 @@ describe('Attachment', () => {
111
106
  expect(handleAction).toHaveBeenCalledTimes(2);
112
107
  });
113
108
  });
114
-
115
- it('should render "Card" if attachment type is not recognized', async () => {
116
- const { getByTestId } = render(
117
- getAttachmentComponent({
118
- attachment: generateCardAttachment({
119
- type: Date.now().toString(),
120
- }),
121
- }),
122
- );
123
- await waitFor(() => {
124
- expect(getByTestId('card-attachment')).toBeTruthy();
125
- });
126
- });
127
-
128
- it('should open the URL in the browser', async () => {
129
- jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn().mockResolvedValue(true));
130
-
131
- jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn().mockResolvedValue(false));
132
-
133
- const { result, waitFor } = renderHook(() => useGoToURL('www.google.com'));
134
-
135
- const [error, openURL] = result.current;
136
-
137
- await act(openURL);
138
-
139
- await waitFor(() => {
140
- expect(Linking.canOpenURL).toHaveBeenCalled();
141
- expect(error).not.toBeTruthy();
142
- expect(Linking.openURL).toHaveBeenCalled();
143
- });
144
- });
145
-
146
- it('should open the URL in the browser when no url', async () => {
147
- jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn().mockResolvedValue(false));
148
-
149
- jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn().mockResolvedValue(true));
150
-
151
- const { result, waitForNextUpdate } = await renderHook(() => useGoToURL());
152
- const [error, openURL] = result.current;
153
-
154
- act(openURL);
155
-
156
- await waitForNextUpdate(() => {
157
- expect(Linking.canOpenURL).toHaveBeenCalled();
158
- expect(error).toBeTruthy();
159
- expect(Linking.openURL).not.toHaveBeenCalled();
160
- });
161
- });
162
109
  });
@@ -251,10 +251,12 @@ describe('Giphy', () => {
251
251
  </OverlayProvider>,
252
252
  );
253
253
 
254
- expect(queryByTestId('giphy-action-attachment')).toBeTruthy();
255
- expect(getByTestId('cancel-action-button')).toBeTruthy();
256
- expect(getByTestId('shuffle-action-button')).toBeTruthy();
257
- expect(getByTestId('send-action-button')).toBeTruthy();
254
+ await waitFor(() => {
255
+ expect(queryByTestId('giphy-action-attachment')).toBeTruthy();
256
+ expect(getByTestId('cancel-action-button')).toBeTruthy();
257
+ expect(getByTestId('shuffle-action-button')).toBeTruthy();
258
+ expect(getByTestId('send-action-button')).toBeTruthy();
259
+ });
258
260
  });
259
261
 
260
262
  it('giphy attachment UI should render within the message list', async () => {
@@ -285,6 +287,8 @@ describe('Giphy', () => {
285
287
  </OverlayProvider>,
286
288
  );
287
289
 
288
- expect(queryByTestId('giphy-attachment')).toBeTruthy();
290
+ await waitFor(() => {
291
+ expect(queryByTestId('giphy-attachment')).toBeTruthy();
292
+ });
289
293
  });
290
294
  });
@@ -0,0 +1,48 @@
1
+ import { Linking } from 'react-native';
2
+
3
+ import { waitFor } from '@testing-library/react-native';
4
+
5
+ import { openUrlSafely } from '../utils/openUrlSafely';
6
+
7
+ describe('openUrlSafely', () => {
8
+ afterEach(() => {
9
+ jest.clearAllMocks();
10
+ });
11
+
12
+ it('should open a valid url', async () => {
13
+ jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn().mockResolvedValue(true));
14
+ jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn());
15
+
16
+ const url = 'https://www.google.com';
17
+ await openUrlSafely(url);
18
+ await waitFor(() => {
19
+ expect(Linking.canOpenURL).toHaveBeenCalled();
20
+ expect(Linking.openURL).toHaveBeenCalled();
21
+ });
22
+ });
23
+
24
+ it('should not call openUrl if url is not supported', async () => {
25
+ jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn().mockResolvedValue(false));
26
+ jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn());
27
+
28
+ Linking.openURL = jest.fn();
29
+ const url = 'basjkdbkjasbdkjabskdjabsjkdbasjkda---asdkjasjkdabsk';
30
+ await openUrlSafely(url);
31
+ await waitFor(() => {
32
+ expect(Linking.canOpenURL).toHaveBeenCalled();
33
+ expect(Linking.openURL).not.toHaveBeenCalled();
34
+ });
35
+ });
36
+
37
+ it('should append http if missing', async () => {
38
+ jest.spyOn(Linking, 'canOpenURL').mockImplementation(jest.fn());
39
+ jest.spyOn(Linking, 'openURL').mockImplementation(jest.fn());
40
+
41
+ Linking.openURL = jest.fn();
42
+ const url = 'google.com';
43
+ await openUrlSafely(url);
44
+ await waitFor(() => {
45
+ expect(Linking.canOpenURL).toHaveBeenCalledWith('http://google.com');
46
+ });
47
+ });
48
+ });
@@ -0,0 +1,17 @@
1
+ import { Linking } from 'react-native';
2
+
3
+ export const openUrlSafely = async (url?: string) => {
4
+ let finalUrl = url as string;
5
+ const pattern = new RegExp(/^\S+:\/\//);
6
+
7
+ if (!pattern.test(finalUrl)) {
8
+ finalUrl = 'http://' + url;
9
+ }
10
+ const supported = await Linking.canOpenURL(finalUrl);
11
+
12
+ if (supported) {
13
+ Linking.openURL(finalUrl);
14
+ } else {
15
+ console.warn(`Don't know how to open URI: ${finalUrl}`);
16
+ }
17
+ };
@@ -26,7 +26,7 @@ import type { AttachmentPickerErrorProps } from './components/AttachmentPickerEr
26
26
  import { useAttachmentPickerContext } from '../../contexts/attachmentPickerContext/AttachmentPickerContext';
27
27
  import { useTheme } from '../../contexts/themeContext/ThemeContext';
28
28
  import { Recorder } from '../../icons';
29
- import { getPhotos } from '../../native';
29
+ import { getLocalAssetUri, getPhotos } from '../../native';
30
30
  import type { Asset, File } from '../../types/types';
31
31
  import { vh, vw } from '../../utils/utils';
32
32
 
@@ -109,7 +109,9 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
109
109
 
110
110
  const size = vw(100) / (numberOfAttachmentPickerImageColumns || 3) - 2;
111
111
 
112
- const onPressVideo = () => {
112
+ const onPressVideo = async () => {
113
+ // For the case of expo messaging app where you need to fetch the asset uri from asset id
114
+ const localAssetURI = asset.id && (await getLocalAssetUri(asset.id));
113
115
  if (selected) {
114
116
  setSelectedFiles((files) => files.filter((file) => file.uri !== asset.uri));
115
117
  } else {
@@ -125,7 +127,7 @@ const AttachmentVideo: React.FC<AttachmentVideoProps> = (props) => {
125
127
  name: asset.filename,
126
128
  size: asset.fileSize,
127
129
  type: 'video',
128
- uri: asset.uri,
130
+ uri: localAssetURI || asset.uri,
129
131
  },
130
132
  ];
131
133
  });
@@ -197,6 +197,7 @@ export const AutoCompleteSuggestionList = <
197
197
  ) => {
198
198
  const { AutoCompleteSuggestionHeader, AutoCompleteSuggestionItem } =
199
199
  useSuggestionsContext<StreamChatGenerics>();
200
+
200
201
  return (
201
202
  <MemoizedAutoCompleteSuggestionList
202
203
  {...{ AutoCompleteSuggestionHeader, AutoCompleteSuggestionItem }}
@@ -55,7 +55,12 @@ import {
55
55
  useOverlayContext,
56
56
  } from '../../contexts/overlayContext/OverlayContext';
57
57
  import { useTheme } from '../../contexts/themeContext/ThemeContext';
58
- import type { VideoPayloadData, VideoProgressData, VideoType } from '../../native';
58
+ import {
59
+ isVideoPackageAvailable,
60
+ VideoPayloadData,
61
+ VideoProgressData,
62
+ VideoType,
63
+ } from '../../native';
59
64
  import type { DefaultStreamChatGenerics } from '../../types/types';
60
65
  import { getResizedImageUrl } from '../../utils/getResizedImageUrl';
61
66
  import { getUrlOfImageAttachment } from '../../utils/getUrlOfImageAttachment';
@@ -252,7 +257,6 @@ export const ImageGallery = <
252
257
  */
253
258
 
254
259
  const photos = images.reduce((acc: Photo<StreamChatGenerics>[], cur) => {
255
- console.log(cur);
256
260
  const attachmentImages =
257
261
  cur.attachments?.filter(
258
262
  (attachment) =>
@@ -264,7 +268,7 @@ export const ImageGallery = <
264
268
  !attachment.title_link &&
265
269
  !attachment.og_scrape_url &&
266
270
  getUrlOfImageAttachment(attachment)) ||
267
- attachment.type === 'video',
271
+ (isVideoPackageAvailable() && attachment.type === 'video'),
268
272
  ) || [];
269
273
 
270
274
  const attachmentPhotos = attachmentImages.map((a) => {
@@ -4,6 +4,7 @@ import type { StyleProp } from 'react-native';
4
4
  import Animated, { useAnimatedStyle } from 'react-native-reanimated';
5
5
 
6
6
  import {
7
+ isVideoPackageAvailable,
7
8
  PlaybackStatus,
8
9
  Video,
9
10
  VideoPayloadData,
@@ -173,19 +174,21 @@ export const AnimatedGalleryVideo: React.FC<Props> = React.memo(
173
174
  },
174
175
  ]}
175
176
  >
176
- <Video
177
- onBuffer={onBuffer}
178
- onEnd={onEnd}
179
- onLoad={onLoad}
180
- onLoadStart={onLoadStart}
181
- onPlaybackStatusUpdate={onPlayBackStatusUpdate}
182
- onProgress={onProgress}
183
- paused={paused}
184
- resizeMode='cover'
185
- style={style}
186
- uri={source.uri}
187
- videoRef={videoRef}
188
- />
177
+ {isVideoPackageAvailable() && (
178
+ <Video
179
+ onBuffer={onBuffer}
180
+ onEnd={onEnd}
181
+ onLoad={onLoad}
182
+ onLoadStart={onLoadStart}
183
+ onPlaybackStatusUpdate={onPlayBackStatusUpdate}
184
+ onProgress={onProgress}
185
+ paused={paused}
186
+ resizeMode='contain'
187
+ style={style}
188
+ uri={source.uri}
189
+ videoRef={videoRef}
190
+ />
191
+ )}
189
192
  <Animated.View
190
193
  style={[
191
194
  styles.activityIndicator,
@@ -4,13 +4,13 @@ import { useSharedValue } from 'react-native-reanimated';
4
4
 
5
5
  import { renderHook } from '@testing-library/react-hooks';
6
6
 
7
- import { render } from '@testing-library/react-native';
7
+ import { render, waitFor } from '@testing-library/react-native';
8
8
 
9
9
  import { ThemeProvider } from '../../../../contexts/themeContext/ThemeContext';
10
10
 
11
11
  import { ImageGalleryHeader } from '../ImageGalleryHeader';
12
12
 
13
- it('doesnt fail if fromNow is not available on first render', () => {
13
+ it('doesnt fail if fromNow is not available on first render', async () => {
14
14
  try {
15
15
  let sharedValueOpacity: Animated.SharedValue<number>;
16
16
  let sharedValueVisible: Animated.SharedValue<number>;
@@ -32,7 +32,9 @@ it('doesnt fail if fromNow is not available on first render', () => {
32
32
  />
33
33
  </ThemeProvider>,
34
34
  );
35
- expect(getAllByText('Unknown User')).toBeTruthy();
35
+ await waitFor(() => {
36
+ expect(getAllByText('Unknown User')).toBeTruthy();
37
+ });
36
38
  } catch (error: unknown) {
37
39
  if (error instanceof Error) {
38
40
  throw new Error(`Error encountered on first render of ImageGalleryHeader: ${error.message}`);
@@ -42,7 +42,7 @@ import {
42
42
  useTranslationContext,
43
43
  } from '../../contexts/translationContext/TranslationContext';
44
44
 
45
- import { triggerHaptic } from '../../native';
45
+ import { isVideoPackageAvailable, triggerHaptic } from '../../native';
46
46
  import type { DefaultStreamChatGenerics } from '../../types/types';
47
47
  import { emojiRegex, MessageStatusTypes } from '../../utils/utils';
48
48
 
@@ -332,9 +332,12 @@ const MessageWithContext = <
332
332
  if (cur.type === 'file') {
333
333
  acc.files.push(cur);
334
334
  acc.other = []; // remove other attachments if a file exists
335
- } else if (cur.type === 'video' && !cur.og_scrape_url) {
335
+ } else if (cur.type === 'video' && !cur.og_scrape_url && isVideoPackageAvailable()) {
336
336
  acc.videos.push({ image_url: cur.asset_url, type: 'video' });
337
337
  acc.other = [];
338
+ } else if (cur.type === 'video' && !cur.og_scrape_url) {
339
+ acc.files.push(cur);
340
+ acc.other = []; // remove other attachments if a file exists
338
341
  } else if (cur.type === 'image' && !cur.title_link && !cur.og_scrape_url) {
339
342
  /**
340
343
  * this next if is not combined with the above one for cases where we have
@@ -27,6 +27,7 @@ export const SendMessageDisallowedIndicator = () => {
27
27
  },
28
28
  },
29
29
  } = useTheme();
30
+
30
31
  return (
31
32
  <View
32
33
  style={[
@@ -256,7 +256,7 @@ describe('FileUploadPreview', () => {
256
256
  generateFileUploadPreview({ id: 'file-upload-id-1', state: FileState.UPLOADING }),
257
257
  generateFileUploadPreview({ id: 'file-upload-id-2', state: FileState.UPLOADED }),
258
258
  generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.UPLOAD_FAILED }),
259
- generateFileUploadPreview({ id: 'file-upload-id-3', state: FileState.NOT_SUPPORTED }),
259
+ generateFileUploadPreview({ id: 'file-upload-id-4', state: FileState.NOT_SUPPORTED }),
260
260
  ];
261
261
  const removeFile = jest.fn();
262
262
  const uploadFile = jest.fn();
@@ -88,12 +88,15 @@ const getMessageType = <
88
88
 
89
89
  const isLastAttachmentVideo = lastAttachment.type === 'video';
90
90
 
91
- const isLastAttachmentGiphy = lastAttachment.type === 'giphy' || lastAttachment.type === 'imgur';
91
+ const isLastAttachmentGiphy =
92
+ lastAttachment?.type === 'giphy' || lastAttachment?.type === 'imgur';
92
93
 
93
94
  const isLastAttachmentImageOrGiphy =
94
- lastAttachment.type === 'image' && !lastAttachment.title_link && !lastAttachment.og_scrape_url;
95
+ lastAttachment?.type === 'image' &&
96
+ !lastAttachment?.title_link &&
97
+ !lastAttachment?.og_scrape_url;
95
98
 
96
- const isLastAttachmentImage = lastAttachment.image_url || lastAttachment.thumb_url;
99
+ const isLastAttachmentImage = lastAttachment?.image_url || lastAttachment?.thumb_url;
97
100
 
98
101
  if (isLastAttachmentFile) {
99
102
  messageType = 'file';
@@ -0,0 +1,103 @@
1
+ import React from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ import { render } from '@testing-library/react-native';
5
+
6
+ import {
7
+ useAttachmentPickerContext,
8
+ useChannelContext,
9
+ useChannelsContext,
10
+ useChatContext,
11
+ useImageGalleryContext,
12
+ useMessageContext,
13
+ useMessageOverlayContext,
14
+ useMessagesContext,
15
+ useOverlayContext,
16
+ useOwnCapabilitiesContext,
17
+ usePaginatedMessageListContext,
18
+ useSuggestionsContext,
19
+ useTheme,
20
+ useThreadContext,
21
+ useTypingContext,
22
+ } from '../';
23
+ import { useChannelsStateContext } from '../channelsStateContext/ChannelsStateContext';
24
+
25
+ jest.mock('../utils/isTestEnvironment', () => ({ isTestEnvironment: jest.fn(() => false) }));
26
+ console.error = jest.fn();
27
+ describe('contexts hooks in a component throws an error with message when not wrapped in a provider', () => {
28
+ const TestComponent = ({ useContextHook }: { useContextHook(): void }) => {
29
+ useContextHook();
30
+ return <View />;
31
+ };
32
+
33
+ it.each([
34
+ [
35
+ useOverlayContext,
36
+ 'The useOverlayContext hook was called outside the OverlayContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider',
37
+ ],
38
+ [
39
+ usePaginatedMessageListContext,
40
+ 'The usePaginatedMessageListContext hook was called outside of the PaginatedMessageList provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel',
41
+ ],
42
+ [
43
+ useChannelsStateContext,
44
+ `The useChannelStateContext hook was called outside the ChannelStateContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
45
+ ],
46
+ [
47
+ useOwnCapabilitiesContext,
48
+ `The useOwnCapabilitiesContext hook was called outside the Channel Component. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
49
+ ],
50
+ [
51
+ useSuggestionsContext,
52
+ 'The useSuggestionsContext hook was called outside of the SuggestionsContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel',
53
+ ],
54
+ [
55
+ useTypingContext,
56
+ `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`,
57
+ ],
58
+ [
59
+ useTheme,
60
+ `The useThemeContext hook was called outside the ThemeContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
61
+ ],
62
+ [
63
+ useChannelContext,
64
+ `The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
65
+ ],
66
+ [
67
+ useChannelsContext,
68
+ `The useChannelsContext hook was called outside of the ChannelsContext provider. Make sure you have configured ChannelList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel-list`,
69
+ ],
70
+ [
71
+ useChatContext,
72
+ `The useChatContext hook was called outside the ChatContext Provider. Make sure you have configured Chat component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#chat`,
73
+ ],
74
+ [
75
+ useImageGalleryContext,
76
+ `The useImageGalleryContext hook was called outside the ImageGalleryContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
77
+ ],
78
+ [
79
+ useMessageContext,
80
+ `The useMessageContext hook was called outside of the MessageContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,
81
+ ],
82
+ [
83
+ useMessageOverlayContext,
84
+ `The useMessageOverlayContext hook was called outside the MessageOverlayContext Provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
85
+ ],
86
+ [
87
+ useMessagesContext,
88
+ `The useMessagesContext hook was called outside of the MessagesContext provider. Make sure you have configured MessageList component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#message-list`,
89
+ ],
90
+ [
91
+ useThreadContext,
92
+ `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`,
93
+ ],
94
+ [
95
+ useAttachmentPickerContext,
96
+ `The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
97
+ ],
98
+ ])('calls %p results in error %p', (useContextHook, expectedErrorMessage) => {
99
+ expect(() => render(<TestComponent useContextHook={useContextHook} />)).toThrowError(
100
+ expectedErrorMessage,
101
+ );
102
+ });
103
+ });
@@ -1,6 +1,7 @@
1
1
  import React, { PropsWithChildren, useContext } from 'react';
2
2
 
3
3
  import type { UnknownType } from '../../types/types';
4
+
4
5
  import { getDisplayName } from '../utils/getDisplayName';
5
6
 
6
7
  type ActiveChannels = React.MutableRefObject<string[]>;
@@ -1,7 +1,10 @@
1
1
  import React, { PropsWithChildren, useContext, useEffect, useState } from 'react';
2
2
 
3
3
  import type { Asset, DefaultStreamChatGenerics, File } from '../../types/types';
4
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
5
+
4
6
  import { getDisplayName } from '../utils/getDisplayName';
7
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
5
8
 
6
9
  export type AttachmentPickerIconProps = {
7
10
  numberOfImageUploads: number;
@@ -55,8 +58,8 @@ export type AttachmentPickerContextValue = {
55
58
  selectedPicker?: 'images';
56
59
  };
57
60
 
58
- export const AttachmentPickerContext = React.createContext<AttachmentPickerContextValue>(
59
- {} as AttachmentPickerContextValue,
61
+ export const AttachmentPickerContext = React.createContext(
62
+ DEFAULT_BASE_CONTEXT_VALUE as AttachmentPickerContextValue,
60
63
  );
61
64
 
62
65
  export const AttachmentPickerProvider = ({
@@ -118,8 +121,19 @@ export const AttachmentPickerProvider = ({
118
121
  );
119
122
  };
120
123
 
121
- export const useAttachmentPickerContext = () =>
122
- useContext(AttachmentPickerContext) as unknown as AttachmentPickerContextValue;
124
+ export const useAttachmentPickerContext = () => {
125
+ const contextValue = useContext(
126
+ AttachmentPickerContext,
127
+ ) as unknown as AttachmentPickerContextValue;
128
+
129
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
130
+ throw new Error(
131
+ `The useAttachmentPickerContext hook was called outside the AttachmentPickerContext provider. Make sure you have configured OverlayProvider component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#overlay-provider`,
132
+ );
133
+ }
134
+
135
+ return contextValue;
136
+ };
123
137
 
124
138
  export const withAttachmentPickerContext = <
125
139
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -5,7 +5,10 @@ import type { Channel, ChannelState } from 'stream-chat';
5
5
  import type { EmptyStateProps } from '../../components/Indicators/EmptyStateIndicator';
6
6
  import type { LoadingProps } from '../../components/Indicators/LoadingIndicator';
7
7
  import type { DefaultStreamChatGenerics, UnknownType } from '../../types/types';
8
+ import { DEFAULT_BASE_CONTEXT_VALUE } from '../utils/defaultBaseContextValue';
9
+
8
10
  import { getDisplayName } from '../utils/getDisplayName';
11
+ import { isTestEnvironment } from '../utils/isTestEnvironment';
9
12
 
10
13
  export type ChannelContextValue<
11
14
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -167,7 +170,9 @@ export type ChannelContextValue<
167
170
  watcherCount?: ChannelState<StreamChatGenerics>['watcher_count'];
168
171
  };
169
172
 
170
- export const ChannelContext = React.createContext({} as ChannelContextValue);
173
+ export const ChannelContext = React.createContext(
174
+ DEFAULT_BASE_CONTEXT_VALUE as ChannelContextValue,
175
+ );
171
176
 
172
177
  export const ChannelProvider = <
173
178
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
@@ -184,8 +189,19 @@ export const ChannelProvider = <
184
189
 
185
190
  export const useChannelContext = <
186
191
  StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
187
- >() => useContext(ChannelContext) as unknown as ChannelContextValue<StreamChatGenerics>;
192
+ >() => {
193
+ const contextValue = useContext(
194
+ ChannelContext,
195
+ ) as unknown as ChannelContextValue<StreamChatGenerics>;
188
196
 
197
+ if (contextValue === DEFAULT_BASE_CONTEXT_VALUE && !isTestEnvironment()) {
198
+ throw new Error(
199
+ `The useChannelContext hook was called outside of the ChannelContext provider. Make sure you have configured Channel component correctly - https://getstream.io/chat/docs/sdk/reactnative/basics/hello_stream_chat/#channel`,
200
+ );
201
+ }
202
+
203
+ return contextValue;
204
+ };
189
205
  /**
190
206
  * Typescript currently does not support partial inference so if ChatContext
191
207
  * typing is desired while using the HOC withChannelContext the Props for the