stream-chat-expo 6.1.2-beta.3 → 6.2.0

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-expo",
3
3
  "description": "The official Expo SDK for Stream Chat, a service for building chat applications",
4
- "version": "6.1.2-beta.3",
4
+ "version": "6.2.0",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -10,7 +10,7 @@
10
10
  "main": "src/index.js",
11
11
  "types": "types/index.d.ts",
12
12
  "dependencies": {
13
- "stream-chat-react-native-core": "6.1.2-beta.3"
13
+ "stream-chat-react-native-core": "6.2.0"
14
14
  },
15
15
  "peerDependencies": {
16
16
  "expo": ">=51.0.0",
@@ -10,7 +10,7 @@ try {
10
10
 
11
11
  if (!ImagePicker) {
12
12
  console.log(
13
- 'expo-image-picker is not installed. Installing this package will enable campturing photos through the app, and thereby send it.',
13
+ 'expo-image-picker is not installed. Installing this package will enable capturing photos and videos(for iOS) through the app, and thereby send it.',
14
14
  );
15
15
  }
16
16
 
@@ -19,8 +19,15 @@ type Size = {
19
19
  width?: number;
20
20
  };
21
21
 
22
+ // Media type mapping for iOS and Android
23
+ const mediaTypeMap = {
24
+ image: 'images',
25
+ mixed: ['images', 'videos'],
26
+ video: 'videos',
27
+ };
28
+
22
29
  export const takePhoto = ImagePicker
23
- ? async ({ compressImageQuality = 1 }) => {
30
+ ? async ({ compressImageQuality = 1, mediaType = Platform.OS === 'ios' ? 'mixed' : 'image' }) => {
24
31
  try {
25
32
  const permissionCheck = await ImagePicker.getCameraPermissionsAsync();
26
33
  const canRequest = permissionCheck.canAskAgain;
@@ -35,45 +42,65 @@ export const takePhoto = ImagePicker
35
42
  }
36
43
 
37
44
  if (permissionGranted) {
38
- const imagePickerSuccessResult = await ImagePicker.launchCameraAsync({
45
+ const result = await ImagePicker.launchCameraAsync({
46
+ mediaTypes: mediaTypeMap[mediaType],
39
47
  quality: Math.min(Math.max(0, compressImageQuality), 1),
40
48
  });
41
- const canceled = imagePickerSuccessResult.canceled;
42
- const assets = imagePickerSuccessResult.assets;
49
+ if (!result || !result.assets || !result.assets.length || result.canceled) {
50
+ return { cancelled: true };
51
+ }
43
52
  // since we only support single photo upload for now we will only be focusing on 0'th element.
44
- const photo = assets && assets[0];
45
-
46
- if (canceled === false && photo && photo.height && photo.width && photo.uri) {
47
- let size: Size = {};
48
- if (Platform.OS === 'android') {
49
- const getSize = (): Promise<Size> =>
50
- new Promise((resolve) => {
51
- Image.getSize(photo.uri, (width, height) => {
52
- resolve({ height, width });
53
- });
54
- });
55
-
56
- try {
57
- const { height, width } = await getSize();
58
- size.height = height;
59
- size.width = width;
60
- } catch (e) {
61
- console.warn('Error get image size of picture caputred from camera ', e);
62
- }
63
- } else {
64
- size = {
65
- height: photo.height,
66
- width: photo.width,
67
- };
68
- }
69
-
53
+ const photo = result.assets[0];
54
+ if (!photo) {
55
+ return { cancelled: true };
56
+ }
57
+ if (photo.mimeType.includes('video')) {
58
+ const clearFilter = new RegExp('[.:]', 'g');
59
+ const date = new Date().toISOString().replace(clearFilter, '_');
70
60
  return {
61
+ ...photo,
71
62
  cancelled: false,
63
+ duration: photo.duration, // in milliseconds
64
+ name: 'video_recording_' + date + photo.uri.split('.').pop(),
72
65
  size: photo.fileSize,
73
66
  source: 'camera',
67
+ type: photo.mimeType,
74
68
  uri: photo.uri,
75
- ...size,
76
69
  };
70
+ } else {
71
+ if (photo && photo.height && photo.width && photo.uri) {
72
+ let size: Size = {};
73
+ if (Platform.OS === 'android') {
74
+ const getSize = (): Promise<Size> =>
75
+ new Promise((resolve) => {
76
+ Image.getSize(photo.uri, (width, height) => {
77
+ resolve({ height, width });
78
+ });
79
+ });
80
+
81
+ try {
82
+ const { height, width } = await getSize();
83
+ size.height = height;
84
+ size.width = width;
85
+ } catch (e) {
86
+ console.warn('Error get image size of picture caputred from camera ', e);
87
+ }
88
+ } else {
89
+ size = {
90
+ height: photo.height,
91
+ width: photo.width,
92
+ };
93
+ }
94
+
95
+ return {
96
+ cancelled: false,
97
+ size: photo.fileSize,
98
+ source: 'camera',
99
+ type: photo.mimeType,
100
+ uri: photo.uri,
101
+ ...size,
102
+ };
103
+ }
77
104
  }
78
105
  }
79
106
  } catch (error) {