@supportworks/multi-imagepicker 8.0.18 → 8.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changes.md CHANGED
@@ -1,4 +1,7 @@
1
1
 
2
+ # v8.0.19 2026-03-31
3
+ * tweak to attaching
4
+
2
5
  # v8.0.18 2026-03-25
3
6
  * refactored attaching
4
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supportworks/multi-imagepicker",
3
- "version": "8.0.18",
3
+ "version": "8.0.19",
4
4
  "description": "Android and iOS customized multiple image picker. For react-native >= 0.60.",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -18,6 +18,72 @@ import { Analytics } from '@supportworks/analytics'
18
18
  import AsyncStorage from '@react-native-async-storage/async-storage'
19
19
  import UploadWarningModal from './UploadWarningModal'
20
20
 
21
+ const ADD_IMAGES_LOG_PREFIX = '[AddImages]'
22
+
23
+ function getFileExtension (value = '') {
24
+ const normalizedValue = String(value || '').split('?')[0]
25
+ const lastSlash = normalizedValue.lastIndexOf('/')
26
+ const lastDot = normalizedValue.lastIndexOf('.')
27
+
28
+ if (lastDot === -1 || lastDot < lastSlash) {
29
+ return ''
30
+ }
31
+
32
+ return normalizedValue.substring(lastDot)
33
+ }
34
+
35
+ function summarizeImageForLog (img = {}, idx = null) {
36
+ const path = img?.path || ''
37
+ const filename = img?.filename || ''
38
+
39
+ return {
40
+ idx,
41
+ path,
42
+ mime: img?.mime || null,
43
+ filename: filename || null,
44
+ filenameHasExtension: !!getFileExtension(filename),
45
+ defaultName: img?.defaultName || null,
46
+ pathExtension: getFileExtension(path) || null,
47
+ width: img?.width ?? null,
48
+ height: img?.height ?? null,
49
+ size: img?.size ?? null,
50
+ sourceURL: img?.sourceURL || null,
51
+ hasDepthMapUri: !!img?.depthMapUri,
52
+ saveToDevice: img?.saveToDevice ?? null,
53
+ showToCust: img?.showToCust ?? null,
54
+ isValid: img?.isValid ?? null
55
+ }
56
+ }
57
+
58
+ function summarizePayloadForLog (payload = {}) {
59
+ const imageArray = Array.isArray(payload?.imageArray) ? payload.imageArray : []
60
+ const imageDescArray = Array.isArray(payload?.imageDescArray) ? payload.imageDescArray : []
61
+ const imageValidArray = Array.isArray(payload?.imageValidArray) ? payload.imageValidArray : []
62
+
63
+ return {
64
+ imageSource: payload?.imageSource || null,
65
+ index: payload?.index ?? null,
66
+ cancelIndex: payload?.cancelIndex ?? null,
67
+ imageCount: imageArray.length,
68
+ descCount: imageDescArray.length,
69
+ validCount: imageValidArray.length,
70
+ images: imageArray.map((img, idx) => summarizeImageForLog(img, idx))
71
+ }
72
+ }
73
+
74
+ function logAddImages (message, details = null) {
75
+ if (details === null || details === undefined) {
76
+ console.log(`${ADD_IMAGES_LOG_PREFIX} ${message}`)
77
+ return
78
+ }
79
+
80
+ try {
81
+ console.log(`${ADD_IMAGES_LOG_PREFIX} ${message}: ${JSON.stringify(details)}`)
82
+ } catch (err) {
83
+ console.log(`${ADD_IMAGES_LOG_PREFIX} ${message}`, details)
84
+ }
85
+ }
86
+
21
87
  const AddImages = forwardRef((
22
88
  {
23
89
  parentStyle = null, // style passed to MultiImagePicker
@@ -61,6 +127,7 @@ const AddImages = forwardRef((
61
127
  }, [])
62
128
 
63
129
  const triggerAction = useCallback(() => {
130
+ logAddImages('triggerAction called', { hasPickerRef: !!pickerRef.current })
64
131
  if (pickerRef.current && typeof pickerRef.current.showActionSheet === 'function') {
65
132
  pickerRef.current.showActionSheet()
66
133
  }
@@ -93,6 +160,14 @@ const AddImages = forwardRef((
93
160
  const addPicturesToProject = useCallback(async () => {
94
161
  // go through all images selected and add to project
95
162
  try {
163
+ logAddImages('addPicturesToProject start', {
164
+ itemCount: itemsRef.current.length,
165
+ imageSource: imgSourceRef.current,
166
+ allowSaveToDevice,
167
+ saveToDevice,
168
+ showToCust,
169
+ items: (itemsRef.current || []).map((item, idx) => summarizeImageForLog(item, idx))
170
+ })
96
171
  loaderHandler.showLoader('Saving Pictures...')
97
172
 
98
173
  // Save selected images to device camera roll (per-item), only for camera-taken images
@@ -106,31 +181,54 @@ const AddImages = forwardRef((
106
181
  {
107
182
  for (const it of toSave) {
108
183
  try {
184
+ logAddImages('CameraRoll.save attempt', summarizeImageForLog(it))
109
185
  await CameraRoll.save(it.path)
186
+ logAddImages('CameraRoll.save success', { path: it.path })
110
187
  } catch (err) {
111
- console.log('CameraRoll.save failed for ' + it.path + '; Error: ' + err)
188
+ logAddImages('CameraRoll.save failed', {
189
+ path: it.path,
190
+ error: err?.message || err?.toString?.() || String(err),
191
+ stack: err?.stack || null
192
+ })
112
193
  }
113
194
  }
114
195
  }
115
196
  }
116
197
  }
117
198
  } catch (e) {
118
- console.log('Error during save-to-device batch: ' + e)
199
+ logAddImages('Error during save-to-device batch', {
200
+ error: e?.message || e?.toString?.() || String(e),
201
+ stack: e?.stack || null
202
+ })
119
203
  }
120
204
 
121
205
  // Upload/add images to project
122
206
  for (let i = 0; i < itemsRef.current.length; i++) {
207
+ const currentItem = itemsRef.current[i]
208
+ logAddImages('Uploading item', {
209
+ idx: i,
210
+ imageSource: imgSourceRef.current,
211
+ item: summarizeImageForLog(currentItem, i)
212
+ })
123
213
  if (addPicture) {
124
- await addPicture(itemsRef.current[i], itemsRef.current[i]?.desc || '', prospectInst)
214
+ const addPictureResult = await addPicture(currentItem, currentItem?.desc || '', prospectInst)
215
+ logAddImages('addPicture result', { idx: i, result: addPictureResult })
125
216
  } else {
126
- await Api.getApi().addOnePictureToProject(itemsRef.current[i], itemsRef.current[i]?.desc || '', prospectInst)
217
+ const apiResult = await Api.getApi().addOnePictureToProject(currentItem, currentItem?.desc || '', prospectInst)
218
+ logAddImages('Api.addOnePictureToProject result', { idx: i, result: apiResult })
127
219
  }
128
220
  }
129
221
 
130
222
  loaderHandler.hideLoader()
223
+ logAddImages('addPicturesToProject complete', { itemCount: itemsRef.current.length })
131
224
  return true
132
225
  } catch (err) {
133
- console.log('----addPicturesToProject: returning false; ERROR: ' + err.toString())
226
+ logAddImages('addPicturesToProject failed', {
227
+ error: err?.message || err?.toString?.() || String(err),
228
+ stack: err?.stack || null,
229
+ imageSource: imgSourceRef.current,
230
+ items: (itemsRef.current || []).map((item, idx) => summarizeImageForLog(item, idx))
231
+ })
134
232
  loaderHandler.hideLoader()
135
233
  return false
136
234
  }
@@ -141,10 +239,18 @@ const AddImages = forwardRef((
141
239
  return
142
240
  }
143
241
 
242
+ logAddImages('performAttach start', {
243
+ itemCount: itemsRef.current.length,
244
+ imageSource: imgSourceRef.current,
245
+ allowEdit,
246
+ allowSaveToDevice,
247
+ showToCustomerAllowed
248
+ })
144
249
  setShowAttaching(true)
145
250
 
146
251
  try {
147
- await addPicturesToProject()
252
+ const addPicturesResult = await addPicturesToProject()
253
+ logAddImages('performAttach addPicturesToProject result', { result: addPicturesResult })
148
254
  if (allowEdit && allowSaveToDevice) {
149
255
  await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
150
256
  }
@@ -160,6 +266,10 @@ const AddImages = forwardRef((
160
266
  setShowAttaching(false)
161
267
  setPendingAttach(false)
162
268
  }
269
+ logAddImages('performAttach end', {
270
+ itemCount: itemsRef.current.length,
271
+ pendingAttach: false
272
+ })
163
273
  }
164
274
  }, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
165
275
 
@@ -168,30 +278,60 @@ const AddImages = forwardRef((
168
278
  return
169
279
  }
170
280
 
281
+ logAddImages('onAttach pressed', {
282
+ platform: Platform.OS,
283
+ showAdd,
284
+ itemCount: itemsRef.current.length,
285
+ allImageDataValid,
286
+ imageSource: imgSourceRef.current
287
+ })
288
+
171
289
  if (Platform.OS === 'ios' && showAdd) {
290
+ logAddImages('onAttach deferring until modal closes on iOS', {
291
+ itemCount: itemsRef.current.length,
292
+ imageSource: imgSourceRef.current
293
+ })
172
294
  setPendingAttach(true)
173
295
  setShowAdd(false)
174
296
  return
175
297
  }
176
298
 
177
299
  void performAttach()
178
- }, [performAttach, showAdd])
300
+ }, [allImageDataValid, performAttach, showAdd])
179
301
 
180
302
  const onAddModalDismiss = useCallback(() => {
181
- if (!pendingAttach) {
303
+ logAddImages('onAddModalDismiss fired', {
304
+ pendingAttach,
305
+ itemCount: itemsRef.current.length,
306
+ imageSource: imgSourceRef.current
307
+ })
308
+ }, [pendingAttach])
309
+
310
+ useEffect(() => {
311
+ if (!pendingAttach || showAdd) {
182
312
  return
183
313
  }
314
+
315
+ logAddImages('pendingAttach detected with modal closed, starting performAttach', {
316
+ itemCount: itemsRef.current.length,
317
+ imageSource: imgSourceRef.current
318
+ })
184
319
  void performAttach()
185
- }, [pendingAttach, performAttach])
320
+ }, [pendingAttach, performAttach, showAdd])
186
321
 
187
322
  const onClose = useCallback(() => {
188
323
  if (!isMountedRef.current) {
189
324
  return
190
325
  }
326
+ logAddImages('onClose called', {
327
+ itemCount: itemsRef.current.length,
328
+ imageSource: imgSourceRef.current,
329
+ pendingAttach
330
+ })
191
331
  setPendingAttach(false)
192
332
  setShowAttaching(false)
193
333
  setShowAdd(false)
194
- }, [])
334
+ }, [pendingAttach])
195
335
 
196
336
  const onCloseInfoDialog = useCallback(async (storageVal) => {
197
337
  try {
@@ -312,6 +452,8 @@ const AddImages = forwardRef((
312
452
  // Build unified items list from payload
313
453
  // handle return of selected images from MultiImagePicker
314
454
 
455
+ logAddImages('onImageSelect raw payload', summarizePayloadForLog(payload))
456
+
315
457
  const { imageArray = [], imageDescArray = [], imageValidArray = [] } = payload || {}
316
458
  const timestampSeed = Date.now()
317
459
  itemsRef.current = imageArray.map((img, i) => ({
@@ -324,9 +466,31 @@ const AddImages = forwardRef((
324
466
  }))
325
467
  imgSourceRef.current = payload.imageSource
326
468
 
469
+ logAddImages('onImageSelect normalized items', {
470
+ imageSource: payload?.imageSource || null,
471
+ itemCount: itemsRef.current.length,
472
+ items: itemsRef.current.map((item, idx) => summarizeImageForLog(item, idx))
473
+ })
474
+
475
+ if (payload?.imageSource === 'taken') {
476
+ const suspiciousTakenItems = itemsRef.current
477
+ .map((item, idx) => ({ idx, item }))
478
+ .filter(({ item }) => !item?.filename || !getFileExtension(item.filename))
479
+ .map(({ idx, item }) => summarizeImageForLog(item, idx))
480
+
481
+ if (suspiciousTakenItems.length > 0) {
482
+ logAddImages('taken image(s) missing filename extension after normalization', suspiciousTakenItems)
483
+ }
484
+ }
485
+
327
486
  // init for saving selected images to device camera roll, only for camera-taken images
328
487
  const canSaveToDevice = allowSaveToDevicePlatform && (payload.imageSource === 'taken')
329
488
  setAllowSaveToDevice(canSaveToDevice)
489
+ logAddImages('onImageSelect save-to-device capability', {
490
+ allowSaveToDevicePlatform,
491
+ imageSource: payload?.imageSource || null,
492
+ canSaveToDevice
493
+ })
330
494
 
331
495
  if (allowEdit) {
332
496
  const [defaultSaveToDevice, defaultShowToCustomer] = await Promise.all([
@@ -334,6 +498,11 @@ const AddImages = forwardRef((
334
498
  showToCustomerAllowed ? Api.getApi().getDefaultShowToCustomer() : Promise.resolve(false)
335
499
  ])
336
500
 
501
+ logAddImages('onImageSelect default flags loaded', {
502
+ defaultSaveToDevice,
503
+ defaultShowToCustomer
504
+ })
505
+
337
506
  // initialize per-image flags
338
507
  const initialSaveFlag = canSaveToDevice ? defaultSaveToDevice : false
339
508
  const initialShowFlag = showToCustomerAllowed ? !!defaultShowToCustomer : false
@@ -356,8 +525,17 @@ const AddImages = forwardRef((
356
525
  if (skipped !== 'true') {
357
526
  setShowInfoDialog(true)
358
527
  }
528
+ logAddImages('onImageSelect modal shown', {
529
+ itemCount: itemsRef.current.length,
530
+ skippedUploadWarningDialog: skipped === 'true',
531
+ initialSaveFlag,
532
+ initialShowFlag
533
+ })
359
534
  } catch (e) {
360
- console.log('AddImages: error reading skip dialog pref: ' + e)
535
+ logAddImages('error reading skip dialog pref', {
536
+ error: e?.message || e?.toString?.() || String(e),
537
+ stack: e?.stack || null
538
+ })
361
539
  setShowInfoDialog(true)
362
540
  }
363
541
  }
@@ -366,6 +544,10 @@ const AddImages = forwardRef((
366
544
  if (isMountedRef.current) {
367
545
  setItems([...itemsRef.current])
368
546
  }
547
+ logAddImages('allowEdit disabled, attaching immediately', {
548
+ itemCount: itemsRef.current.length,
549
+ imageSource: payload?.imageSource || null
550
+ })
369
551
  await onAttach()
370
552
  }
371
553
  }, [allowEdit, buildDefaultFilename, onAttach, showToCustomerAllowed])