stream-chat-react-native-core 5.11.3-beta.6 → 5.12.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 (33) hide show
  1. package/lib/commonjs/components/Attachment/Gallery.js +38 -22
  2. package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
  3. package/lib/commonjs/components/Attachment/ImageReloadIndicator.js +40 -0
  4. package/lib/commonjs/components/Attachment/ImageReloadIndicator.js.map +1 -0
  5. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js +15 -3
  6. package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  7. package/lib/commonjs/hooks/useLoadingImage.js +57 -16
  8. package/lib/commonjs/hooks/useLoadingImage.js.map +1 -1
  9. package/lib/commonjs/native.js +6 -1
  10. package/lib/commonjs/native.js.map +1 -1
  11. package/lib/commonjs/version.json +1 -1
  12. package/lib/module/components/Attachment/Gallery.js +38 -22
  13. package/lib/module/components/Attachment/Gallery.js.map +1 -1
  14. package/lib/module/components/Attachment/ImageReloadIndicator.js +40 -0
  15. package/lib/module/components/Attachment/ImageReloadIndicator.js.map +1 -0
  16. package/lib/module/components/AttachmentPicker/AttachmentPicker.js +15 -3
  17. package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
  18. package/lib/module/hooks/useLoadingImage.js +57 -16
  19. package/lib/module/hooks/useLoadingImage.js.map +1 -1
  20. package/lib/module/native.js +6 -1
  21. package/lib/module/native.js.map +1 -1
  22. package/lib/module/version.json +1 -1
  23. package/lib/typescript/components/Attachment/ImageReloadIndicator.d.ts +6 -0
  24. package/lib/typescript/hooks/useLoadingImage.d.ts +3 -3
  25. package/lib/typescript/native.d.ts +5 -0
  26. package/package.json +1 -1
  27. package/src/components/Attachment/Gallery.tsx +22 -5
  28. package/src/components/Attachment/ImageReloadIndicator.tsx +27 -0
  29. package/src/components/Attachment/__tests__/Gallery.test.js +3 -1
  30. package/src/components/AttachmentPicker/AttachmentPicker.tsx +18 -1
  31. package/src/hooks/useLoadingImage.tsx +57 -9
  32. package/src/native.ts +8 -0
  33. package/src/version.json +1 -1
@@ -1,16 +1,64 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useReducer, useRef } from 'react';
2
2
 
3
- import { useNetInfo } from '@react-native-community/netinfo';
3
+ import { useChatContext } from '../contexts/chatContext/ChatContext';
4
4
 
5
+ type ImageState = {
6
+ isLoadingImage: boolean;
7
+ isLoadingImageError: boolean;
8
+ };
9
+
10
+ type Action =
11
+ | { type: 'reloadImage' }
12
+ | { isLoadingImage: boolean; type: 'setLoadingImage' }
13
+ | { isLoadingImageError: boolean; type: 'setLoadingImageError' };
14
+
15
+ function reducer(prevState: ImageState, action: Action) {
16
+ switch (action.type) {
17
+ case 'reloadImage':
18
+ return {
19
+ ...prevState,
20
+ isLoadingImage: true,
21
+ isLoadingImageError: false,
22
+ };
23
+ case 'setLoadingImage':
24
+ return { ...prevState, isLoadingImage: action.isLoadingImage };
25
+ case 'setLoadingImageError':
26
+ return { ...prevState, isLoadingImageError: action.isLoadingImageError };
27
+ default:
28
+ return prevState;
29
+ }
30
+ }
5
31
  export const useLoadingImage = () => {
6
- const [isLoadingImage, setLoadingImage] = useState(true);
7
- const [isLoadingImageError, setLoadingImageError] = useState(false);
8
- const { isConnected } = useNetInfo();
32
+ const [imageState, dispatch] = useReducer(reducer, {
33
+ isLoadingImage: true,
34
+ isLoadingImageError: false,
35
+ });
36
+ const { isLoadingImage, isLoadingImageError } = imageState;
37
+ const onReloadImageRef = useRef(() => dispatch({ type: 'reloadImage' }));
38
+ const setLoadingImageRef = useRef((isLoadingImage: boolean) =>
39
+ dispatch({ isLoadingImage, type: 'setLoadingImage' }),
40
+ );
41
+ const setLoadingImageErrorRef = useRef((isLoadingImageError: boolean) =>
42
+ dispatch({ isLoadingImageError, type: 'setLoadingImageError' }),
43
+ );
44
+ const { isOnline } = useChatContext();
45
+
46
+ // storing the value of isLoadingImageError in a ref to avoid passing as a dep to useEffect
47
+ const hasImageLoadedErroredRef = useRef(isLoadingImageError);
48
+ hasImageLoadedErroredRef.current = isLoadingImageError;
49
+
9
50
  useEffect(() => {
10
- if (isConnected) {
11
- setLoadingImageError(false);
51
+ if (isOnline && hasImageLoadedErroredRef.current) {
52
+ // if there was an error previously, reload the image automatically when user comes back online
53
+ onReloadImageRef.current();
12
54
  }
13
- }, [isConnected]);
55
+ }, [isOnline]);
14
56
 
15
- return { isLoadingImage, isLoadingImageError, setLoadingImage, setLoadingImageError };
57
+ return {
58
+ isLoadingImage,
59
+ isLoadingImageError,
60
+ onReloadImage: onReloadImageRef.current,
61
+ setLoadingImage: setLoadingImageRef.current,
62
+ setLoadingImageError: setLoadingImageErrorRef.current,
63
+ };
16
64
  };
package/src/native.ts CHANGED
@@ -30,6 +30,9 @@ export let deleteFile: DeleteFile = fail;
30
30
  type GetLocalAssetUri = (uriOrAssetId: string) => Promise<string> | never;
31
31
  export let getLocalAssetUri: GetLocalAssetUri = fail;
32
32
 
33
+ type OniOS14LibrarySelectionChange = (callback: () => void) => { unsubscribe: () => void };
34
+ export let oniOS14GalleryLibrarySelectionChange: OniOS14LibrarySelectionChange = fail;
35
+
33
36
  type GetPhotos = ({ after, first }: { first: number; after?: string }) =>
34
37
  | Promise<{
35
38
  assets: Array<Omit<Asset, 'source'> & { source: 'picker' }>;
@@ -216,6 +219,7 @@ type Handlers = {
216
219
  getLocalAssetUri?: GetLocalAssetUri;
217
220
  getPhotos?: GetPhotos;
218
221
  NetInfo?: NetInfo;
222
+ oniOS14GalleryLibrarySelectionChange?: OniOS14LibrarySelectionChange;
219
223
  pickDocument?: PickDocument;
220
224
  saveFile?: SaveFile;
221
225
  SDK?: string;
@@ -251,6 +255,10 @@ export const registerNativeHandlers = (handlers: Handlers) => {
251
255
  getPhotos = handlers.getPhotos;
252
256
  }
253
257
 
258
+ if (handlers.oniOS14GalleryLibrarySelectionChange) {
259
+ oniOS14GalleryLibrarySelectionChange = handlers.oniOS14GalleryLibrarySelectionChange;
260
+ }
261
+
254
262
  if (handlers.pickDocument !== undefined) {
255
263
  pickDocument = handlers.pickDocument;
256
264
  }
package/src/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "5.11.3-beta.6"
2
+ "version": "5.12.0-beta.1"
3
3
  }