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.
- package/lib/commonjs/components/Attachment/Gallery.js +38 -22
- package/lib/commonjs/components/Attachment/Gallery.js.map +1 -1
- package/lib/commonjs/components/Attachment/ImageReloadIndicator.js +40 -0
- package/lib/commonjs/components/Attachment/ImageReloadIndicator.js.map +1 -0
- package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js +15 -3
- package/lib/commonjs/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
- package/lib/commonjs/hooks/useLoadingImage.js +57 -16
- package/lib/commonjs/hooks/useLoadingImage.js.map +1 -1
- package/lib/commonjs/native.js +6 -1
- package/lib/commonjs/native.js.map +1 -1
- package/lib/commonjs/version.json +1 -1
- package/lib/module/components/Attachment/Gallery.js +38 -22
- package/lib/module/components/Attachment/Gallery.js.map +1 -1
- package/lib/module/components/Attachment/ImageReloadIndicator.js +40 -0
- package/lib/module/components/Attachment/ImageReloadIndicator.js.map +1 -0
- package/lib/module/components/AttachmentPicker/AttachmentPicker.js +15 -3
- package/lib/module/components/AttachmentPicker/AttachmentPicker.js.map +1 -1
- package/lib/module/hooks/useLoadingImage.js +57 -16
- package/lib/module/hooks/useLoadingImage.js.map +1 -1
- package/lib/module/native.js +6 -1
- package/lib/module/native.js.map +1 -1
- package/lib/module/version.json +1 -1
- package/lib/typescript/components/Attachment/ImageReloadIndicator.d.ts +6 -0
- package/lib/typescript/hooks/useLoadingImage.d.ts +3 -3
- package/lib/typescript/native.d.ts +5 -0
- package/package.json +1 -1
- package/src/components/Attachment/Gallery.tsx +22 -5
- package/src/components/Attachment/ImageReloadIndicator.tsx +27 -0
- package/src/components/Attachment/__tests__/Gallery.test.js +3 -1
- package/src/components/AttachmentPicker/AttachmentPicker.tsx +18 -1
- package/src/hooks/useLoadingImage.tsx +57 -9
- package/src/native.ts +8 -0
- package/src/version.json +1 -1
|
@@ -1,16 +1,64 @@
|
|
|
1
|
-
import { useEffect,
|
|
1
|
+
import { useEffect, useReducer, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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 [
|
|
7
|
-
|
|
8
|
-
|
|
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 (
|
|
11
|
-
|
|
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
|
-
}, [
|
|
55
|
+
}, [isOnline]);
|
|
14
56
|
|
|
15
|
-
return {
|
|
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