From b9dbd9d76cb017bae0323485ba7c8cbe8e8cd3d8 Mon Sep 17 00:00:00 2001 From: Akash Dhiman Date: Wed, 10 Nov 2021 20:10:42 +0530 Subject: [PATCH] image-picker [wip]: Don't immediately send & Send Multiple. TODO: * Choose better name for `toAttachmentResponse` fn. * Break into multiple commits. * FileName isn't appropriate, `react-native-image-picker` modifies it. (it's along the line of `rn_image_picker_lib_temp_*`) --- ios/Podfile.lock | 2 +- ios/ZulipMobile.xcodeproj/project.pbxproj | 4 +-- src/compose/ComposeMenu.js | 37 ++++++++++++++--------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index ee119ad5733..7db9da9bf02 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -644,7 +644,7 @@ SPEC CHECKSUMS: EXScreenOrientation: 09fe6b6b87899ae0c9320255bda7b7513cdfc8ec EXWebBrowser: 76783ba5dcb8699237746ecf41a9643d428a4cc5 FBLazyVector: e686045572151edef46010a6f819ade377dfeb4b - FBReactNativeSpec: b96f20d2bcabd43e9acdeff6210208026a13633a + FBReactNativeSpec: 84bf0ee621e47a89282c2b1960e92dcb9d991b0c Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021 Flipper-DoubleConversion: 38631e41ef4f9b12861c67d17cb5518d06badc41 Flipper-Folly: 755929a4f851b2fb2c347d533a23f191b008554c diff --git a/ios/ZulipMobile.xcodeproj/project.pbxproj b/ios/ZulipMobile.xcodeproj/project.pbxproj index d6643914661..6f118b25beb 100644 --- a/ios/ZulipMobile.xcodeproj/project.pbxproj +++ b/ios/ZulipMobile.xcodeproj/project.pbxproj @@ -462,7 +462,7 @@ COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; - "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 "; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -524,7 +524,7 @@ COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; - "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 "; + "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; diff --git a/src/compose/ComposeMenu.js b/src/compose/ComposeMenu.js index 3cccfca125e..6b9ed31e3ef 100644 --- a/src/compose/ComposeMenu.js +++ b/src/compose/ComposeMenu.js @@ -3,6 +3,7 @@ import React, { PureComponent } from 'react'; import type { ComponentType } from 'react'; import { Platform, View, Alert, Linking } from 'react-native'; import type { DocumentPickerResponse } from 'react-native-document-picker'; +import type { Asset } from 'react-native-image-picker'; import { launchCamera, launchImageLibrary } from 'react-native-image-picker'; import * as logging from '../utils/logging'; @@ -20,7 +21,6 @@ import { IconVideo, } from '../common/Icons'; import AnimatedComponent from '../animation/AnimatedComponent'; -import { uploadFile } from '../actions'; import { androidEnsureStoragePermission } from '../lightbox/download'; type OuterProps = $ReadOnly<{| @@ -88,8 +88,23 @@ class ComposeMenuInner extends PureComponent { static contextType = TranslationContext; context: GetText; + toAttachmentResponse = (assets: Array): Array => { + const images = []; + for (let i = 0; i < assets.length; i++) { + const asset = assets[i]; + if (asset.type !== undefined && asset.uri !== undefined) { + images.push({ + name: asset.fileName, + size: asset.fileSize, + type: asset.type, + uri: asset.uri, + }); + } + } + return images; + }; + handleImagePickerResponse = response => { - const { dispatch, destinationNarrow } = this.props; const _ = this.context; if (response.didCancel === true) { @@ -130,24 +145,15 @@ class ComposeMenuInner extends PureComponent { return; } - // TODO: support sending multiple files; see library's docs for how to - // let `assets` have more than one item in `response`. - const firstAsset = response.assets && response.assets[0]; - - const { uri, fileName } = firstAsset ?? {}; - - if (!firstAsset || uri == null || fileName == null) { + if (!response.assets) { // TODO: See if we these unexpected situations actually happen. showErrorAlert(_('Error'), _('Something went wrong, and your message was not sent.')); - logging.error('Unexpected response from image picker', { - '!firstAsset': !firstAsset, - 'uri == null': uri == null, - 'fileName == null': fileName == null, - }); + logging.error('Unexpected response from image picker'); return; } - dispatch(uploadFile(destinationNarrow, uri, chooseUploadImageFilename(uri, fileName))); + // dispatch(uploadFile(destinationNarrow, uri, chooseUploadImageFilename(uri, fileName))); + this.props.insertAttachment(this.toAttachmentResponse(response.assets)); }; handleImagePicker = () => { @@ -158,6 +164,7 @@ class ComposeMenuInner extends PureComponent { quality: 1.0, includeBase64: false, + selectionLimit: 0, }, this.handleImagePickerResponse, );