stream-chat-react-native 5.22.0-beta.3 → 5.22.0-beta.5
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 +10 -5
- package/package.json +2 -2
- package/src/handlers/takePhoto.ts +61 -36
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
[](https://www.npmjs.com/package/stream-chat-react-native)
|
|
12
|
-
[](https://github.com/GetStream/stream-chat-react-native/actions)
|
|
13
13
|
[](https://getstream.io/chat/docs/sdk/reactnative)
|
|
14
14
|
|
|
15
15
|
<img align="right" src="https://getstream.imgix.net/images/ios-chat-tutorial/iphone_chat_art@3x.png?auto=format,enhance" width="50%" />
|
|
@@ -25,10 +25,15 @@
|
|
|
25
25
|
|
|
26
26
|
## Contents
|
|
27
27
|
|
|
28
|
-
- [React Native Chat
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
28
|
+
- [Official React Native SDK for Stream Chat](#official-react-native-sdk-for-stream-chat)
|
|
29
|
+
- [Contents](#contents)
|
|
30
|
+
- [📖 React Native Chat Tutorial](#-react-native-chat-tutorial)
|
|
31
|
+
- [Free for Makers](#free-for-makers)
|
|
32
|
+
- [🔮 Example Apps](#-example-apps)
|
|
33
|
+
- [💬 Keep in mind](#-keep-in-mind)
|
|
34
|
+
- [👏 Contributing](#-contributing)
|
|
35
|
+
- [Git flow \& Release process](#git-flow--release-process)
|
|
36
|
+
- [We are hiring](#we-are-hiring)
|
|
32
37
|
|
|
33
38
|
## 📖 React Native Chat Tutorial
|
|
34
39
|
|
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.
|
|
4
|
+
"version": "5.22.0-beta.5",
|
|
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.
|
|
14
|
+
"stream-chat-react-native-core": "5.22.0-beta.5"
|
|
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
|
-
|
|
5
|
-
const photo = await ImagePicker.openCamera({
|
|
6
|
-
compressImageQuality: Math.min(Math.max(0, compressImageQuality), 1),
|
|
7
|
-
});
|
|
4
|
+
let hadDeniedAndroidPermission = false;
|
|
8
5
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
57
|
+
return {
|
|
58
|
+
cancelled: false,
|
|
59
|
+
source: 'camera',
|
|
60
|
+
uri: photo.path,
|
|
61
|
+
...size,
|
|
36
62
|
};
|
|
37
63
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
};
|