Tengo el siguiente código
<DocumentPicker onDone={(res: DocumentPickerResponse[]) => { if (res.hasOwnProperty('isCancel')) { } else { handleDocumentPicker(res); handleAttachmentResizing(); } toggleDocumentPicker(); }} DocumentPicker permite al usuario elegir un video de su galería, una vez que elige el identificador de video handleDocumentPicker obtiene la matriz de resultados y establece el estado de mi matriz de attachments . A continuación, se llama a handleAttachmentResizing para cambiar el tamaño de todos los archivos adjuntos de video en mi estado de attachments .
Así es como se ve el handleAttachmentResizing
const handleAttachmentResizing = async () => { console.log('handleAttachmentResizing called'); try { console.log('handleAttachmentResizing called try'); lodash.forEach(newAttachments, async (item, idx) => { console.log('handleAttachmentResizing called try lodash'); console.log('handleAttachmentResizing loop ', idx); if (!item.isCompressed && !item.isCompressing && isVideo(item.type)) { const resizedVideo = await resizeVideo(item, idx); if (resizedVideo) { const uri = await moveFile(resizedVideo); const update: Attachment = { ...item, isCompressed: true, isCompressing: false, uri, }; updateAttachment(item.uri, update); } } }); } catch (err) { console.error('handleAttachmentResizing ', err); } console.log('handleAttachmentResizing called');};
Y resizeVideo se ve así
const resizeVideo = async (attachment: Attachment, idx: number) => { console.log('resizeVideo called'); try { return await Video.compress( attachment.uri, { compressionMethod: 'auto', getCancellationId: (cancellationId) => setVideoCancellationToken(cancellationId), }, (progress) => { if(mounted.current){ const updated: Attachment = { ...attachment, progress, isCompressing: true, }; updateAttachment(attachment.uri, updated); }else { //Video.cancelCompression() handleRemoveAttachment(attachment, idx); } }, ); } catch (err) { console.error('resizeVideo ', err); handleRemoveAttachment(attachment, idx); } }; No estoy seguro de por qué, pero handleAttachmentResizing solo imprime handleAttachmentResizing called try y termina allí, si elijo otro archivo en mi galería, misteriosamente continúa ejecutándose.