@supportworks/multi-imagepicker 8.0.17 → 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,10 @@
1
1
 
2
+ # v8.0.19 2026-03-31
3
+ * tweak to attaching
4
+
5
+ # v8.0.18 2026-03-25
6
+ * refactored attaching
7
+
2
8
  # v8.0.17 2026-03-25
3
9
  * removed CRM modal to see if that fixes it
4
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supportworks/multi-imagepicker",
3
- "version": "8.0.17",
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
@@ -33,6 +99,7 @@ const AddImages = forwardRef((
33
99
  }, ref) => {
34
100
  const [showAttaching, setShowAttaching] = useState(false)
35
101
  const [showAdd, setShowAdd] = useState(false)
102
+ const [pendingAttach, setPendingAttach] = useState(false)
36
103
  const [showInfoDialog, setShowInfoDialog] = useState(false)
37
104
  const [allImageDataValid, setAllImageDataValid] = useState(true)
38
105
  const [showToCust, setShowToCust] = useState(false)
@@ -60,6 +127,7 @@ const AddImages = forwardRef((
60
127
  }, [])
61
128
 
62
129
  const triggerAction = useCallback(() => {
130
+ logAddImages('triggerAction called', { hasPickerRef: !!pickerRef.current })
63
131
  if (pickerRef.current && typeof pickerRef.current.showActionSheet === 'function') {
64
132
  pickerRef.current.showActionSheet()
65
133
  }
@@ -92,6 +160,14 @@ const AddImages = forwardRef((
92
160
  const addPicturesToProject = useCallback(async () => {
93
161
  // go through all images selected and add to project
94
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
+ })
95
171
  loaderHandler.showLoader('Saving Pictures...')
96
172
 
97
173
  // Save selected images to device camera roll (per-item), only for camera-taken images
@@ -105,64 +181,157 @@ const AddImages = forwardRef((
105
181
  {
106
182
  for (const it of toSave) {
107
183
  try {
184
+ logAddImages('CameraRoll.save attempt', summarizeImageForLog(it))
108
185
  await CameraRoll.save(it.path)
186
+ logAddImages('CameraRoll.save success', { path: it.path })
109
187
  } catch (err) {
110
- 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
+ })
111
193
  }
112
194
  }
113
195
  }
114
196
  }
115
197
  }
116
198
  } catch (e) {
117
- 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
+ })
118
203
  }
119
204
 
120
205
  // Upload/add images to project
121
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
+ })
122
213
  if (addPicture) {
123
- 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 })
124
216
  } else {
125
- 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 })
126
219
  }
127
220
  }
128
221
 
129
222
  loaderHandler.hideLoader()
223
+ logAddImages('addPicturesToProject complete', { itemCount: itemsRef.current.length })
130
224
  return true
131
225
  } catch (err) {
132
- 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
+ })
133
232
  loaderHandler.hideLoader()
134
233
  return false
135
234
  }
136
235
  }, [addPicture, prospectInst, hasAndroidWritePermission, showToCust, saveToDevice, allowSaveToDevice])
137
236
 
138
- const onAttach = useCallback(async () => {
237
+ const performAttach = useCallback(async () => {
139
238
  if (!isMountedRef.current) {
140
239
  return
141
240
  }
142
241
 
143
- setShowAttaching(false)
144
- setShowAdd(false)
242
+ logAddImages('performAttach start', {
243
+ itemCount: itemsRef.current.length,
244
+ imageSource: imgSourceRef.current,
245
+ allowEdit,
246
+ allowSaveToDevice,
247
+ showToCustomerAllowed
248
+ })
249
+ setShowAttaching(true)
145
250
 
146
- await addPicturesToProject()
147
- if (allowEdit && allowSaveToDevice) {
148
- await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
251
+ try {
252
+ const addPicturesResult = await addPicturesToProject()
253
+ logAddImages('performAttach addPicturesToProject result', { result: addPicturesResult })
254
+ if (allowEdit && allowSaveToDevice) {
255
+ await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
256
+ }
257
+ if (allowEdit && showToCustomerAllowed) {
258
+ await Api.getApi().setDefaultShowToCustomer(showToCust)
259
+ }
260
+ Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
261
+ if (callback) {
262
+ callback()
263
+ }
264
+ } finally {
265
+ if (isMountedRef.current) {
266
+ setShowAttaching(false)
267
+ setPendingAttach(false)
268
+ }
269
+ logAddImages('performAttach end', {
270
+ itemCount: itemsRef.current.length,
271
+ pendingAttach: false
272
+ })
149
273
  }
150
- if (allowEdit && showToCustomerAllowed) {
151
- await Api.getApi().setDefaultShowToCustomer(showToCust)
274
+ }, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
275
+
276
+ const onAttach = useCallback(() => {
277
+ if (!isMountedRef.current) {
278
+ return
152
279
  }
153
- Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
154
- if (callback) {
155
- callback()
280
+
281
+ logAddImages('onAttach pressed', {
282
+ platform: Platform.OS,
283
+ showAdd,
284
+ itemCount: itemsRef.current.length,
285
+ allImageDataValid,
286
+ imageSource: imgSourceRef.current
287
+ })
288
+
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
+ })
294
+ setPendingAttach(true)
295
+ setShowAdd(false)
296
+ return
156
297
  }
157
- }, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
298
+
299
+ void performAttach()
300
+ }, [allImageDataValid, performAttach, showAdd])
301
+
302
+ const onAddModalDismiss = useCallback(() => {
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) {
312
+ return
313
+ }
314
+
315
+ logAddImages('pendingAttach detected with modal closed, starting performAttach', {
316
+ itemCount: itemsRef.current.length,
317
+ imageSource: imgSourceRef.current
318
+ })
319
+ void performAttach()
320
+ }, [pendingAttach, performAttach, showAdd])
158
321
 
159
322
  const onClose = useCallback(() => {
160
323
  if (!isMountedRef.current) {
161
324
  return
162
325
  }
326
+ logAddImages('onClose called', {
327
+ itemCount: itemsRef.current.length,
328
+ imageSource: imgSourceRef.current,
329
+ pendingAttach
330
+ })
331
+ setPendingAttach(false)
163
332
  setShowAttaching(false)
164
333
  setShowAdd(false)
165
- }, [])
334
+ }, [pendingAttach])
166
335
 
167
336
  const onCloseInfoDialog = useCallback(async (storageVal) => {
168
337
  try {
@@ -283,6 +452,8 @@ const AddImages = forwardRef((
283
452
  // Build unified items list from payload
284
453
  // handle return of selected images from MultiImagePicker
285
454
 
455
+ logAddImages('onImageSelect raw payload', summarizePayloadForLog(payload))
456
+
286
457
  const { imageArray = [], imageDescArray = [], imageValidArray = [] } = payload || {}
287
458
  const timestampSeed = Date.now()
288
459
  itemsRef.current = imageArray.map((img, i) => ({
@@ -295,9 +466,31 @@ const AddImages = forwardRef((
295
466
  }))
296
467
  imgSourceRef.current = payload.imageSource
297
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
+
298
486
  // init for saving selected images to device camera roll, only for camera-taken images
299
487
  const canSaveToDevice = allowSaveToDevicePlatform && (payload.imageSource === 'taken')
300
488
  setAllowSaveToDevice(canSaveToDevice)
489
+ logAddImages('onImageSelect save-to-device capability', {
490
+ allowSaveToDevicePlatform,
491
+ imageSource: payload?.imageSource || null,
492
+ canSaveToDevice
493
+ })
301
494
 
302
495
  if (allowEdit) {
303
496
  const [defaultSaveToDevice, defaultShowToCustomer] = await Promise.all([
@@ -305,6 +498,11 @@ const AddImages = forwardRef((
305
498
  showToCustomerAllowed ? Api.getApi().getDefaultShowToCustomer() : Promise.resolve(false)
306
499
  ])
307
500
 
501
+ logAddImages('onImageSelect default flags loaded', {
502
+ defaultSaveToDevice,
503
+ defaultShowToCustomer
504
+ })
505
+
308
506
  // initialize per-image flags
309
507
  const initialSaveFlag = canSaveToDevice ? defaultSaveToDevice : false
310
508
  const initialShowFlag = showToCustomerAllowed ? !!defaultShowToCustomer : false
@@ -327,8 +525,17 @@ const AddImages = forwardRef((
327
525
  if (skipped !== 'true') {
328
526
  setShowInfoDialog(true)
329
527
  }
528
+ logAddImages('onImageSelect modal shown', {
529
+ itemCount: itemsRef.current.length,
530
+ skippedUploadWarningDialog: skipped === 'true',
531
+ initialSaveFlag,
532
+ initialShowFlag
533
+ })
330
534
  } catch (e) {
331
- 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
+ })
332
539
  setShowInfoDialog(true)
333
540
  }
334
541
  }
@@ -337,6 +544,10 @@ const AddImages = forwardRef((
337
544
  if (isMountedRef.current) {
338
545
  setItems([...itemsRef.current])
339
546
  }
547
+ logAddImages('allowEdit disabled, attaching immediately', {
548
+ itemCount: itemsRef.current.length,
549
+ imageSource: payload?.imageSource || null
550
+ })
340
551
  await onAttach()
341
552
  }
342
553
  }, [allowEdit, buildDefaultFilename, onAttach, showToCustomerAllowed])
@@ -413,9 +624,15 @@ const AddImages = forwardRef((
413
624
  )
414
625
  }
415
626
 
416
- if (showAdd) {
417
- return (
418
- <Modal presentationStyle='fullScreen' animationType='slide'>
627
+ return (
628
+ <>
629
+ {!showAdd && (
630
+ <MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
631
+ {children}
632
+ </MultiImagePicker>
633
+ )}
634
+
635
+ <Modal visible={showAdd} presentationStyle='fullScreen' animationType='slide' onDismiss={onAddModalDismiss}>
419
636
  <ScreenSafeAreaView style={styles.Page} edges={['top','bottom']} includeProvider>
420
637
  <AppBarH8
421
638
  variant='regular'
@@ -460,13 +677,7 @@ const AddImages = forwardRef((
460
677
  />
461
678
  )}
462
679
  </Modal>
463
- )
464
- }
465
-
466
- return (
467
- <MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
468
- {children}
469
- </MultiImagePicker>
680
+ </>
470
681
  )
471
682
  })
472
683