stream-chat-react-native 5.40.0-rc.2 → 5.41.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/README.md +2 -1
- package/package.json +21 -19
- package/src/handlers/NetInfo.ts +43 -0
- package/src/{optionalDependencies → handlers}/Sound.tsx +1 -1
- package/src/{optionalDependencies → handlers}/Video.tsx +1 -1
- package/src/handlers/compressImage.ts +1 -1
- package/src/handlers/deleteFile.ts +11 -0
- package/src/handlers/index.ts +5 -0
- package/src/handlers/saveFile.ts +11 -0
- package/src/index.js +3 -6
- package/src/optionalDependencies/Audio.ts +3 -10
- package/src/optionalDependencies/getLocalAssetUri.ts +1 -1
- package/src/optionalDependencies/getPhotos.ts +1 -1
- package/src/optionalDependencies/iOS14RefreshGallerySelection.ts +1 -1
- package/src/optionalDependencies/index.ts +6 -10
- package/src/optionalDependencies/oniOS14GalleryLibrarySelectionChange.ts +1 -1
- package/src/optionalDependencies/shareImage.ts +6 -10
- package/src/optionalDependencies/takePhoto.ts +11 -15
- package/src/optionalDependencies/FlatList.ts +0 -21
- package/src/optionalDependencies/deleteFile.ts +0 -19
- package/src/optionalDependencies/saveFile.ts +0 -24
- /package/src/optionalDependencies/{AudioVideo.ts → Video.ts} +0 -0
package/README.md
CHANGED
|
@@ -7,10 +7,11 @@
|
|
|
7
7
|
> The official React Native and Expo components for Stream Chat, a service for
|
|
8
8
|
> building chat applications.
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
[](https://www.npmjs.com/package/stream-chat-react-native)
|
|
11
12
|
[](https://github.com/GetStream/stream-chat-react-native/actions)
|
|
12
13
|
[](https://getstream.io/chat/docs/sdk/reactnative)
|
|
13
|
-

|
|
14
15
|
|
|
15
16
|
<img align="right" src="https://getstream.imgix.net/images/ios-chat-tutorial/iphone_chat_art@3x.png?auto=format,enhance" width="50%" />
|
|
16
17
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stream-chat-react-native",
|
|
3
3
|
"description": "The official React Native SDK for Stream Chat, a service for building chat applications",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.41.0-beta.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -11,20 +11,22 @@
|
|
|
11
11
|
"types": "types/index.d.ts",
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"es6-symbol": "^3.1.3",
|
|
14
|
-
"stream-chat-react-native-core": "5.
|
|
14
|
+
"stream-chat-react-native-core": "5.41.0-beta.1"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@react-native-
|
|
19
|
-
"@react-native-
|
|
20
|
-
"@stream-io/flat-list-mvcp": "
|
|
21
|
-
"react-native": ">=0.
|
|
17
|
+
"@react-native-camera-roll/camera-roll": ">=5.0.0",
|
|
18
|
+
"@react-native-clipboard/clipboard": "^1.11.1",
|
|
19
|
+
"@react-native-community/netinfo": ">=2.0.7",
|
|
20
|
+
"@stream-io/flat-list-mvcp": "^0.10.3",
|
|
21
|
+
"react-native": ">=0.60.0",
|
|
22
22
|
"react-native-audio-recorder-player": ">=3.6.4",
|
|
23
|
-
"react-native-
|
|
24
|
-
"react-native-
|
|
25
|
-
"react-native-haptic-feedback": ">=
|
|
23
|
+
"react-native-document-picker": ">=9.0.1",
|
|
24
|
+
"react-native-fs": ">=2.16.6",
|
|
25
|
+
"react-native-haptic-feedback": ">=1.11.0",
|
|
26
26
|
"react-native-image-picker": ">=7.1.2",
|
|
27
|
-
"react-native-
|
|
27
|
+
"react-native-image-crop-picker": ">=0.33.2",
|
|
28
|
+
"react-native-image-resizer": ">=1.4.2",
|
|
29
|
+
"react-native-share": ">=4.1.0",
|
|
28
30
|
"react-native-video": ">=6.4.2"
|
|
29
31
|
},
|
|
30
32
|
"peerDependenciesMeta": {
|
|
@@ -34,9 +36,6 @@
|
|
|
34
36
|
"@react-native-clipboard/clipboard": {
|
|
35
37
|
"optional": true
|
|
36
38
|
},
|
|
37
|
-
"@stream-io/flat-list-mvcp": {
|
|
38
|
-
"optional": true
|
|
39
|
-
},
|
|
40
39
|
"react-native-share": {
|
|
41
40
|
"optional": true
|
|
42
41
|
},
|
|
@@ -49,13 +48,13 @@
|
|
|
49
48
|
"react-native-image-picker": {
|
|
50
49
|
"optional": true
|
|
51
50
|
},
|
|
52
|
-
"react-native-
|
|
51
|
+
"react-native-image-crop-picker": {
|
|
53
52
|
"optional": true
|
|
54
53
|
},
|
|
55
|
-
"react-native-
|
|
54
|
+
"react-native-audio-recorder-player": {
|
|
56
55
|
"optional": true
|
|
57
56
|
},
|
|
58
|
-
"react-native-
|
|
57
|
+
"react-native-video": {
|
|
59
58
|
"optional": true
|
|
60
59
|
}
|
|
61
60
|
},
|
|
@@ -64,7 +63,10 @@
|
|
|
64
63
|
"postpack": "rm README.md"
|
|
65
64
|
},
|
|
66
65
|
"devDependencies": {
|
|
67
|
-
"@
|
|
68
|
-
"
|
|
66
|
+
"@react-native-community/netinfo": ">=2.0.7",
|
|
67
|
+
"@stream-io/flat-list-mvcp": "0.10.3",
|
|
68
|
+
"react-native": ">=0.60.0",
|
|
69
|
+
"react-native-fs": ">=2.16.6",
|
|
70
|
+
"react-native-image-resizer": ">=1.4.2"
|
|
69
71
|
}
|
|
70
72
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { NetInfoState, default as OriginalNetInfo } from '@react-native-community/netinfo';
|
|
2
|
+
|
|
3
|
+
export const NetInfo = {
|
|
4
|
+
addEventListener(listener) {
|
|
5
|
+
let unsubscribe;
|
|
6
|
+
// For NetInfo >= 3.x.x
|
|
7
|
+
if (OriginalNetInfo.fetch && typeof OriginalNetInfo.fetch === 'function') {
|
|
8
|
+
unsubscribe = OriginalNetInfo.addEventListener(({ isConnected, isInternetReachable }) => {
|
|
9
|
+
// Initialize with truthy value when internetReachable is still loading
|
|
10
|
+
// if it resolves to false, listener is triggered with false value and network
|
|
11
|
+
// status is updated
|
|
12
|
+
listener(isInternetReachable === null ? isConnected : isConnected && isInternetReachable);
|
|
13
|
+
});
|
|
14
|
+
return unsubscribe;
|
|
15
|
+
} else {
|
|
16
|
+
// For NetInfo < 3.x.x
|
|
17
|
+
unsubscribe = OriginalNetInfo.addEventListener('connectionChange', () => {
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
OriginalNetInfo.isConnected.fetch().then((isConnected: NetInfoState) => {
|
|
20
|
+
listener(isConnected);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return unsubscribe.remove;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
fetch() {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
// For NetInfo >= 3.x.x
|
|
30
|
+
if (OriginalNetInfo.fetch && typeof OriginalNetInfo.fetch === 'function') {
|
|
31
|
+
OriginalNetInfo.fetch().then(({ isConnected }) => {
|
|
32
|
+
resolve(isConnected);
|
|
33
|
+
}, reject);
|
|
34
|
+
} else {
|
|
35
|
+
// For NetInfo < 3.x.x
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
OriginalNetInfo.isConnected.fetch().then((isConnected: NetInfoState) => {
|
|
38
|
+
resolve(isConnected);
|
|
39
|
+
}, reject);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import AudioVideoPlayer from './AudioVideo';
|
|
3
2
|
|
|
3
|
+
import AudioVideoPlayer from '../optionalDependencies/Video';
|
|
4
4
|
export const Video = AudioVideoPlayer
|
|
5
5
|
? ({ onBuffer, onEnd, onLoad, onProgress, paused, repeat, resizeMode, style, uri, videoRef }) => (
|
|
6
6
|
<AudioVideoPlayer
|
package/src/handlers/index.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import RNFS from 'react-native-fs';
|
|
2
|
+
|
|
3
|
+
export const saveFile = async ({ fileName, fromUrl }: { fileName: string; fromUrl: string }) => {
|
|
4
|
+
try {
|
|
5
|
+
const path = RNFS.CachesDirectoryPath + '/' + encodeURIComponent(fileName);
|
|
6
|
+
await RNFS.downloadFile({ fromUrl, toFile: path }).promise;
|
|
7
|
+
return 'file://' + path;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
throw new Error('Downloading image failed...');
|
|
10
|
+
}
|
|
11
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
2
|
|
|
3
|
+
import { FlatList } from '@stream-io/flat-list-mvcp';
|
|
3
4
|
import { registerNativeHandlers } from 'stream-chat-react-native-core';
|
|
4
5
|
|
|
5
|
-
import { compressImage } from './handlers';
|
|
6
|
+
import { compressImage, deleteFile, NetInfo, saveFile, Sound, Video } from './handlers';
|
|
6
7
|
|
|
7
8
|
import {
|
|
8
9
|
Audio,
|
|
9
|
-
deleteFile,
|
|
10
|
-
FlatList,
|
|
11
10
|
getLocalAssetUri,
|
|
12
11
|
getPhotos,
|
|
13
12
|
iOS14RefreshGallerySelection,
|
|
14
13
|
oniOS14GalleryLibrarySelectionChange,
|
|
15
14
|
pickDocument,
|
|
16
15
|
pickImage,
|
|
17
|
-
saveFile,
|
|
18
16
|
setClipboardString,
|
|
19
17
|
shareImage,
|
|
20
|
-
Sound,
|
|
21
18
|
takePhoto,
|
|
22
19
|
triggerHaptic,
|
|
23
|
-
Video,
|
|
24
20
|
} from './optionalDependencies';
|
|
25
21
|
|
|
26
22
|
registerNativeHandlers({
|
|
@@ -31,6 +27,7 @@ registerNativeHandlers({
|
|
|
31
27
|
getLocalAssetUri,
|
|
32
28
|
getPhotos,
|
|
33
29
|
iOS14RefreshGallerySelection,
|
|
30
|
+
NetInfo,
|
|
34
31
|
oniOS14GalleryLibrarySelectionChange,
|
|
35
32
|
pickDocument,
|
|
36
33
|
pickImage,
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { PermissionsAndroid, Platform } from 'react-native';
|
|
2
|
+
import RNFS from 'react-native-fs';
|
|
2
3
|
let AudioRecorderPackage;
|
|
3
4
|
let audioRecorderPlayer;
|
|
4
5
|
|
|
5
|
-
let RNBlobUtil;
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
RNBlobUtil = require('react-native-blob-util').default;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
console.log('react-native-blob-util is not installed');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
try {
|
|
14
7
|
AudioRecorderPackage = require('react-native-audio-recorder-player').default;
|
|
15
8
|
audioRecorderPlayer = new AudioRecorderPackage();
|
|
@@ -204,7 +197,7 @@ class _Audio {
|
|
|
204
197
|
}
|
|
205
198
|
try {
|
|
206
199
|
const path = Platform.select({
|
|
207
|
-
android: `${
|
|
200
|
+
android: `${RNFS.CachesDirectoryPath}/sound.aac`,
|
|
208
201
|
ios: 'sound.aac',
|
|
209
202
|
});
|
|
210
203
|
const audioSet = {
|
|
@@ -256,4 +249,4 @@ class _Audio {
|
|
|
256
249
|
};
|
|
257
250
|
}
|
|
258
251
|
|
|
259
|
-
export const Audio = AudioRecorderPackage
|
|
252
|
+
export const Audio = AudioRecorderPackage ? new _Audio() : null;
|
|
@@ -5,7 +5,7 @@ try {
|
|
|
5
5
|
} catch (e) {
|
|
6
6
|
// do nothing
|
|
7
7
|
console.log(
|
|
8
|
-
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
|
|
8
|
+
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
|
|
9
9
|
);
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
} catch (e) {
|
|
8
8
|
// do nothing
|
|
9
9
|
console.log(
|
|
10
|
-
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
|
|
10
|
+
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
} catch (e) {
|
|
8
8
|
// do nothing
|
|
9
9
|
console.log(
|
|
10
|
-
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
|
|
10
|
+
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
export * from './Audio';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
2
|
+
export * from './shareImage';
|
|
3
|
+
export * from './Video';
|
|
4
|
+
export * from './triggerHaptic';
|
|
5
|
+
export * from './setClipboardString';
|
|
6
|
+
export * from './pickDocument';
|
|
4
7
|
export * from './getLocalAssetUri';
|
|
5
|
-
export * from './getPhotos';
|
|
6
8
|
export * from './iOS14RefreshGallerySelection';
|
|
7
9
|
export * from './oniOS14GalleryLibrarySelectionChange';
|
|
8
|
-
export * from './
|
|
10
|
+
export * from './getPhotos';
|
|
9
11
|
export * from './pickImage';
|
|
10
|
-
export * from './saveFile';
|
|
11
|
-
export * from './setClipboardString';
|
|
12
|
-
export * from './shareImage';
|
|
13
|
-
export * from './Sound';
|
|
14
12
|
export * from './takePhoto';
|
|
15
|
-
export * from './triggerHaptic';
|
|
16
|
-
export * from './Video';
|
|
@@ -7,7 +7,7 @@ try {
|
|
|
7
7
|
} catch (e) {
|
|
8
8
|
// do nothing
|
|
9
9
|
console.log(
|
|
10
|
-
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
|
|
10
|
+
'@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
|
|
11
11
|
);
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
+
import RNFS from 'react-native-fs';
|
|
2
3
|
|
|
3
4
|
let RNShare;
|
|
4
5
|
|
|
@@ -8,18 +9,10 @@ try {
|
|
|
8
9
|
console.log('react-native-share is not installed');
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
let RNBlobUtil;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
RNBlobUtil = require('react-native-blob-util').default;
|
|
15
|
-
} catch (e) {
|
|
16
|
-
console.log('react-native-blob-util is not installed');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
12
|
export const shareImage = RNShare
|
|
20
13
|
? async ({ type, url }) => {
|
|
21
14
|
try {
|
|
22
|
-
const base64Image = await
|
|
15
|
+
const base64Image = await RNFS.readFile(url, 'base64');
|
|
23
16
|
const base64Url = `data:${type};base64,${base64Image}`;
|
|
24
17
|
await RNShare.open({
|
|
25
18
|
activityItemSources:
|
|
@@ -42,6 +35,9 @@ export const shareImage = RNShare
|
|
|
42
35
|
},
|
|
43
36
|
]
|
|
44
37
|
: undefined,
|
|
38
|
+
// react-native-share has a typing issue, where their docs confirm that
|
|
39
|
+
// this property should be an array of strings, but the type is a string
|
|
40
|
+
// in the @types/react-native-share package.
|
|
45
41
|
excludedActivityTypes: [] as unknown as string,
|
|
46
42
|
failOnCancel: false,
|
|
47
43
|
type,
|
|
@@ -49,7 +45,7 @@ export const shareImage = RNShare
|
|
|
49
45
|
});
|
|
50
46
|
return true;
|
|
51
47
|
} catch (error) {
|
|
52
|
-
console.warn('Sharing failed...'
|
|
48
|
+
console.warn('Sharing failed...');
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
51
|
: null;
|
|
@@ -3,11 +3,9 @@ import { AppState, Image, PermissionsAndroid, Platform } from 'react-native';
|
|
|
3
3
|
let ImagePicker;
|
|
4
4
|
|
|
5
5
|
try {
|
|
6
|
-
ImagePicker = require('react-native-image-picker');
|
|
6
|
+
ImagePicker = require('react-native-image-crop-picker').default;
|
|
7
7
|
} catch (e) {
|
|
8
|
-
console.log(
|
|
9
|
-
'The package react-native-image-picker is not installed. Please install the same so as to take photo through camera and upload it.',
|
|
10
|
-
);
|
|
8
|
+
console.log('react-native-image-crop-picker is not installed');
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
export const takePhoto = ImagePicker
|
|
@@ -28,22 +26,20 @@ export const takePhoto = ImagePicker
|
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
28
|
try {
|
|
31
|
-
const
|
|
32
|
-
|
|
29
|
+
const photo = await ImagePicker.openCamera({
|
|
30
|
+
compressImageQuality: Math.min(Math.max(0, compressImageQuality), 1),
|
|
33
31
|
});
|
|
34
|
-
if (
|
|
35
|
-
return {
|
|
36
|
-
cancelled: true,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
const photo = result.assets[0];
|
|
40
|
-
if (photo.height && photo.width && photo.uri) {
|
|
32
|
+
if (photo.height && photo.width && photo.path) {
|
|
41
33
|
let size: { height?: number; width?: number } = {};
|
|
42
34
|
if (Platform.OS === 'android') {
|
|
43
35
|
// Height and width returned by ImagePicker are incorrect on Android.
|
|
36
|
+
// The issue is described in following github issue:
|
|
37
|
+
// https://github.com/ivpusic/react-native-image-crop-picker/issues/901
|
|
38
|
+
// This we can't rely on them as it is, and we need to use Image.getSize
|
|
39
|
+
// to get accurate size.
|
|
44
40
|
const getSize = (): Promise<{ height: number; width: number }> =>
|
|
45
41
|
new Promise((resolve) => {
|
|
46
|
-
Image.getSize(photo.
|
|
42
|
+
Image.getSize(photo.path, (width, height) => {
|
|
47
43
|
resolve({ height, width });
|
|
48
44
|
});
|
|
49
45
|
});
|
|
@@ -66,7 +62,7 @@ export const takePhoto = ImagePicker
|
|
|
66
62
|
cancelled: false,
|
|
67
63
|
size: photo.size,
|
|
68
64
|
source: 'camera',
|
|
69
|
-
uri: photo.
|
|
65
|
+
uri: photo.path,
|
|
70
66
|
...size,
|
|
71
67
|
};
|
|
72
68
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { FlatList as DefaultFlatList, Platform } from 'react-native';
|
|
2
|
-
let FlatList;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (Platform.constants.reactNativeVersion.minor < 72) {
|
|
6
|
-
const upgradeLog =
|
|
7
|
-
"'@stream-io/flat-list-mvcp' is deprecated, please upgrade your react-native version to >0.71 to get same the benefits on the default FlatList and uninstall the package.";
|
|
8
|
-
try {
|
|
9
|
-
FlatList = require('@stream-io/flat-list-mvcp').FlatList;
|
|
10
|
-
console.log(upgradeLog);
|
|
11
|
-
} catch (error) {
|
|
12
|
-
console.log(
|
|
13
|
-
`@stream-io/flat-list-mvcp not found, using react-native's FlatList. This library is used to achieve bi-directional infinite scrolling on lower react native versions. ${upgradeLog}`,
|
|
14
|
-
);
|
|
15
|
-
FlatList = require('react-native').FlatList;
|
|
16
|
-
}
|
|
17
|
-
} else {
|
|
18
|
-
FlatList = DefaultFlatList;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { FlatList };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
let RNBlobUtil;
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
RNBlobUtil = require('react-native-blob-util').default;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
console.log('react-native-blob-util is not installed');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const deleteFile = RNBlobUtil
|
|
10
|
-
? async ({ uri }) => {
|
|
11
|
-
try {
|
|
12
|
-
await RNBlobUtil.fs.unlink(uri);
|
|
13
|
-
return true;
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.log('File deletion failed...', error);
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
: null;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
let RNBlobUtil;
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
RNBlobUtil = require('react-native-blob-util').default;
|
|
5
|
-
} catch (e) {
|
|
6
|
-
console.log('react-native-blob-util is not installed');
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const saveFile = RNBlobUtil
|
|
10
|
-
? async ({ fileName, fromUrl }) => {
|
|
11
|
-
try {
|
|
12
|
-
const path = RNBlobUtil.fs.dirs.CacheDir + '/' + encodeURIComponent(fileName);
|
|
13
|
-
await RNBlobUtil.config({
|
|
14
|
-
fileCache: true,
|
|
15
|
-
path,
|
|
16
|
-
}).fetch('GET', fromUrl);
|
|
17
|
-
|
|
18
|
-
return path;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.log('Downloading image failed...', error);
|
|
21
|
-
throw new Error('Downloading image failed...');
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
: null;
|
|
File without changes
|