stream-chat-react-native 5.12.1 → 5.13.0-beta.2
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/package.json +2 -2
- package/src/handlers/getPhotos.ts +48 -12
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.13.0-beta.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"company": "Stream.io Inc",
|
|
7
7
|
"name": "Stream.io Inc"
|
|
@@ -11,7 +11,7 @@
|
|
|
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.13.0-beta.2"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@react-native-camera-roll/camera-roll": ">=5.0.0",
|
|
@@ -2,23 +2,59 @@ import { PermissionsAndroid, Platform } from 'react-native';
|
|
|
2
2
|
|
|
3
3
|
import { CameraRoll, GetPhotosParams } from '@react-native-camera-roll/camera-roll';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
const verifyAndroidPermissions = async () => {
|
|
6
|
+
const isRN71orAbove = Platform.constants.reactNativeVersion?.minor >= 71;
|
|
7
|
+
const isAndroid13orAbove = Platform.Version >= 33;
|
|
8
|
+
const shouldCheckForMediaPermissions = isRN71orAbove && isAndroid13orAbove;
|
|
9
|
+
const getCheckPermissionPromise = () => {
|
|
10
|
+
if (shouldCheckForMediaPermissions) {
|
|
11
|
+
return Promise.all([
|
|
12
|
+
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES),
|
|
13
|
+
PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO),
|
|
14
|
+
]).then(
|
|
15
|
+
([hasReadMediaImagesPermission, hasReadMediaVideoPermission]) =>
|
|
16
|
+
hasReadMediaImagesPermission && hasReadMediaVideoPermission,
|
|
17
|
+
);
|
|
18
|
+
} else {
|
|
19
|
+
return PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const hasPermission = await getCheckPermissionPromise();
|
|
23
|
+
if (!hasPermission) {
|
|
24
|
+
const getRequestPermissionPromise = () => {
|
|
25
|
+
if (shouldCheckForMediaPermissions) {
|
|
26
|
+
return PermissionsAndroid.requestMultiple([
|
|
27
|
+
PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES,
|
|
28
|
+
PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO,
|
|
29
|
+
]).then(
|
|
30
|
+
(statuses) =>
|
|
31
|
+
statuses[PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES] ===
|
|
32
|
+
PermissionsAndroid.RESULTS.GRANTED &&
|
|
33
|
+
statuses[PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO] ===
|
|
34
|
+
PermissionsAndroid.RESULTS.GRANTED,
|
|
35
|
+
);
|
|
36
|
+
} else {
|
|
37
|
+
return PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, {
|
|
13
38
|
buttonNegative: 'Deny',
|
|
14
39
|
buttonNeutral: 'Ask Me Later',
|
|
15
40
|
buttonPositive: 'Allow',
|
|
16
41
|
message: 'Permissions are required to access and share photos.',
|
|
17
42
|
title: 'Photos Access',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
43
|
+
}).then((status) => status === PermissionsAndroid.RESULTS.GRANTED);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const granted = await getRequestPermissionPromise();
|
|
47
|
+
return granted;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const getPhotos = async ({ after, first }: Pick<GetPhotosParams, 'after' | 'first'>) => {
|
|
53
|
+
try {
|
|
54
|
+
if (Platform.OS === 'android') {
|
|
55
|
+
const granted = await verifyAndroidPermissions();
|
|
56
|
+
if (!granted) {
|
|
57
|
+
throw new Error('getPhotos Error');
|
|
22
58
|
}
|
|
23
59
|
}
|
|
24
60
|
const results = await CameraRoll.getPhotos({
|