stream-chat-react-native 6.1.2-beta.3 → 6.2.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/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": "6.1.2-beta.3",
4
+ "version": "6.2.0-beta.1",
5
5
  "homepage": "https://www.npmjs.com/package/stream-chat-react-native",
6
6
  "author": {
7
7
  "company": "Stream.io Inc",
@@ -20,7 +20,7 @@
20
20
  "types": "types/index.d.ts",
21
21
  "dependencies": {
22
22
  "es6-symbol": "^3.1.3",
23
- "stream-chat-react-native-core": "6.1.2-beta.3"
23
+ "stream-chat-react-native-core": "6.2.0-beta.1"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@react-native-camera-roll/camera-roll": ">=7.8.0",
@@ -6,12 +6,15 @@ try {
6
6
  ImagePicker = require('react-native-image-picker');
7
7
  } catch (e) {
8
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.',
9
+ 'The package react-native-image-picker is not installed. Installing this package will enable capturing photos and videos(for iOS) through the app, and thereby send it.',
10
10
  );
11
11
  }
12
12
 
13
13
  export const takePhoto = ImagePicker
14
- ? async ({ compressImageQuality = Platform.OS === 'ios' ? 0.8 : 1 }) => {
14
+ ? async ({
15
+ compressImageQuality = Platform.OS === 'ios' ? 0.8 : 1,
16
+ mediaType = Platform.OS === 'ios' ? 'mixed' : 'image',
17
+ }) => {
15
18
  if (Platform.OS === 'android') {
16
19
  const cameraPermissions = await PermissionsAndroid.check(
17
20
  PermissionsAndroid.PERMISSIONS.CAMERA,
@@ -29,46 +32,68 @@ export const takePhoto = ImagePicker
29
32
  }
30
33
  try {
31
34
  const result = await ImagePicker.launchCamera({
35
+ mediaType,
32
36
  quality: Math.min(Math.max(0, compressImageQuality), 1),
33
37
  });
34
- if (!result.assets.length) {
38
+ if (!result || !result.assets || !result.assets.length || result.didCancel) {
35
39
  return {
36
40
  cancelled: true,
37
41
  };
38
42
  }
39
- const photo = result.assets[0];
40
- if (photo.height && photo.width && photo.uri) {
41
- let size: { height?: number; width?: number } = {};
42
- if (Platform.OS === 'android') {
43
- // Height and width returned by ImagePicker are incorrect on Android.
44
- const getSize = (): Promise<{ height: number; width: number }> =>
45
- new Promise((resolve) => {
46
- Image.getSize(photo.uri, (width, height) => {
47
- resolve({ height, width });
43
+ const asset = result.assets[0];
44
+ if (!asset) {
45
+ return {
46
+ cancelled: true,
47
+ };
48
+ }
49
+ if (asset.type.includes('video')) {
50
+ const clearFilter = new RegExp('[.:]', 'g');
51
+ const date = new Date().toISOString().replace(clearFilter, '_');
52
+ return {
53
+ ...asset,
54
+ cancelled: false,
55
+ duration: asset.duration * 1000,
56
+ name: 'video_recording_' + date + asset.fileName.split('.').pop(),
57
+ size: asset.fileSize,
58
+ source: 'camera',
59
+ type: asset.type,
60
+ uri: asset.uri,
61
+ };
62
+ } else {
63
+ if (asset.height && asset.width && asset.uri) {
64
+ let size: { height?: number; width?: number } = {};
65
+ if (Platform.OS === 'android') {
66
+ // Height and width returned by ImagePicker are incorrect on Android.
67
+ const getSize = (): Promise<{ height: number; width: number }> =>
68
+ new Promise((resolve) => {
69
+ Image.getSize(asset.uri, (width, height) => {
70
+ resolve({ height, width });
71
+ });
48
72
  });
49
- });
50
73
 
51
- try {
52
- const { height, width } = await getSize();
53
- size.height = height;
54
- size.width = width;
55
- } catch (e) {
56
- // do nothing
57
- console.warn('Error get image size of picture caputred from camera ', e);
74
+ try {
75
+ const { height, width } = await getSize();
76
+ size.height = height;
77
+ size.width = width;
78
+ } catch (e) {
79
+ // do nothing
80
+ console.warn('Error get image size of picture caputred from camera ', e);
81
+ }
82
+ } else {
83
+ size = {
84
+ height: asset.height,
85
+ width: asset.width,
86
+ };
58
87
  }
59
- } else {
60
- size = {
61
- height: photo.height,
62
- width: photo.width,
88
+ return {
89
+ cancelled: false,
90
+ size: asset.size,
91
+ source: 'camera',
92
+ type: asset.type,
93
+ uri: asset.uri,
94
+ ...size,
63
95
  };
64
96
  }
65
- return {
66
- cancelled: false,
67
- size: photo.size,
68
- source: 'camera',
69
- uri: photo.uri,
70
- ...size,
71
- };
72
97
  }
73
98
  } catch (e: unknown) {
74
99
  if (e instanceof Error) {