stream-chat-react-native 4.0.0-beta.1 → 4.0.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +36 -6
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": "4.0.0-beta.1",
4
+ "version": "4.0.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": "4.0.0-beta.1"
14
+ "stream-chat-react-native-core": "4.0.0-beta.5"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@react-native-community/cameraroll": ">=4.0.1",
package/src/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import React from 'react';
2
- import { PermissionsAndroid, Platform } from 'react-native';
3
- import CameraRoll from '@react-native-community/cameraroll';
4
- import NetInfo from '@react-native-community/netinfo';
5
- import { FlatList } from '@stream-io/flat-list-mvcp';
2
+ import { Image, PermissionsAndroid, Platform } from 'react-native';
3
+
6
4
  import DocumentPicker from 'react-native-document-picker';
7
5
  import RNFS from 'react-native-fs';
8
6
  import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
9
7
  import ImagePicker from 'react-native-image-crop-picker';
10
8
  import ImageResizer from 'react-native-image-resizer';
11
9
  import RNShare from 'react-native-share';
10
+
11
+ import CameraRoll from '@react-native-community/cameraroll';
12
+ import NetInfo from '@react-native-community/netinfo';
13
+ import { FlatList } from '@stream-io/flat-list-mvcp';
12
14
  import { registerNativeHandlers } from 'stream-chat-react-native-core';
13
15
 
14
16
  registerNativeHandlers({
@@ -199,13 +201,41 @@ registerNativeHandlers({
199
201
  const photo = await ImagePicker.openCamera({
200
202
  compressImageQuality: Math.min(Math.max(0, compressImageQuality), 1),
201
203
  });
204
+
202
205
  if (photo.height && photo.width && photo.path) {
206
+ let size = {};
207
+ if (Platform.OS === 'android') {
208
+ // Height and width returned by ImagePicker are incorrect on Android.
209
+ // The issue is described in following github issue:
210
+ // https://github.com/ivpusic/react-native-image-crop-picker/issues/901
211
+ // This we can't rely on them as it is, and we need to use Image.getSize
212
+ // to get accurate size.
213
+ const getSize = () => new Promise((resolve) => {
214
+ Image.getSize(photo.path, (width, height) => {
215
+ resolve({height, width});
216
+ });
217
+ });
218
+
219
+ try {
220
+ const { height, width } = await getSize();
221
+ size.height = height;
222
+ size.width = width;
223
+ } catch (e) {
224
+ // do nothing
225
+ console.warning('Error get image size of picture caputred from camera ', e);
226
+ }
227
+ } else {
228
+ size = {
229
+ height: photo.height,
230
+ width: photo.width,
231
+ };
232
+ }
233
+
203
234
  return {
204
235
  cancelled: false,
205
- height: photo.height,
206
236
  source: 'camera',
207
237
  uri: photo.path,
208
- width: photo.width,
238
+ ...size,
209
239
  };
210
240
  }
211
241
  return { cancelled: true };