@@ -124,11 +124,7 @@ export default function ComposeMenu(props: Props): Node {
124
124
125
125
const { assets } = response ;
126
126
127
- // TODO: support sending multiple files; see library's docs for how to
128
- // let `assets` have more than one item in `response`.
129
- const firstAsset = assets && assets [ 0 ] ;
130
-
131
- if ( ! firstAsset ) {
127
+ if ( ! assets || ! assets [ 0 ] ) {
132
128
// TODO: See if we these unexpected situations actually happen. …Ah,
133
129
// yep, reportedly (and we've seen in Sentry):
134
130
// https://github.com/react-native-image-picker/react-native-image-picker/issues/1945
@@ -139,22 +135,39 @@ export default function ComposeMenu(props: Props): Node {
139
135
return ;
140
136
}
141
137
142
- const { uri, fileName } = firstAsset ;
138
+ const attachments = [ ] ;
139
+ let numMalformed = 0 ;
140
+ assets . forEach ( ( asset , i ) => {
141
+ const { uri, fileName } = asset ;
143
142
144
- if ( uri == null || fileName == null ) {
145
- // TODO: See if these unexpected situations actually happen.
146
- showErrorAlert ( _ ( 'Error' ) , _ ( 'Failed to attach your file.' ) ) ;
147
- logging . error (
148
- 'First (should be only) asset returned from image picker had nullish `url` and/or `fileName`' ,
149
- {
143
+ if ( uri == null || fileName == null ) {
144
+ // TODO: See if these unexpected situations actually happen.
145
+ logging . error ( 'An asset returned from image picker had nullish `url` and/or `fileName`' , {
150
146
'uri == null' : uri == null ,
151
147
'fileName == null' : fileName == null ,
152
- } ,
153
- ) ;
154
- return ;
148
+ i,
149
+ } ) ;
150
+ numMalformed ++ ;
151
+ return ;
152
+ }
153
+
154
+ attachments . push ( { name : chooseUploadImageFilename ( uri , fileName ) , url : uri } ) ;
155
+ } ) ;
156
+
157
+ if ( numMalformed > 0 ) {
158
+ if ( assets . length === 1 && numMalformed === 1 ) {
159
+ showErrorAlert ( _ ( 'Error' ) , _ ( 'Failed to attach your file.' ) ) ;
160
+ return ;
161
+ } else if ( assets . length === numMalformed ) {
162
+ showErrorAlert ( _ ( 'Error' ) , _ ( 'Failed to attach your files.' ) ) ;
163
+ return ;
164
+ } else {
165
+ showErrorAlert ( _ ( 'Error' ) , _ ( 'Failed to attach some of your files.' ) ) ;
166
+ // no return; `attachments` will have some items that we can insert
167
+ }
155
168
}
156
169
157
- insertAttachments ( [ { name : chooseUploadImageFilename ( uri , fileName ) , url : uri } ] ) ;
170
+ insertAttachments ( attachments ) ;
158
171
} ,
159
172
[ _ , insertAttachments ] ,
160
173
) ;
@@ -167,6 +180,17 @@ export default function ComposeMenu(props: Props): Node {
167
180
168
181
quality : 1.0 ,
169
182
includeBase64 : false ,
183
+
184
+ // From the doc:
185
+ // https://github.com/react-native-image-picker/react-native-image-picker/tree/v4.8.4#options
186
+ // > […] use `0` to allow any number of files. Only iOS version >=
187
+ // > 14 support `0` and also it supports providing any integer value
188
+ //
189
+ // On Android, the implementation now seems to put you into a kind
190
+ // of file picker UI filtered down to images, instead of into the
191
+ // Gallery app. See screen recordings on a recent Android:
192
+ // https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Android.20select.20multiple.20photos/near/1423109
193
+ selectionLimit : 0 ,
170
194
} ,
171
195
handleImagePickerResponse ,
172
196
) ;
0 commit comments