Skip to content

Commit 6989c1d

Browse files
authored
Merge pull request #1346 from GetStream/khushal87-video-upload
feat: allow video upload from image picker
2 parents d2d17ac + 0a46ca1 commit 6989c1d

File tree

19 files changed

+535
-113
lines changed

19 files changed

+535
-113
lines changed

docusaurus/docs/reactnative/contexts/attachment_picker_context.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ Function to open the attachment picker bottom sheet.
8686
| -------- |
8787
| function |
8888

89+
### selectedFiles
90+
91+
List of currently selected files in attachment picker.
92+
93+
```tsx
94+
Array<{
95+
duration: number | null;
96+
name: string;
97+
size: string;
98+
type: string;
99+
uri: string;
100+
}>
101+
```
102+
89103
### selectedImages
90104

91105
List of currently selected images in attachment picker.
@@ -118,6 +132,14 @@ Setter function for [`bottomInset`](#bottominset)
118132

119133
<!-- ### setMaxNumberOfFiles -->
120134

135+
### setSelectedFiles
136+
137+
Setter function for [`selectedFiles`](#selectedFiles)
138+
139+
| Type |
140+
| ------------------------- |
141+
| `(selectedFiles) => void` |
142+
121143
### setSelectedImages
122144

123145
Setter function for [`selectedImages`](#selectedimages)

examples/ExpoMessaging/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ SPEC CHECKSUMS:
530530
EXSharing: 328228a9f14503cfdec68892796478a7a15b8d4d
531531
EXSplashScreen: 21669e598804ee810547dbb6692c8deb5dd8dbf3
532532
FBLazyVector: c71c5917ec0ad2de41d5d06a5855f6d5eda06971
533-
FBReactNativeSpec: b72999e1c6a58ea23a25a616a814764c0f91577d
533+
FBReactNativeSpec: 244d2780a858c4f0972d17e1d6a0cad15e32fbbc
534534
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
535535
RCT-Folly: ec7a233ccc97cc556cf7237f0db1ff65b986f27c
536536
RCTRequired: d34bf57e17cb6e3b2681f4809b13843c021feb6c
@@ -566,4 +566,4 @@ SPEC CHECKSUMS:
566566

567567
PODFILE CHECKSUM: 8089780b20a2c230f15d6573003c7a651b171fa4
568568

569-
COCOAPODS: 1.11.2
569+
COCOAPODS: 1.11.3

examples/ExpoMessaging/yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,13 @@ babel-plugin-polyfill-regenerator@^0.3.0:
25402540
dependencies:
25412541
"@babel/helper-define-polyfill-provider" "^0.3.1"
25422542

2543+
babel-plugin-polyfill-regenerator@^0.3.0:
2544+
version "0.3.1"
2545+
resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.3.1.tgz#2c0678ea47c75c8cc2fbb1852278d8fb68233990"
2546+
integrity sha512-Y2B06tvgHYt1x0yz17jGkGeeMr5FeKUu+ASJ+N6nB5lQ8Dapfg42i0OVrf8PNGJ3zKL4A23snMi1IRwrqqND7A==
2547+
dependencies:
2548+
"@babel/helper-define-polyfill-provider" "^0.3.1"
2549+
25432550
babel-plugin-react-native-web@~0.17.1:
25442551
version "0.17.7"
25452552
resolved "https://registry.yarnpkg.com/babel-plugin-react-native-web/-/babel-plugin-react-native-web-0.17.7.tgz#1580e27a2e3c6692127535d3880fe1e247ef6414"
@@ -4939,6 +4946,7 @@ [email protected], metro-react-native-babel-preset@~0.64.0:
49394946
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.0.0"
49404947
"@babel/plugin-syntax-optional-chaining" "^7.0.0"
49414948
"@babel/plugin-transform-arrow-functions" "^7.0.0"
4949+
"@babel/plugin-transform-async-to-generator" "^7.0.0"
49424950
"@babel/plugin-transform-block-scoping" "^7.0.0"
49434951
"@babel/plugin-transform-classes" "^7.0.0"
49444952
"@babel/plugin-transform-computed-properties" "^7.0.0"

package/expo-package/src/index.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,19 @@ registerNativeHandlers({
4545
const results = await MediaLibrary.getAssetsAsync({
4646
after,
4747
first,
48-
mediaType: [MediaLibrary.MediaType.photo],
48+
mediaType: [MediaLibrary.MediaType.photo, MediaLibrary.MediaType.video],
4949
});
5050
const assets = results.assets.map((asset) => ({
51+
duration: asset.duration,
52+
filename: asset.filename,
5153
height: asset.height,
5254
id: asset.id,
5355
source: 'picker',
56+
type: asset.mediaType,
5457
uri: asset.uri,
5558
width: asset.width,
5659
}));
60+
5761
const hasNextPage = results.hasNextPage;
5862
const endCursor = results.endCursor;
5963
return { assets, endCursor, hasNextPage };
@@ -155,12 +159,13 @@ registerNativeHandlers({
155159
// https://github.com/ivpusic/react-native-image-crop-picker/issues/901
156160
// This we can't rely on them as it is, and we need to use Image.getSize
157161
// to get accurate size.
158-
const getSize = () => new Promise((resolve) => {
159-
Image.getSize(photo.uri, (width, height) => {
160-
resolve({height, width});
162+
const getSize = () =>
163+
new Promise((resolve) => {
164+
Image.getSize(photo.uri, (width, height) => {
165+
resolve({ height, width });
166+
});
161167
});
162-
});
163-
168+
164169
try {
165170
const { height, width } = await getSize();
166171
size.height = height;
@@ -175,12 +180,12 @@ registerNativeHandlers({
175180
width: photo.width,
176181
};
177182
}
178-
183+
179184
return {
180185
cancelled: false,
181186
source: 'camera',
182187
uri: photo.uri,
183-
...size
188+
...size,
184189
};
185190
}
186191
}

package/native-package/src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ registerNativeHandlers({
7272
}
7373
const results = await CameraRoll.getPhotos({
7474
after,
75-
assetType: 'Photos',
75+
assetType: 'All',
7676
first,
77-
include: ['imageSize'],
77+
include: ['fileSize', 'filename', 'imageSize', 'playableDuration'],
7878
});
7979
const assets = results.edges.map((edge) => ({
8080
...edge.node.image,
@@ -210,11 +210,12 @@ registerNativeHandlers({
210210
// https://github.com/ivpusic/react-native-image-crop-picker/issues/901
211211
// This we can't rely on them as it is, and we need to use Image.getSize
212212
// to get accurate size.
213-
const getSize = () => new Promise((resolve) => {
214-
Image.getSize(photo.path, (width, height) => {
215-
resolve({height, width});
213+
const getSize = () =>
214+
new Promise((resolve) => {
215+
Image.getSize(photo.path, (width, height) => {
216+
resolve({ height, width });
217+
});
216218
});
217-
});
218219

219220
try {
220221
const { height, width } = await getSize();

package/src/components/Attachment/FileIcon.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { SEVEN_Z } from '../../icons/SEVEN_Z';
1919
import { TAR } from '../../icons/TAR';
2020
import { TXT } from '../../icons/TXT';
2121
import type { IconProps } from '../../icons/utils/base';
22+
import { Video } from '../../icons/Video';
2223
import { XLS } from '../../icons/XLS';
2324
import { XLSX } from '../../icons/XLSX';
2425
import { ZIP } from '../../icons/ZIP';
@@ -320,6 +321,46 @@ const zipFileTypes = [
320321
'application/zip',
321322
];
322323

324+
const videoFileTypes = [
325+
'video/3g2',
326+
'video/3gp',
327+
'video/aaf',
328+
'video/asf',
329+
'video/avchd',
330+
'video/avi',
331+
'video/drc',
332+
'video/flv',
333+
'video/m2v',
334+
'video/m3u8',
335+
'video/m4p',
336+
'video/m4v',
337+
'video/mkv',
338+
'video/mng',
339+
'video/mov',
340+
'video/mp2',
341+
'video/mp4',
342+
'video/mpe',
343+
'video/mpeg',
344+
'video/mpg',
345+
'video/mpv',
346+
'video/mxf',
347+
'video/nsv',
348+
'video/ogg',
349+
'video/ogv',
350+
'video/qt',
351+
'video/rm',
352+
'video/rmvb',
353+
'video/roq',
354+
'video/svi',
355+
'video/vob',
356+
'video/webm',
357+
'video/wmv',
358+
'video/yuv',
359+
'video/quicktime',
360+
'video/webm',
361+
'video/x-flv',
362+
];
363+
323364
const mimeTypeToIconMap: Record<string, React.FC<IconProps>> = {
324365
'application/pdf': PDF, // .pdf
325366
'application/rtf': RTF, // .rtf
@@ -371,6 +412,10 @@ for (const type of zipFileTypes) {
371412
mimeTypeToIconMap[type] = ZIP;
372413
}
373414

415+
for (const type of videoFileTypes) {
416+
mimeTypeToIconMap[type] = Video;
417+
}
418+
374419
function mimeTypeToIcon(mimeType?: string): React.FC<IconProps> {
375420
if (!mimeType) return GenericFile;
376421

0 commit comments

Comments
 (0)