Skip to content

Commit 06041c7

Browse files
Merge pull request #1442 from GetStream/vishal/optional-video-dep
refactor: made react-native-video an optional dependency
2 parents ef8fab7 + 99e9456 commit 06041c7

File tree

22 files changed

+319
-206
lines changed

22 files changed

+319
-206
lines changed

docusaurus/docs/reactnative/basics/getting_started.mdx

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This should be considered a primer before delving into the UI and Core Component
1616

1717
Your [environment should be setup](https://reactnative.dev/docs/environment-setup) and a project created prior to beginning the installation.
1818

19-
### Add dependencies
19+
### Add Required dependencies
2020

2121
Install the required packages in your React Native project.
2222

@@ -151,14 +151,22 @@ For some of the packages listed below, there are additional steps required to se
151151
- `react-native` - [additional installation steps](https://reactnative.dev/docs/image#gif-and-webp-support-on-android)
152152
- `react-native-image-crop-picker` - [additional installation steps](https://github.com/ivpusic/react-native-image-crop-picker#step-3)
153153
- `react-native-cameraroll` - [additional installation steps](https://github.com/react-native-cameraroll/react-native-cameraroll#permissions)
154-
- `react-native-video` - [additional installation steps](https://github.com/react-native-video/react-native-video/blob/master/API.md#installation)
155154

156155
:::note
157156

158157
If you are planning to use file picker functionality, make sure you enable iCloud capability in your app - [Enable iCloud capability](https://camo.githubusercontent.com/ac300ca7e3bbab573a76c151469a89efd8b31e72/68747470733a2f2f33313365353938373731386233343661616638332d66356538323532373066323961383466373838313432333431303338343334322e73736c2e6366312e7261636b63646e2e636f6d2f313431313932303637342d656e61626c652d69636c6f75642d64726976652e706e67)
159158

160159
:::
161160

161+
### Add Optional Dependencies
162+
163+
- `react-native-video` - [additional installation steps](https://github.com/react-native-video/react-native-video/blob/master/API.md#installation)
164+
165+
> Available in stream-chat-react-native >= v4.7.0
166+
167+
Installing this package allows you to play the video files/attachments in the chat. Otherwise by default, video files will be opened in default
168+
browser of the device.
169+
162170
### AndroidX Support
163171

164172
> AndroidX is a major step forward in the Android ecosystem, and the old support library artifacts are being deprecated.
@@ -172,9 +180,67 @@ But an awesome tool named [jetifier](https://github.com/mikehardy/jetifier) is q
172180

173181
## Expo Installation
174182

175-
Stream Chat for React Native is set up for parity on Expo, expo requires a different set of dependencies than bare React Native, in your project directory run:
183+
Stream Chat for React Native is set up for parity on Expo, expo requires a different set of dependencies than bare React Native, in your project directory run.
184+
185+
### Add Required Dependencies
176186

177187
```bash
178188
expo install stream-chat-expo
179189
expo install @react-native-community/netinfo expo-document-picker expo-file-system expo-haptics expo-image-manipulator expo-image-picker expo-media-library expo-sharing react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-svg expo-av
180190
```
191+
192+
### Additional Steps
193+
194+
For some of the packages listed below, there are additional steps required to setup the package:
195+
196+
- `react-native-reanimated` - [additional installation steps](https://docs.expo.dev/versions/latest/sdk/reanimated/#installation)
197+
198+
Add Reanimated's babel plugin to your babel.config.js:
199+
200+
```js
201+
module.exports = {
202+
...
203+
plugins: [
204+
...
205+
'react-native-reanimated/plugin',
206+
],
207+
};
208+
```
209+
210+
- `react-native-gesture-handler` - [additional installation steps](https://docs.expo.dev/versions/latest/sdk/gesture-handler/#api)
211+
212+
RNGH requires the package to be imported at the **top of the entry file** before anything else, this is usually your `App.js` or `index.js` file.
213+
214+
```tsx
215+
import 'react-native-gesture-handler';
216+
import { AppRegistry } from 'react-native';
217+
218+
import App from './App';
219+
import { name as appName } from './app.json';
220+
221+
AppRegistry.registerComponent(appName, () => App);
222+
```
223+
224+
Also wrap your entry point with `<GestureHandlerRootView>` or `gestureHandlerRootHO`
225+
226+
```jsx
227+
import { GestureHandlerRootView } from 'react-native-gesture-handler';
228+
import { OverlayProvider } from 'stream-chat-react-native';
229+
230+
export default function App() {
231+
return (
232+
<GestureHandlerRootView>
233+
<OverlayProvider>{/* Your app code goes here */}</OverlayProvider>
234+
</GestureHandlerRootView>
235+
);
236+
}
237+
```
238+
239+
### Add Optional Dependencies
240+
241+
- `expo-av` - [additional installation steps](https://docs.expo.dev/versions/v45.0.0/sdk/video/)
242+
243+
> Available in stream-chat-expo >= v4.7.0
244+
245+
Installing this package allows you to play the video files/attachments in the chat. Otherwise by default, video files will be opened in default
246+
browser of the device.

package/expo-package/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"expo-media-library": "^12.0.2",
2424
"expo-sharing": "^9.1.2"
2525
},
26+
"optionalDependencies": {
27+
"expo-av": "^11.2.3"
28+
},
2629
"scripts": {
2730
"prepack": " cp ../../README.md .",
2831
"postpack": "rm README.md"

package/expo-package/src/index.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { FlatList, Image, Platform } from 'react-native';
33

44
import NetInfo from '@react-native-community/netinfo';
5-
import { Video as ExpoVideoPlayer } from 'expo-av';
5+
66
import * as DocumentPicker from 'expo-document-picker';
77
import * as FileSystem from 'expo-file-system';
88
import * as Haptics from 'expo-haptics';
@@ -12,6 +12,8 @@ import * as MediaLibrary from 'expo-media-library';
1212
import * as Sharing from 'expo-sharing';
1313
import { registerNativeHandlers } from 'stream-chat-react-native-core';
1414

15+
import ExpoVideoPlayer from './optionalDependencies/Video';
16+
1517
registerNativeHandlers({
1618
compressImage: async ({ compressImageQuality = 1, uri }) => {
1719
const { uri: compressedUri } = await ImageManipulator.manipulateAsync(uri, [], {
@@ -220,18 +222,18 @@ registerNativeHandlers({
220222
}
221223
},
222224
// eslint-disable-next-line react/display-name
223-
Video: ({ onPlaybackStatusUpdate, paused, style, uri, videoRef }) => (
224-
<ExpoVideoPlayer
225-
onPlaybackStatusUpdate={onPlaybackStatusUpdate}
226-
ref={videoRef}
227-
resizeMode='contain'
228-
shouldPlay={!paused}
229-
source={{
230-
uri,
231-
}}
232-
style={[style]}
233-
/>
234-
),
225+
Video: ExpoVideoPlayer ? ({ onPlaybackStatusUpdate, paused, style, uri, videoRef }) => (
226+
<ExpoVideoPlayer
227+
onPlaybackStatusUpdate={onPlaybackStatusUpdate}
228+
ref={videoRef}
229+
resizeMode='contain'
230+
shouldPlay={!paused}
231+
source={{
232+
uri,
233+
}}
234+
style={[style]}
235+
/>
236+
) : null,
235237
});
236238

237239
export * from 'stream-chat-react-native-core';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let VideoComponent;
2+
try {
3+
const videoPackage = require('expo-av');
4+
VideoComponent = videoPackage.Video;
5+
} catch (_) {
6+
console.warn(
7+
'Video library is currently not installed. To allow in-app video playback, install the "expo-av" package.',
8+
);
9+
}
10+
11+
export default VideoComponent;

package/expo-package/yarn.lock

Lines changed: 30 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -711,20 +711,19 @@
711711
"@babel/helper-validator-identifier" "^7.16.7"
712712
to-fast-properties "^2.0.0"
713713

714-
"@expo/config-plugins@^4.0.2":
715-
version "4.1.0"
716-
resolved "https://registry.yarnpkg.com/@expo/config-plugins/-/config-plugins-4.1.0.tgz#0365e2e51e2e3e3b4e7db1fbbada5be661798be6"
717-
integrity sha512-+Uq7kzi1StUZZZivnnqNV6+v8b+SMF6MDgH+cEZxCoM9uwLXOK0rTAURzBGtl+C6EEbKnoZmnKGuzABBGPRP7A==
718-
dependencies:
719-
"@expo/config-types" "^44.0.0"
720-
"@expo/json-file" "8.2.34"
721-
"@expo/plist" "0.0.17"
714+
"@expo/config-plugins@^4.0.14":
715+
version "4.1.5"
716+
resolved "https://registry.yarnpkg.com/@expo/config-plugins/-/config-plugins-4.1.5.tgz#9d357d2cda9c095e511b51583ede8a3b76174068"
717+
integrity sha512-RVvU40RtZt12HavuDAe+LDIq9lHj7sheOfMEHdmpJ/uTA8pgvkbc56XF6JHQD+yRr6+uhhb+JnAasGq49dsQbw==
718+
dependencies:
719+
"@expo/config-types" "^45.0.0"
720+
"@expo/json-file" "8.2.36"
721+
"@expo/plist" "0.0.18"
722722
"@expo/sdk-runtime-versions" "^1.0.0"
723723
"@react-native/normalize-color" "^2.0.0"
724724
chalk "^4.1.2"
725725
debug "^4.3.1"
726726
find-up "~5.0.0"
727-
fs-extra "9.0.0"
728727
getenv "^1.0.0"
729728
glob "7.1.6"
730729
resolve-from "^5.0.0"
@@ -733,24 +732,24 @@
733732
xcode "^3.0.1"
734733
xml2js "0.4.23"
735734

736-
"@expo/config-types@^44.0.0":
737-
version "44.0.0"
738-
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-44.0.0.tgz#d3480fe2c99f9e895dae4ebba58b74ed72d03e26"
739-
integrity sha512-d+gpdKOAhqaD5RmcMzGgKzNtvE1w+GCqpFQNSXLliYlXjj+Tv0eL8EPeAdPtvke0vowpPFwd5McXLA90dgY6Jg==
735+
"@expo/config-types@^45.0.0":
736+
version "45.0.0"
737+
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-45.0.0.tgz#963c2fdce8fbcbd003758b92ed8a25375f437ef6"
738+
integrity sha512-/QGhhLWyaGautgEyU50UJr5YqKJix5t77ePTwreOVAhmZH+ff3nrrtYTTnccx+qF08ZNQmfAyYMCD3rQfzpiJA==
740739

741-
"@expo/[email protected].34":
742-
version "8.2.34"
743-
resolved "https://registry.yarnpkg.com/@expo/json-file/-/json-file-8.2.34.tgz#2f24e90a677195f7a81e167115460eb2902c3130"
744-
integrity sha512-ZxtBodAZGxdLtgKzmsC+8ViUxt1mhFW642Clu2OuG3f6PAyAFsU/SqEGag9wKFaD3x3Wt8VhL+3y5fMJmUFgPw==
740+
"@expo/[email protected].36":
741+
version "8.2.36"
742+
resolved "https://registry.yarnpkg.com/@expo/json-file/-/json-file-8.2.36.tgz#62a505cb7f30a34d097386476794680a3f7385ff"
743+
integrity sha512-tOZfTiIFA5KmMpdW9KF7bc6CFiGjb0xnbieJhTGlHrLL+ps2G0OkqmuZ3pFEXBOMnJYUVpnSy++52LFxvpa5ZQ==
745744
dependencies:
746745
"@babel/code-frame" "~7.10.4"
747746
json5 "^1.0.1"
748747
write-file-atomic "^2.3.0"
749748

750-
"@expo/[email protected].17":
751-
version "0.0.17"
752-
resolved "https://registry.yarnpkg.com/@expo/plist/-/plist-0.0.17.tgz#0f6c594e116f45a28f5ed20998dadb5f3429f88b"
753-
integrity sha512-5Ul3d/YOYE6mfum0jCE25XUnkKHZ5vGlU/X2275ZmCtGrpRn1Fl8Nq+jQKSaks3NqTfxdyXROi/TgH8Zxeg2wg==
749+
"@expo/[email protected].18":
750+
version "0.0.18"
751+
resolved "https://registry.yarnpkg.com/@expo/plist/-/plist-0.0.18.tgz#9abcde78df703a88f6d9fa1a557ee2f045d178b0"
752+
integrity sha512-+48gRqUiz65R21CZ/IXa7RNBXgAI/uPSdvJqoN9x1hfL44DNbUoWHgHiEXTx7XelcATpDwNTz6sHLfy0iNqf+w==
754753
dependencies:
755754
"@xmldom/xmldom" "~0.7.0"
756755
base64-js "^1.2.3"
@@ -893,11 +892,6 @@ asynckit@^0.4.0:
893892
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
894893
integrity sha1-x57Zf380y48robyXkLzDZkdLS3k=
895894

896-
at-least-node@^1.0.0:
897-
version "1.0.0"
898-
resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2"
899-
integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==
900-
901895
axios@^0.22.0:
902896
version "0.22.0"
903897
resolved "https://registry.yarnpkg.com/axios/-/axios-0.22.0.tgz#bf702c41fb50fbca4539589d839a077117b79b25"
@@ -1154,12 +1148,12 @@ escape-string-regexp@^1.0.5:
11541148
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
11551149
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
11561150

1157-
expo-av@^10.2.1:
1158-
version "10.2.1"
1159-
resolved "https://registry.yarnpkg.com/expo-av/-/expo-av-10.2.1.tgz#c08bce464d673d0e90c68cac082bfb75a9437f25"
1160-
integrity sha512-thrkHVg4HVn8L+jHKVnXYd4TLkJQblFE8QXd3d1hwrYG63gehQT2nK4DM0Frl50EcdV8YN9XjhwHobtK5oMc9A==
1151+
expo-av@^11.2.3:
1152+
version "11.2.3"
1153+
resolved "https://registry.yarnpkg.com/expo-av/-/expo-av-11.2.3.tgz#254242dae76e3cd60ef9d9c33618e4a12d37aa33"
1154+
integrity sha512-ptTe96s33Ct0eOsOmNTvtaWFx4B0SDkQmDfPbiuX/C2afqbLQf8geEopw7BRO8ZZl7Qe3qBMH6YLHXKTkZkTyQ==
11611155
dependencies:
1162-
"@expo/config-plugins" "^4.0.2"
1156+
"@expo/config-plugins" "^4.0.14"
11631157

11641158
fast-deep-equal@^3.1.1:
11651159
version "3.1.3"
@@ -1201,16 +1195,6 @@ form-data@^4.0.0:
12011195
combined-stream "^1.0.8"
12021196
mime-types "^2.1.12"
12031197

1204-
1205-
version "9.0.0"
1206-
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.0.tgz#b6afc31036e247b2466dc99c29ae797d5d4580a3"
1207-
integrity sha512-pmEYSk3vYsG/bF651KPUXZ+hvjpgWYw/Gc7W9NFUe3ZVLczKKWIij3IKpOrQcdw4TILtibFslZ0UmR8Vvzig4g==
1208-
dependencies:
1209-
at-least-node "^1.0.0"
1210-
graceful-fs "^4.2.0"
1211-
jsonfile "^6.0.1"
1212-
universalify "^1.0.0"
1213-
12141198
fs.realpath@^1.0.0:
12151199
version "1.0.0"
12161200
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1257,7 +1241,7 @@ globals@^11.1.0:
12571241
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
12581242
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
12591243

1260-
graceful-fs@^4.1.11, graceful-fs@^4.1.6, graceful-fs@^4.2.0:
1244+
graceful-fs@^4.1.11:
12611245
version "4.2.10"
12621246
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
12631247
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==
@@ -1372,15 +1356,6 @@ json5@^2.1.2:
13721356
dependencies:
13731357
minimist "^1.2.5"
13741358

1375-
jsonfile@^6.0.1:
1376-
version "6.1.0"
1377-
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae"
1378-
integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==
1379-
dependencies:
1380-
universalify "^2.0.0"
1381-
optionalDependencies:
1382-
graceful-fs "^4.1.6"
1383-
13841359
jsonwebtoken@^8.5.1:
13851360
version "8.5.1"
13861361
resolved "https://registry.yarnpkg.com/jsonwebtoken/-/jsonwebtoken-8.5.1.tgz#00e71e0b8df54c2121a1f26137df2280673bcc0d"
@@ -1901,10 +1876,10 @@ [email protected]:
19011876
resolved "https://registry.yarnpkg.com/stream-buffers/-/stream-buffers-2.2.0.tgz#91d5f5130d1cef96dcfa7f726945188741d09ee4"
19021877
integrity sha1-kdX1Ew0c75bc+n9yaUUYh0HQnuQ=
19031878

1904-
stream-chat-react-native-core@4.3.0:
1905-
version "4.3.0"
1906-
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-4.3.0.tgz#24b41e0aa8da6e4e9adeca50fe08002b2ddd5caf"
1907-
integrity sha512-tjbW7wCgEfr2kZe/OdiYfqv4bOz4Y2nwpMuBo1Rm5xkWPQ9zs0hpdpJLAiU17J8mboHZpfuxSwe0LEKlE8ZJRg==
1879+
stream-chat-react-native-core@4.6.1:
1880+
version "4.6.1"
1881+
resolved "https://registry.yarnpkg.com/stream-chat-react-native-core/-/stream-chat-react-native-core-4.6.1.tgz#17a88bbba8c10ba0259e3bc04623bb184fb652fa"
1882+
integrity sha512-QUVI9HdNMV6sYOXHtEmrowl2Rg4qWdFSjQL7VATyEWheTfIAbx7wFNZ9jLqlkwKL10AUAww1X85NXO7aFD64Yg==
19081883
dependencies:
19091884
"@babel/runtime" "^7.12.5"
19101885
"@gorhom/bottom-sheet" "4.1.5"
@@ -1987,16 +1962,6 @@ unicode-property-aliases-ecmascript@^2.0.0:
19871962
resolved "https://registry.yarnpkg.com/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.0.0.tgz#0a36cb9a585c4f6abd51ad1deddb285c165297c8"
19881963
integrity sha512-5Zfuy9q/DFr4tfO7ZPeVXb1aPoeQSdeFMLpYuFebehDAhbuevLs5yxSZmIFN1tP5F9Wl4IpJrYojg85/zgyZHQ==
19891964

1990-
universalify@^1.0.0:
1991-
version "1.0.0"
1992-
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
1993-
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
1994-
1995-
universalify@^2.0.0:
1996-
version "2.0.0"
1997-
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
1998-
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==
1999-
20001965
uri-js@^4.2.2:
20011966
version "4.4.1"
20021967
resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"

package/native-package/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"react-native-haptic-feedback": ">=1.11.0",
2424
"react-native-image-crop-picker": ">=0.33.2",
2525
"react-native-image-resizer": ">=1.4.2",
26-
"react-native-share": ">=4.1.0",
26+
"react-native-share": ">=4.1.0"
27+
},
28+
"optionalDependencies": {
2729
"react-native-video": "^5.2.0"
2830
},
2931
"scripts": {

0 commit comments

Comments
 (0)