stream-chat-expo 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.
package/README.md CHANGED
@@ -7,11 +7,10 @@
7
7
  > The official React Native and Expo components for Stream Chat, a service for
8
8
  > building chat applications.
9
9
 
10
-
11
10
  [![NPM](https://img.shields.io/npm/v/stream-chat-react-native.svg)](https://www.npmjs.com/package/stream-chat-react-native)
12
11
  [![Build Status](https://github.com/GetStream/stream-chat-react-native/actions/workflows/release.yml/badge.svg)](https://github.com/GetStream/stream-chat-react-native/actions)
13
12
  [![Component Reference](https://img.shields.io/badge/docs-component%20reference-blue.svg)](https://getstream.io/chat/docs/sdk/reactnative)
14
- ![JS Bundle Size](https://img.shields.io/badge/js_bundle_size-452%20KB-blue)
13
+ ![JS Bundle Size](https://img.shields.io/badge/js_bundle_size-453%20KB-blue)
15
14
 
16
15
  <img align="right" src="https://getstream.imgix.net/images/ios-chat-tutorial/iphone_chat_art@3x.png?auto=format,enhance" width="50%" />
17
16
 
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": "5.44.2",
4
+ "version": "6.0.0-beta.1",
5
5
  "author": {
6
6
  "company": "Stream.io Inc",
7
7
  "name": "Stream.io Inc"
@@ -10,11 +10,10 @@
10
10
  "main": "src/index.js",
11
11
  "types": "types/index.d.ts",
12
12
  "dependencies": {
13
- "stream-chat-react-native-core": "5.44.2"
13
+ "stream-chat-react-native-core": "6.0.0-beta.1"
14
14
  },
15
15
  "peerDependencies": {
16
- "@react-native-community/netinfo": ">=6.0.0",
17
- "expo": ">=44.0.0",
16
+ "expo": ">=51.0.0",
18
17
  "expo-av": "*",
19
18
  "expo-clipboard": "*",
20
19
  "expo-document-picker": "*",
@@ -35,6 +34,9 @@
35
34
  "expo-document-picker": {
36
35
  "optional": true
37
36
  },
37
+ "expo-file-system": {
38
+ "optional": true
39
+ },
38
40
  "expo-media-library": {
39
41
  "optional": true
40
42
  },
@@ -49,10 +51,8 @@
49
51
  }
50
52
  },
51
53
  "devDependencies": {
52
- "@react-native-community/netinfo": "^6.0.0",
53
- "expo": "^44.0.0",
54
- "expo-file-system": "^11.0.2",
55
- "expo-image-manipulator": "^9.1.0"
54
+ "expo": "^51.0.17",
55
+ "expo-image-manipulator": "^12.0.5"
56
56
  },
57
57
  "scripts": {
58
58
  "prepack": " cp ../../README.md .",
@@ -1,7 +1 @@
1
- export * from './Audio';
2
1
  export * from './compressImage';
3
- export * from './deleteFile';
4
- export * from './NetInfo';
5
- export * from './saveFile';
6
- export * from './Sound';
7
- export * from './Video';
package/src/index.js CHANGED
@@ -2,27 +2,24 @@ import { FlatList } from 'react-native';
2
2
 
3
3
  import { registerNativeHandlers } from 'stream-chat-react-native-core';
4
4
 
5
+ import { compressImage } from './handlers';
6
+
5
7
  import {
6
8
  Audio,
7
- compressImage,
8
9
  deleteFile,
9
- NetInfo,
10
- saveFile,
11
- Sound,
12
- Video,
13
- } from './handlers';
14
-
15
- import {
16
10
  getLocalAssetUri,
17
11
  getPhotos,
18
12
  iOS14RefreshGallerySelection,
19
13
  oniOS14GalleryLibrarySelectionChange,
20
14
  pickDocument,
21
15
  pickImage,
16
+ saveFile,
22
17
  setClipboardString,
23
18
  shareImage,
19
+ Sound,
24
20
  takePhoto,
25
21
  triggerHaptic,
22
+ Video,
26
23
  } from './optionalDependencies';
27
24
 
28
25
  registerNativeHandlers({
@@ -33,7 +30,6 @@ registerNativeHandlers({
33
30
  getLocalAssetUri,
34
31
  getPhotos,
35
32
  iOS14RefreshGallerySelection,
36
- NetInfo,
37
33
  oniOS14GalleryLibrarySelectionChange,
38
34
  pickDocument,
39
35
  pickImage,
@@ -1,4 +1,4 @@
1
- import { AudioComponent, RecordingObject } from '../optionalDependencies/Video';
1
+ import { AudioComponent, RecordingObject } from './AudioVideo';
2
2
 
3
3
  export enum AndroidOutputFormat {
4
4
  DEFAULT = 0,
@@ -1,4 +1,4 @@
1
- import { AudioComponent } from '../optionalDependencies/Video';
1
+ import { AudioComponent } from './AudioVideo';
2
2
 
3
3
  export const Sound = {
4
4
  initializeSound: AudioComponent
@@ -1,6 +1,6 @@
1
1
  import React, { useEffect } from 'react';
2
2
 
3
- import { AudioComponent, VideoComponent } from '../optionalDependencies';
3
+ import { AudioComponent, VideoComponent } from './AudioVideo';
4
4
 
5
5
  export const Video = VideoComponent
6
6
  ? ({ onPlaybackStatusUpdate, paused, resizeMode, style, uri, videoRef }) => {
@@ -0,0 +1,25 @@
1
+ let FileSystem;
2
+
3
+ try {
4
+ FileSystem = require('expo-file-system');
5
+ } catch (e) {
6
+ // do nothing
7
+ }
8
+
9
+ if (!FileSystem) {
10
+ console.log(
11
+ 'expo-file-system is not installed. Installing this package will allow your users to save/delete file locally and access the cache dir for android/iOS.',
12
+ );
13
+ }
14
+
15
+ export const deleteFile = FileSystem
16
+ ? async ({ uri }: { uri: string }) => {
17
+ try {
18
+ await FileSystem.deleteAsync(uri, { idempotent: true });
19
+ return true;
20
+ } catch (error) {
21
+ console.log('File deletion failed...', error);
22
+ return false;
23
+ }
24
+ }
25
+ : null;
@@ -1,3 +1,5 @@
1
+ import { Platform } from 'react-native';
2
+
1
3
  let MediaLibrary;
2
4
 
3
5
  try {
@@ -12,10 +14,14 @@ if (!MediaLibrary) {
12
14
  );
13
15
  }
14
16
 
17
+ // TODO: The API is different for Expo and RN CLI. We should unify it.
15
18
  export const getLocalAssetUri = async (assetId: string): Promise<string | undefined> => {
16
19
  try {
17
- const { localUri } = await MediaLibrary.getAssetInfoAsync(assetId);
18
- return localUri;
20
+ if (Platform.OS === 'ios') {
21
+ const { localUri } = await MediaLibrary.getAssetInfoAsync(assetId);
22
+ return localUri;
23
+ }
24
+ return null;
19
25
  } catch {
20
26
  throw new Error('getLocalAssetUri Error');
21
27
  }
@@ -1,3 +1,5 @@
1
+ import { Platform } from 'react-native';
2
+
1
3
  let MediaLibrary;
2
4
 
3
5
  try {
@@ -13,6 +15,8 @@ if (!MediaLibrary) {
13
15
  }
14
16
  import type { Asset } from 'stream-chat-react-native-core';
15
17
 
18
+ import { getLocalAssetUri } from './getLocalAssetUri';
19
+
16
20
  type ReturnType = {
17
21
  assets: Array<Omit<Asset, 'source'> & { source: 'picker' }>;
18
22
  endCursor: string | undefined;
@@ -40,16 +44,22 @@ export const getPhotos = MediaLibrary
40
44
  mediaType: [MediaLibrary.MediaType.photo, MediaLibrary.MediaType.video],
41
45
  sortBy: [MediaLibrary.SortBy.modificationTime],
42
46
  });
43
- const assets = results.assets.map((asset) => ({
44
- duration: asset.duration * 1000,
45
- height: asset.height,
46
- id: asset.id,
47
- name: asset.filename,
48
- source: 'picker' as const,
49
- type: asset.mediaType,
50
- uri: asset.uri,
51
- width: asset.width,
52
- }));
47
+ const assets = await Promise.all(
48
+ results.assets.map(async (asset) => {
49
+ const localUri = await getLocalAssetUri(asset.id);
50
+ return {
51
+ duration: asset.duration * 1000,
52
+ height: asset.height,
53
+ id: asset.id,
54
+ name: asset.filename,
55
+ originalUri: asset.uri,
56
+ source: 'picker' as const,
57
+ type: asset.mediaType,
58
+ uri: localUri || asset.uri,
59
+ width: asset.width,
60
+ };
61
+ }),
62
+ );
53
63
 
54
64
  const hasNextPage = results.hasNextPage;
55
65
  const endCursor = results.endCursor;
@@ -1,6 +1,16 @@
1
+ export * from './Audio';
2
+ export * from './deleteFile';
3
+ export * from './getLocalAssetUri';
4
+ export * from './getPhotos';
5
+ export * from './iOS14RefreshGallerySelection';
6
+ export * from './oniOS14GalleryLibrarySelectionChange';
7
+ export * from './pickDocument';
8
+ export * from './pickImage';
9
+ export * from './saveFile';
1
10
  export * from './setClipboardString';
2
11
  export * from './shareImage';
3
- export * from './pickDocument';
12
+ export * from './Sound';
13
+ export * from './takePhoto';
4
14
  export * from './triggerHaptic';
5
15
  export * from './Video';
6
16
  export * from './oniOS14GalleryLibrarySelectionChange';
@@ -33,7 +33,7 @@ export const pickImage = ImagePicker
33
33
  if (permissionGranted) {
34
34
  const result = await ImagePicker.launchImageLibraryAsync({
35
35
  allowsMultipleSelection: true,
36
- mediaTypes: ImagePicker.MediaTypeOptions.All,
36
+ mediaTypes: ['images', 'videos'],
37
37
  });
38
38
 
39
39
  const canceled = result.canceled;
@@ -0,0 +1,26 @@
1
+ let FileSystem;
2
+
3
+ try {
4
+ FileSystem = require('expo-file-system');
5
+ } catch (e) {
6
+ // do nothing
7
+ }
8
+
9
+ if (!FileSystem) {
10
+ console.log(
11
+ 'expo-file-system is not installed. Installing this package will allow your users to save/delete file locally and access the cache dir for android/iOS.',
12
+ );
13
+ }
14
+
15
+ export const saveFile = FileSystem
16
+ ? async ({ fileName, fromUrl }: { fileName: string; fromUrl: string }) => {
17
+ try {
18
+ const path = FileSystem.cacheDirectory + encodeURIComponent(fileName);
19
+ const downloadedImage = await FileSystem.downloadAsync(fromUrl, path);
20
+ return downloadedImage.uri;
21
+ } catch (error) {
22
+ console.log('Downloading image failed...', error);
23
+ throw new Error('Downloading image failed...');
24
+ }
25
+ }
26
+ : null;
@@ -46,11 +46,6 @@ export const takePhoto = ImagePicker
46
46
  if (canceled === false && photo && photo.height && photo.width && photo.uri) {
47
47
  let size: Size = {};
48
48
  if (Platform.OS === 'android') {
49
- // Height and width returned by ImagePicker are incorrect on Android.
50
- // The issue is described in following github issue:
51
- // https://github.com/ivpusic/react-native-image-crop-picker/issues/901
52
- // This we can't rely on them as it is, and we need to use Image.getSize
53
- // to get accurate size.
54
49
  const getSize = (): Promise<Size> =>
55
50
  new Promise((resolve) => {
56
51
  Image.getSize(photo.uri, (width, height) => {
@@ -45,5 +45,4 @@ export const triggerHaptic = Haptics
45
45
  Haptics.selectionAsync();
46
46
  }
47
47
  }
48
- : // eslint-disable-next-line @typescript-eslint/no-empty-function
49
- () => {};
48
+ : () => {};
@@ -1,43 +0,0 @@
1
- import { NetInfoState, default as OriginalNetInfo } from '@react-native-community/netinfo';
2
-
3
- export const NetInfo = {
4
- addEventListener(listener) {
5
- let unsubscribe;
6
- // For NetInfo >= 3.x.x
7
- if (OriginalNetInfo.fetch && typeof OriginalNetInfo.fetch === 'function') {
8
- unsubscribe = OriginalNetInfo.addEventListener(({ isConnected, isInternetReachable }) => {
9
- // Initialize with truthy value when internetReachable is still loading
10
- // if it resolves to false, listener is triggered with false value and network
11
- // status is updated
12
- listener(isInternetReachable === null ? isConnected : isConnected && isInternetReachable);
13
- });
14
- return unsubscribe;
15
- } else {
16
- // For NetInfo < 3.x.x
17
- unsubscribe = OriginalNetInfo.addEventListener('connectionChange', () => {
18
- // @ts-ignore
19
- OriginalNetInfo.isConnected.fetch().then((isConnected: NetInfoState) => {
20
- listener(isConnected);
21
- });
22
- });
23
-
24
- return unsubscribe.remove;
25
- }
26
- },
27
- fetch() {
28
- return new Promise((resolve, reject) => {
29
- // For NetInfo >= 3.x.x
30
- if (OriginalNetInfo.fetch && typeof OriginalNetInfo.fetch === 'function') {
31
- OriginalNetInfo.fetch().then(({ isConnected }) => {
32
- resolve(isConnected);
33
- }, reject);
34
- } else {
35
- // For NetInfo < 3.x.x
36
- // @ts-ignore
37
- OriginalNetInfo.isConnected.fetch().then((isConnected: NetInfoState) => {
38
- resolve(isConnected);
39
- }, reject);
40
- }
41
- });
42
- },
43
- };
@@ -1,11 +0,0 @@
1
- import * as FileSystem from 'expo-file-system';
2
-
3
- export const deleteFile = async ({ uri }: { uri: string }) => {
4
- try {
5
- await FileSystem.deleteAsync(uri, { idempotent: true });
6
- return true;
7
- } catch (error) {
8
- console.log('File deletion failed...');
9
- return false;
10
- }
11
- };
@@ -1,11 +0,0 @@
1
- import * as FileSystem from 'expo-file-system';
2
-
3
- export const saveFile = async ({ fileName, fromUrl }: { fileName: string; fromUrl: string }) => {
4
- try {
5
- const path = FileSystem.cacheDirectory + encodeURIComponent(fileName);
6
- const downloadedImage = await FileSystem.downloadAsync(fromUrl, path);
7
- return downloadedImage.uri;
8
- } catch (error) {
9
- throw new Error('Downloading image failed...');
10
- }
11
- };