Skip to content

Commit 08f5f37

Browse files
authored
[Video] Allow drag-and-drop & pasting video (#5252)
* allow DnD/pasting video * rm await
1 parent 6bc5a05 commit 08f5f37

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/view/com/composer/Composer.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,13 @@ export const ComposePost = observer(function ComposePost({
303303
const onPhotoPasted = useCallback(
304304
async (uri: string) => {
305305
track('Composer:PastedPhotos')
306-
await gallery.paste(uri)
306+
if (uri.startsWith('data:video/')) {
307+
selectVideo({uri, type: 'video', height: 0, width: 0})
308+
} else {
309+
await gallery.paste(uri)
310+
}
307311
},
308-
[gallery, track],
312+
[gallery, track, selectVideo],
309313
)
310314

311315
const isAltTextRequiredAndMissing = useMemo(() => {

src/view/com/composer/text-input/TextInput.web.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export const TextInput = React.forwardRef(function TextInputImpl(
9393
}
9494
}, [onPressPublish])
9595
React.useEffect(() => {
96-
textInputWebEmitter.addListener('photo-pasted', onPhotoPasted)
96+
textInputWebEmitter.addListener('media-pasted', onPhotoPasted)
9797
return () => {
98-
textInputWebEmitter.removeListener('photo-pasted', onPhotoPasted)
98+
textInputWebEmitter.removeListener('media-pasted', onPhotoPasted)
9999
}
100100
}, [onPhotoPasted])
101101

@@ -105,8 +105,8 @@ export const TextInput = React.forwardRef(function TextInputImpl(
105105
if (transfer) {
106106
const items = transfer.items
107107

108-
getImageFromUri(items, (uri: string) => {
109-
textInputWebEmitter.emit('photo-pasted', uri)
108+
getImageOrVideoFromUri(items, (uri: string) => {
109+
textInputWebEmitter.emit('media-pasted', uri)
110110
})
111111
}
112112

@@ -160,8 +160,8 @@ export const TextInput = React.forwardRef(function TextInputImpl(
160160
view.pasteText(text)
161161
preventDefault = true
162162
}
163-
getImageFromUri(clipboardData.items, (uri: string) => {
164-
textInputWebEmitter.emit('photo-pasted', uri)
163+
getImageOrVideoFromUri(clipboardData.items, (uri: string) => {
164+
textInputWebEmitter.emit('media-pasted', uri)
165165
})
166166
if (preventDefault) {
167167
// Return `true` to prevent ProseMirror's default paste behavior.
@@ -346,7 +346,7 @@ const styles = StyleSheet.create({
346346
},
347347
})
348348

349-
function getImageFromUri(
349+
function getImageOrVideoFromUri(
350350
items: DataTransferItemList,
351351
callback: (uri: string) => void,
352352
) {
@@ -363,11 +363,21 @@ function getImageFromUri(
363363
if (blob.type.startsWith('image/')) {
364364
blobToDataUri(blob).then(callback, err => console.error(err))
365365
}
366+
367+
if (blob.type.startsWith('video/')) {
368+
blobToDataUri(blob).then(callback, err => console.error(err))
369+
}
366370
}
367371
})
368372
} else if (type.startsWith('image/')) {
369373
const file = item.getAsFile()
370374

375+
if (file) {
376+
blobToDataUri(file).then(callback, err => console.error(err))
377+
}
378+
} else if (type.startsWith('video/')) {
379+
const file = item.getAsFile()
380+
371381
if (file) {
372382
blobToDataUri(file).then(callback, err => console.error(err))
373383
}

0 commit comments

Comments
 (0)