stream-chat-react-native 5.22.0-beta.3 → 5.22.0-beta.4

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 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.22.0-beta.3",
4
+ "version": "5.22.0-beta.4",
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.22.0-beta.3"
14
+ "stream-chat-react-native-core": "5.22.0-beta.4"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@react-native-camera-roll/camera-roll": ">=5.0.0",
@@ -1,47 +1,72 @@
1
- import { Image, Platform } from 'react-native';
1
+ import { AppState, Image, Linking, PermissionsAndroid, Platform } from 'react-native';
2
2
  import ImagePicker from 'react-native-image-crop-picker';
3
3
 
4
- export const takePhoto = async ({ compressImageQuality = Platform.OS === 'ios' ? 0.8 : 1 }) => {
5
- const photo = await ImagePicker.openCamera({
6
- compressImageQuality: Math.min(Math.max(0, compressImageQuality), 1),
7
- });
4
+ let hadDeniedAndroidPermission = false;
8
5
 
9
- if (photo.height && photo.width && photo.path) {
10
- let size: { height?: number; width?: number } = {};
11
- if (Platform.OS === 'android') {
12
- // Height and width returned by ImagePicker are incorrect on Android.
13
- // The issue is described in following github issue:
14
- // https://github.com/ivpusic/react-native-image-crop-picker/issues/901
15
- // This we can't rely on them as it is, and we need to use Image.getSize
16
- // to get accurate size.
17
- const getSize = (): Promise<{ height: number; width: number }> =>
18
- new Promise((resolve) => {
19
- Image.getSize(photo.path, (width, height) => {
20
- resolve({ height, width });
6
+ export const takePhoto = async ({ compressImageQuality = Platform.OS === 'ios' ? 0.8 : 1 }) => {
7
+ if (Platform.OS === 'android') {
8
+ const cameraPermissions = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA);
9
+ if (!cameraPermissions) {
10
+ const androidPermissionStatus = await PermissionsAndroid.request(
11
+ PermissionsAndroid.PERMISSIONS.CAMERA,
12
+ );
13
+ if (androidPermissionStatus === PermissionsAndroid.RESULTS.DENIED) {
14
+ hadDeniedAndroidPermission = true;
15
+ return { cancelled: true };
16
+ } else if (androidPermissionStatus === PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN) {
17
+ if (!hadDeniedAndroidPermission) {
18
+ Linking.openSettings();
19
+ }
20
+ return { cancelled: true };
21
+ }
22
+ }
23
+ }
24
+ try {
25
+ const photo = await ImagePicker.openCamera({
26
+ compressImageQuality: Math.min(Math.max(0, compressImageQuality), 1),
27
+ });
28
+ if (photo.height && photo.width && photo.path) {
29
+ let size: { height?: number; width?: number } = {};
30
+ if (Platform.OS === 'android') {
31
+ // Height and width returned by ImagePicker are incorrect on Android.
32
+ // The issue is described in following github issue:
33
+ // https://github.com/ivpusic/react-native-image-crop-picker/issues/901
34
+ // This we can't rely on them as it is, and we need to use Image.getSize
35
+ // to get accurate size.
36
+ const getSize = (): Promise<{ height: number; width: number }> =>
37
+ new Promise((resolve) => {
38
+ Image.getSize(photo.path, (width, height) => {
39
+ resolve({ height, width });
40
+ });
21
41
  });
22
- });
23
42
 
24
- try {
25
- const { height, width } = await getSize();
26
- size.height = height;
27
- size.width = width;
28
- } catch (e) {
29
- // do nothing
30
- console.warn('Error get image size of picture caputred from camera ', e);
43
+ try {
44
+ const { height, width } = await getSize();
45
+ size.height = height;
46
+ size.width = width;
47
+ } catch (e) {
48
+ // do nothing
49
+ console.warn('Error get image size of picture caputred from camera ', e);
50
+ }
51
+ } else {
52
+ size = {
53
+ height: photo.height,
54
+ width: photo.width,
55
+ };
31
56
  }
32
- } else {
33
- size = {
34
- height: photo.height,
35
- width: photo.width,
57
+ return {
58
+ cancelled: false,
59
+ source: 'camera',
60
+ uri: photo.path,
61
+ ...size,
36
62
  };
37
63
  }
38
-
39
- return {
40
- cancelled: false,
41
- source: 'camera',
42
- uri: photo.path,
43
- ...size,
44
- };
64
+ } catch (e: unknown) {
65
+ // on iOS: if it was in inactive state, then the user had just denied the permissions
66
+ if (Platform.OS === 'ios' && AppState.currentState === 'active') {
67
+ await Linking.openSettings();
68
+ }
45
69
  }
70
+
46
71
  return { cancelled: true };
47
72
  };