stream-chat-react-native 5.44.2 → 6.0.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.
Files changed (40) hide show
  1. package/README.md +1 -2
  2. package/android/build.gradle +103 -0
  3. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/streamchatreactnative/StreamChatReactNative.java +594 -0
  7. package/android/src/main/java/com/streamchatreactnative/StreamChatReactNativeModule.java +111 -0
  8. package/android/src/main/java/com/streamchatreactnative/StreamChatReactNativePackage.java +45 -0
  9. package/android/src/newarch/com/streamchatreactnative/StreamChatReactNative.java +9 -0
  10. package/android/src/oldarch/com/streamchatreactnative/StreamChatReactNative.java +16 -0
  11. package/ios/ImageHelpers.h +57 -0
  12. package/ios/ImageHelpers.m +179 -0
  13. package/ios/StreamChatReactNative.h +13 -0
  14. package/ios/StreamChatReactNative.mm +417 -0
  15. package/ios/StreamChatReactNative.xcodeproj/project.pbxproj +280 -0
  16. package/package.json +31 -21
  17. package/src/handlers/compressImage.ts +3 -4
  18. package/src/handlers/index.ts +0 -5
  19. package/src/index.js +6 -3
  20. package/src/native/NativeStreamChatReactNative.ts +24 -0
  21. package/src/native/index.tsx +48 -0
  22. package/src/native/types.ts +32 -0
  23. package/src/optionalDependencies/Audio.ts +10 -4
  24. package/src/optionalDependencies/FlatList.ts +21 -0
  25. package/src/{handlers → optionalDependencies}/Sound.tsx +1 -1
  26. package/src/{handlers → optionalDependencies}/Video.tsx +1 -1
  27. package/src/optionalDependencies/deleteFile.ts +19 -0
  28. package/src/optionalDependencies/getLocalAssetUri.ts +8 -3
  29. package/src/optionalDependencies/getPhotos.ts +20 -10
  30. package/src/optionalDependencies/iOS14RefreshGallerySelection.ts +1 -1
  31. package/src/optionalDependencies/index.ts +10 -6
  32. package/src/optionalDependencies/oniOS14GalleryLibrarySelectionChange.ts +1 -1
  33. package/src/optionalDependencies/saveFile.ts +24 -0
  34. package/src/optionalDependencies/shareImage.ts +10 -6
  35. package/src/optionalDependencies/takePhoto.ts +15 -11
  36. package/stream-chat-react-native.podspec +38 -0
  37. package/src/handlers/NetInfo.ts +0 -43
  38. package/src/handlers/deleteFile.ts +0 -11
  39. package/src/handlers/saveFile.ts +0 -11
  40. /package/src/optionalDependencies/{Video.ts → AudioVideo.ts} +0 -0
package/package.json CHANGED
@@ -1,32 +1,38 @@
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.44.2",
4
+ "version": "6.0.0-beta.1",
5
+ "homepage": "https://www.npmjs.com/package/stream-chat-react-native",
5
6
  "author": {
6
7
  "company": "Stream.io Inc",
7
8
  "name": "Stream.io Inc"
8
9
  },
10
+ "files": [
11
+ "src",
12
+ "types",
13
+ "android",
14
+ "ios",
15
+ "*.podspec",
16
+ "package.json"
17
+ ],
9
18
  "license": "SEE LICENSE IN LICENSE",
10
19
  "main": "src/index.js",
11
20
  "types": "types/index.d.ts",
12
21
  "dependencies": {
13
22
  "es6-symbol": "^3.1.3",
14
- "stream-chat-react-native-core": "5.44.2"
23
+ "stream-chat-react-native-core": "6.0.0-beta.1"
15
24
  },
16
25
  "peerDependencies": {
17
- "@react-native-camera-roll/camera-roll": ">=5.0.0",
18
- "@react-native-clipboard/clipboard": "^1.11.1",
19
- "@react-native-community/netinfo": ">=2.0.7",
20
- "@stream-io/flat-list-mvcp": "^0.10.3",
21
- "react-native": ">=0.60.0",
26
+ "@react-native-camera-roll/camera-roll": ">=7.8.0",
27
+ "@react-native-clipboard/clipboard": ">=1.14.1",
28
+ "@stream-io/flat-list-mvcp": ">=0.10.3",
29
+ "react-native": ">=0.67.0",
22
30
  "react-native-audio-recorder-player": ">=3.6.4",
23
- "react-native-document-picker": ">=9.0.1",
24
- "react-native-fs": ">=2.16.6",
25
- "react-native-haptic-feedback": ">=1.11.0",
31
+ "react-native-blob-util": ">=0.19.9",
32
+ "react-native-document-picker": ">=9.3.0",
33
+ "react-native-haptic-feedback": ">=2.2.0",
26
34
  "react-native-image-picker": ">=7.1.2",
27
- "react-native-image-crop-picker": ">=0.33.2",
28
- "react-native-image-resizer": ">=1.4.2",
29
- "react-native-share": ">=4.1.0",
35
+ "react-native-share": ">=10.2.1",
30
36
  "react-native-video": ">=6.4.2"
31
37
  },
32
38
  "peerDependenciesMeta": {
@@ -36,6 +42,9 @@
36
42
  "@react-native-clipboard/clipboard": {
37
43
  "optional": true
38
44
  },
45
+ "@stream-io/flat-list-mvcp": {
46
+ "optional": true
47
+ },
39
48
  "react-native-share": {
40
49
  "optional": true
41
50
  },
@@ -48,14 +57,14 @@
48
57
  "react-native-image-picker": {
49
58
  "optional": true
50
59
  },
51
- "react-native-image-crop-picker": {
52
- "optional": true
53
- },
54
60
  "react-native-audio-recorder-player": {
55
61
  "optional": true
56
62
  },
57
63
  "react-native-video": {
58
64
  "optional": true
65
+ },
66
+ "react-native-blob-util": {
67
+ "optional": true
59
68
  }
60
69
  },
61
70
  "scripts": {
@@ -63,10 +72,11 @@
63
72
  "postpack": "rm README.md"
64
73
  },
65
74
  "devDependencies": {
66
- "@react-native-community/netinfo": ">=2.0.7",
67
- "@stream-io/flat-list-mvcp": "0.10.3",
68
- "react-native": ">=0.60.0",
69
- "react-native-fs": ">=2.16.6",
70
- "react-native-image-resizer": ">=1.4.2"
75
+ "react-native": ">=0.67.0"
76
+ },
77
+ "codegenConfig": {
78
+ "name": "StreamChatReactNativeSpec",
79
+ "type": "modules",
80
+ "jsSrcsDir": "src/native"
71
81
  }
72
82
  }
@@ -1,5 +1,4 @@
1
- // @ts-ignore this module does not have a type declaration
2
- import ImageResizer from 'react-native-image-resizer';
1
+ import StreamChatReactNative from '../native';
3
2
 
4
3
  type CompressImageParams = {
5
4
  compressImageQuality: number;
@@ -15,7 +14,7 @@ export const compressImage = async ({
15
14
  width,
16
15
  }: CompressImageParams) => {
17
16
  try {
18
- const { uri: compressedUri } = await ImageResizer.createResizedImage(
17
+ const { uri: compressedUri } = await StreamChatReactNative.createResizedImage(
19
18
  uri,
20
19
  width,
21
20
  height,
@@ -28,7 +27,7 @@ export const compressImage = async ({
28
27
  );
29
28
  return compressedUri;
30
29
  } catch (error) {
31
- console.log(error);
30
+ console.log('Error resizing image:', error);
32
31
  return uri;
33
32
  }
34
33
  };
@@ -1,6 +1 @@
1
- export * from './deleteFile';
2
1
  export * from './compressImage';
3
- export * from './NetInfo';
4
- export * from './saveFile';
5
- export * from './Sound';
6
- export * from './Video';
package/src/index.js CHANGED
@@ -1,22 +1,26 @@
1
1
  import { Platform } from 'react-native';
2
2
 
3
- import { FlatList } from '@stream-io/flat-list-mvcp';
4
3
  import { registerNativeHandlers } from 'stream-chat-react-native-core';
5
4
 
6
- import { compressImage, deleteFile, NetInfo, saveFile, Sound, Video } from './handlers';
5
+ import { compressImage } from './handlers';
7
6
 
8
7
  import {
9
8
  Audio,
9
+ deleteFile,
10
+ FlatList,
10
11
  getLocalAssetUri,
11
12
  getPhotos,
12
13
  iOS14RefreshGallerySelection,
13
14
  oniOS14GalleryLibrarySelectionChange,
14
15
  pickDocument,
15
16
  pickImage,
17
+ saveFile,
16
18
  setClipboardString,
17
19
  shareImage,
20
+ Sound,
18
21
  takePhoto,
19
22
  triggerHaptic,
23
+ Video,
20
24
  } from './optionalDependencies';
21
25
 
22
26
  registerNativeHandlers({
@@ -27,7 +31,6 @@ registerNativeHandlers({
27
31
  getLocalAssetUri,
28
32
  getPhotos,
29
33
  iOS14RefreshGallerySelection,
30
- NetInfo,
31
34
  oniOS14GalleryLibrarySelectionChange,
32
35
  pickDocument,
33
36
  pickImage,
@@ -0,0 +1,24 @@
1
+ import type { TurboModule } from 'react-native';
2
+
3
+ import { TurboModuleRegistry } from 'react-native';
4
+
5
+ export interface Spec extends TurboModule {
6
+ createResizedImage(
7
+ uri: string,
8
+ width: number,
9
+ height: number,
10
+ format: string,
11
+ quality: number,
12
+ mode: string,
13
+ onlyScaleDown: boolean,
14
+ rotation?: number,
15
+ outputPath?: string | null,
16
+ keepMeta?: boolean,
17
+ ): Promise<{
18
+ base64: string;
19
+ height: number;
20
+ name: string;
21
+ }>;
22
+ }
23
+
24
+ export default TurboModuleRegistry.getEnforcing<Spec>('StreamChatReactNative');
@@ -0,0 +1,48 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ import type { Options, ResizeFormat, Response } from './types';
4
+ export type { ResizeFormat, ResizeMode, Response } from './types';
5
+
6
+ // @ts-ignore
7
+ // eslint-disable-next-line no-underscore-dangle
8
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
9
+
10
+ const ImageResizer = isTurboModuleEnabled
11
+ ? require('./NativeStreamChatReactNative').default
12
+ : NativeModules.StreamChatReactNative;
13
+
14
+ const defaultOptions: Options = {
15
+ mode: 'contain',
16
+ onlyScaleDown: false,
17
+ };
18
+
19
+ async function createResizedImage(
20
+ uri: string,
21
+ width: number,
22
+ height: number,
23
+ format: ResizeFormat,
24
+ quality: number,
25
+ rotation: number = 0,
26
+ outputPath?: string | null,
27
+ keepMeta = false,
28
+ options: Options = defaultOptions,
29
+ ): Promise<Response> {
30
+ const { mode, onlyScaleDown } = { ...defaultOptions, ...options };
31
+
32
+ return await ImageResizer.createResizedImage(
33
+ uri,
34
+ width,
35
+ height,
36
+ format,
37
+ quality,
38
+ mode,
39
+ onlyScaleDown,
40
+ rotation,
41
+ outputPath,
42
+ keepMeta,
43
+ );
44
+ }
45
+
46
+ export default {
47
+ createResizedImage,
48
+ };
@@ -0,0 +1,32 @@
1
+ export interface Response {
2
+ height: number;
3
+ name: string;
4
+ path: string;
5
+ size: number;
6
+ uri: string;
7
+ width: number;
8
+ }
9
+
10
+ export type ResizeFormat = 'PNG' | 'JPEG' | 'WEBP';
11
+ export type ResizeMode = 'contain' | 'cover' | 'stretch';
12
+
13
+ export type Options = {
14
+ /**
15
+ * Either `contain` (the default), `cover`, or `stretch`. Similar to
16
+ * [react-native <Image>'s resizeMode](https://reactnative.dev/docs/image#resizemode)
17
+ *
18
+ * - `contain` will fit the image within `width` and `height`,
19
+ * preserving its ratio
20
+ * - `cover` will make sure at least one dimension fits `width` or
21
+ * `height`, and the other is larger, also preserving its ratio.
22
+ * - `stretch` will resize the image to exactly `width` and `height`.
23
+ *
24
+ * (Default: 'contain')
25
+ */
26
+ mode?: ResizeMode;
27
+ /**
28
+ * Whether to avoid resizing the image to be larger than the original.
29
+ * (Default: false)
30
+ */
31
+ onlyScaleDown?: boolean;
32
+ };
@@ -1,15 +1,21 @@
1
1
  import { PermissionsAndroid, Platform } from 'react-native';
2
- import RNFS from 'react-native-fs';
3
2
  let AudioRecorderPackage;
4
3
  let audioRecorderPlayer;
5
4
 
5
+ let RNBlobUtil;
6
+
7
+ try {
8
+ RNBlobUtil = require('react-native-blob-util').default;
9
+ } catch (e) {
10
+ console.log('react-native-blob-util is not installed');
11
+ }
12
+
6
13
  try {
7
14
  AudioRecorderPackage = require('react-native-audio-recorder-player').default;
8
15
  audioRecorderPlayer = new AudioRecorderPackage();
9
16
  audioRecorderPlayer.setSubscriptionDuration(Platform.OS === 'android' ? 0.1 : 0.06);
10
17
  } catch (e) {
11
18
  console.log('react-native-audio-recorder-player is not installed.');
12
- console.log(e);
13
19
  }
14
20
 
15
21
  export enum AudioSourceAndroidType {
@@ -197,7 +203,7 @@ class _Audio {
197
203
  }
198
204
  try {
199
205
  const path = Platform.select({
200
- android: `${RNFS.CachesDirectoryPath}/sound.aac`,
206
+ android: `${RNBlobUtil.fs.dirs.CacheDir}/sound.aac`,
201
207
  ios: 'sound.aac',
202
208
  });
203
209
  const audioSet = {
@@ -249,4 +255,4 @@ class _Audio {
249
255
  };
250
256
  }
251
257
 
252
- export const Audio = AudioRecorderPackage ? new _Audio() : null;
258
+ export const Audio = AudioRecorderPackage && RNBlobUtil ? new _Audio() : null;
@@ -0,0 +1,21 @@
1
+ import { FlatList as DefaultFlatList, Platform } from 'react-native';
2
+ let FlatList;
3
+
4
+
5
+ if (Platform.constants.reactNativeVersion.minor < 72) {
6
+ const upgradeLog =
7
+ "'@stream-io/flat-list-mvcp' is deprecated, please upgrade your react-native version to >0.71 to get same the benefits on the default FlatList and uninstall the package.";
8
+ try {
9
+ FlatList = require('@stream-io/flat-list-mvcp').FlatList;
10
+ console.log(upgradeLog);
11
+ } catch (error) {
12
+ console.log(
13
+ `@stream-io/flat-list-mvcp not found, using react-native's FlatList. This library is used to achieve bi-directional infinite scrolling on lower react native versions. ${upgradeLog}`,
14
+ );
15
+ FlatList = require('react-native').FlatList;
16
+ }
17
+ } else {
18
+ FlatList = DefaultFlatList;
19
+ }
20
+
21
+ export { FlatList };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import AudioVideoPlayer from '../optionalDependencies/Video';
3
+ import AudioVideoPlayer from './AudioVideo';
4
4
 
5
5
  export const Sound = {
6
6
  initializeSound: null,
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
+ import AudioVideoPlayer from './AudioVideo';
2
3
 
3
- import AudioVideoPlayer from '../optionalDependencies/Video';
4
4
  export const Video = AudioVideoPlayer
5
5
  ? ({ onBuffer, onEnd, onLoad, onProgress, paused, repeat, resizeMode, style, uri, videoRef }) => (
6
6
  <AudioVideoPlayer
@@ -0,0 +1,19 @@
1
+ let RNBlobUtil;
2
+
3
+ try {
4
+ RNBlobUtil = require('react-native-blob-util').default;
5
+ } catch (e) {
6
+ console.log('react-native-blob-util is not installed');
7
+ }
8
+
9
+ export const deleteFile = RNBlobUtil
10
+ ? async ({ uri }) => {
11
+ try {
12
+ await RNBlobUtil.fs.unlink(uri);
13
+ return true;
14
+ } catch (error) {
15
+ console.log('File deletion failed...', error);
16
+ return false;
17
+ }
18
+ }
19
+ : null;
@@ -1,3 +1,5 @@
1
+ import { Platform } from 'react-native';
2
+
1
3
  let CameraRollDependency;
2
4
 
3
5
  try {
@@ -5,15 +7,18 @@ try {
5
7
  } catch (e) {
6
8
  // do nothing
7
9
  console.log(
8
- '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
10
+ '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
9
11
  );
10
12
  }
11
13
 
12
14
  export const getLocalAssetUri = CameraRollDependency
13
15
  ? async (remoteUri: string) => {
14
16
  try {
15
- const localUri = await CameraRollDependency.CameraRoll.save(remoteUri);
16
- return localUri;
17
+ if (Platform.OS === 'ios') {
18
+ const imageData = await CameraRollDependency.CameraRoll.iosGetImageDataById(remoteUri);
19
+ return imageData?.node?.image?.filepath;
20
+ }
21
+ return remoteUri;
17
22
  } catch {
18
23
  throw new Error('getLocalAssetUri Error');
19
24
  }
@@ -7,12 +7,14 @@ try {
7
7
  } catch (e) {
8
8
  // do nothing
9
9
  console.log(
10
- '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
10
+ '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
11
11
  );
12
12
  }
13
13
 
14
14
  import type { Asset } from 'stream-chat-react-native-core';
15
15
 
16
+ import { getLocalAssetUri } from './getLocalAssetUri';
17
+
16
18
  type ReturnType = {
17
19
  assets: Array<Omit<Asset, 'source'> & { source: 'picker' }>;
18
20
  endCursor: string | undefined;
@@ -82,15 +84,23 @@ export const getPhotos = CameraRollDependency
82
84
  first,
83
85
  include: ['fileSize', 'filename', 'imageSize', 'playableDuration'],
84
86
  });
85
- const assets = results.edges.map((edge) => ({
86
- ...edge.node.image,
87
- duration: edge.node.image.playableDuration * 1000,
88
- // since we include filename, fileSize in the query, we can safely assume it will be defined
89
- name: edge.node.image.filename as string,
90
- size: edge.node.image.fileSize as number,
91
- source: 'picker' as const,
92
- type: edge.node.type,
93
- }));
87
+ const assets = await Promise.all(
88
+ results.edges.map(async (edge) => {
89
+ const originalUri = edge.node?.image?.uri;
90
+ const uri = getLocalAssetUri ? await getLocalAssetUri(originalUri) : originalUri;
91
+ return {
92
+ ...edge.node.image,
93
+ duration: edge.node.image.playableDuration * 1000,
94
+ // since we include filename, fileSize in the query, we can safely assume it will be defined
95
+ name: edge.node.image.filename as string,
96
+ originalUri,
97
+ size: edge.node.image.fileSize as number,
98
+ source: 'picker' as const,
99
+ type: edge.node.type,
100
+ uri,
101
+ };
102
+ }),
103
+ );
94
104
  const hasNextPage = results.page_info.has_next_page;
95
105
  const endCursor = results.page_info.end_cursor;
96
106
  return { assets, endCursor, hasNextPage, iOSLimited: !!results.limited };
@@ -7,7 +7,7 @@ try {
7
7
  } catch (e) {
8
8
  // do nothing
9
9
  console.log(
10
- '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
10
+ '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
11
11
  );
12
12
  }
13
13
 
@@ -1,12 +1,16 @@
1
1
  export * from './Audio';
2
- export * from './shareImage';
3
- export * from './Video';
4
- export * from './triggerHaptic';
5
- export * from './setClipboardString';
6
- export * from './pickDocument';
2
+ export * from './deleteFile';
3
+ export * from './FlatList';
7
4
  export * from './getLocalAssetUri';
5
+ export * from './getPhotos';
8
6
  export * from './iOS14RefreshGallerySelection';
9
7
  export * from './oniOS14GalleryLibrarySelectionChange';
10
- export * from './getPhotos';
8
+ export * from './pickDocument';
11
9
  export * from './pickImage';
10
+ export * from './saveFile';
11
+ export * from './setClipboardString';
12
+ export * from './shareImage';
13
+ export * from './Sound';
12
14
  export * from './takePhoto';
15
+ export * from './triggerHaptic';
16
+ export * from './Video';
@@ -7,7 +7,7 @@ try {
7
7
  } catch (e) {
8
8
  // do nothing
9
9
  console.log(
10
- '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-crop-picker for native image picker.',
10
+ '@react-native-camera-roll/camera-roll is not installed. Please install it or you can choose to install react-native-image-picker for native image picker.',
11
11
  );
12
12
  }
13
13
 
@@ -0,0 +1,24 @@
1
+ let RNBlobUtil;
2
+
3
+ try {
4
+ RNBlobUtil = require('react-native-blob-util').default;
5
+ } catch (e) {
6
+ console.log('react-native-blob-util is not installed');
7
+ }
8
+
9
+ export const saveFile = RNBlobUtil
10
+ ? async ({ fileName, fromUrl }) => {
11
+ try {
12
+ const path = RNBlobUtil.fs.dirs.CacheDir + '/' + encodeURIComponent(fileName);
13
+ await RNBlobUtil.config({
14
+ fileCache: true,
15
+ path,
16
+ }).fetch('GET', fromUrl);
17
+
18
+ return path;
19
+ } catch (error) {
20
+ console.log('Downloading image failed...', error);
21
+ throw new Error('Downloading image failed...');
22
+ }
23
+ }
24
+ : null;
@@ -1,5 +1,4 @@
1
1
  import { Platform } from 'react-native';
2
- import RNFS from 'react-native-fs';
3
2
 
4
3
  let RNShare;
5
4
 
@@ -9,10 +8,18 @@ try {
9
8
  console.log('react-native-share is not installed');
10
9
  }
11
10
 
11
+ let RNBlobUtil;
12
+
13
+ try {
14
+ RNBlobUtil = require('react-native-blob-util').default;
15
+ } catch (e) {
16
+ console.log('react-native-blob-util is not installed');
17
+ }
18
+
12
19
  export const shareImage = RNShare
13
20
  ? async ({ type, url }) => {
14
21
  try {
15
- const base64Image = await RNFS.readFile(url, 'base64');
22
+ const base64Image = await RNBlobUtil.fs.readFile(url, 'base64');
16
23
  const base64Url = `data:${type};base64,${base64Image}`;
17
24
  await RNShare.open({
18
25
  activityItemSources:
@@ -35,9 +42,6 @@ export const shareImage = RNShare
35
42
  },
36
43
  ]
37
44
  : undefined,
38
- // react-native-share has a typing issue, where their docs confirm that
39
- // this property should be an array of strings, but the type is a string
40
- // in the @types/react-native-share package.
41
45
  excludedActivityTypes: [] as unknown as string,
42
46
  failOnCancel: false,
43
47
  type,
@@ -45,7 +49,7 @@ export const shareImage = RNShare
45
49
  });
46
50
  return true;
47
51
  } catch (error) {
48
- console.warn('Sharing failed...');
52
+ console.warn('Sharing failed...', error);
49
53
  }
50
54
  }
51
55
  : null;
@@ -3,9 +3,11 @@ import { AppState, Image, PermissionsAndroid, Platform } from 'react-native';
3
3
  let ImagePicker;
4
4
 
5
5
  try {
6
- ImagePicker = require('react-native-image-crop-picker').default;
6
+ ImagePicker = require('react-native-image-picker');
7
7
  } catch (e) {
8
- console.log('react-native-image-crop-picker is not installed');
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.',
10
+ );
9
11
  }
10
12
 
11
13
  export const takePhoto = ImagePicker
@@ -26,20 +28,22 @@ export const takePhoto = ImagePicker
26
28
  }
27
29
  }
28
30
  try {
29
- const photo = await ImagePicker.openCamera({
30
- compressImageQuality: Math.min(Math.max(0, compressImageQuality), 1),
31
+ const result = await ImagePicker.launchCamera({
32
+ quality: Math.min(Math.max(0, compressImageQuality), 1),
31
33
  });
32
- if (photo.height && photo.width && photo.path) {
34
+ if (!result.assets.length) {
35
+ return {
36
+ cancelled: true,
37
+ };
38
+ }
39
+ const photo = result.assets[0];
40
+ if (photo.height && photo.width && photo.uri) {
33
41
  let size: { height?: number; width?: number } = {};
34
42
  if (Platform.OS === 'android') {
35
43
  // Height and width returned by ImagePicker are incorrect on Android.
36
- // The issue is described in following github issue:
37
- // https://github.com/ivpusic/react-native-image-crop-picker/issues/901
38
- // This we can't rely on them as it is, and we need to use Image.getSize
39
- // to get accurate size.
40
44
  const getSize = (): Promise<{ height: number; width: number }> =>
41
45
  new Promise((resolve) => {
42
- Image.getSize(photo.path, (width, height) => {
46
+ Image.getSize(photo.uri, (width, height) => {
43
47
  resolve({ height, width });
44
48
  });
45
49
  });
@@ -62,7 +66,7 @@ export const takePhoto = ImagePicker
62
66
  cancelled: false,
63
67
  size: photo.size,
64
68
  source: 'camera',
65
- uri: photo.path,
69
+ uri: photo.uri,
66
70
  ...size,
67
71
  };
68
72
  }
@@ -0,0 +1,38 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "stream-chat-react-native"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => "10.0" }
15
+ s.source = { :git => "./ios", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm}"
18
+
19
+ s.dependency "React-Core"
20
+ s.ios.framework = 'AssetsLibrary', 'MobileCoreServices'
21
+
22
+ # Don't install the dependencies when we run `pod install` in the old architecture.
23
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
24
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
25
+ s.pod_target_xcconfig = {
26
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
27
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
28
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
29
+ }
30
+ s.dependency "React-Codegen"
31
+ s.dependency "RCT-Folly"
32
+ s.dependency "RCTRequired"
33
+ s.dependency "RCTTypeSafety"
34
+ s.dependency "ReactCommon/turbomodule/core"
35
+ install_modules_dependencies(s)
36
+ end
37
+ end
38
+