@supportworks/multi-imagepicker 7.3.2 → 8.0.1
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/README.md +43 -219
- package/TestMIP.js +103 -0
- package/changes.md +5 -14
- package/index.js +3 -3
- package/package.json +2 -1
- package/src/components/ActionBar.js +3 -3
- package/src/components/AddImages.js +175 -119
- package/src/components/CameraModal.tsx +790 -0
- package/src/components/ImageDetailsModal.js +11 -20
- package/src/components/ImageIndicators.js +7 -5
- package/src/components/MultiImagePicker.js +76 -10
- package/src/components/MultiImagePicker_JOHNRIPPLE.js +348 -0
- package/src/components/MultiImagePicker_OLD.js +281 -0
- package/src/components/SelectedImages.js +5 -5
- package/src/components/SingleImage.js +6 -6
- package/src/components/UploadWarningModal.js +40 -50
- package/src/lib/MIPickerApi.js +14 -17
- package/src/components/AddImagesProvider.js +0 -269
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useState, useRef, forwardRef, useImperativeHandle } from 'react'
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
View,
|
|
4
|
+
Modal,
|
|
5
|
+
SafeAreaView,
|
|
6
|
+
StyleSheet, ScrollView, KeyboardAvoidingView, Platform, PermissionsAndroid, Alert
|
|
4
7
|
} from 'react-native'
|
|
5
8
|
import Moment from 'moment'
|
|
9
|
+
import { Icons } from '@supportworks/icon-library'
|
|
6
10
|
import loaderHandler from './loaderHandler'
|
|
7
11
|
import MultiImagePicker from './MultiImagePicker'
|
|
12
|
+
import SelectedImages from './SelectedImages'
|
|
13
|
+
import { colors } from '@supportworks/app-styler'
|
|
14
|
+
import { LoadingOverlay } from '@supportworks/navbars'
|
|
15
|
+
import { CheckBox, AppBarH8, CommonButton, ListItem } from '@supportworks/core-controls'
|
|
8
16
|
import { CameraRoll } from '@react-native-camera-roll/camera-roll'
|
|
9
17
|
import { Api } from '@supportworks/api-core'
|
|
10
18
|
import { Analytics } from '@supportworks/analytics'
|
|
11
19
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
12
|
-
import
|
|
20
|
+
import UploadWarningModal from './UploadWarningModal'
|
|
13
21
|
|
|
14
22
|
const AddImages = forwardRef((
|
|
15
23
|
{
|
|
@@ -24,7 +32,6 @@ const AddImages = forwardRef((
|
|
|
24
32
|
maxCount, // = null, //max number of images that can be selected. Passed to MultiImagePicker. If null default not commented out, causes crash, so leave it this way.
|
|
25
33
|
children
|
|
26
34
|
}, ref) => {
|
|
27
|
-
const updateAddImagesProvider = useAddImagesProvider()
|
|
28
35
|
const [showAttaching, setShowAttaching] = useState(false)
|
|
29
36
|
const [showAdd, setShowAdd] = useState(false)
|
|
30
37
|
const [showInfoDialog, setShowInfoDialog] = useState(false)
|
|
@@ -40,30 +47,14 @@ const AddImages = forwardRef((
|
|
|
40
47
|
const imgSourceRef = useRef(null) // temp value designating picker type used, if image was "taken" from device now, or image(s) chosen from "library"
|
|
41
48
|
const pickerRef = useRef(null)
|
|
42
49
|
const isMountedRef = useRef(true)
|
|
43
|
-
const hasPublishedEditorRef = useRef(false)
|
|
44
|
-
const onCloseRef = useRef(null)
|
|
45
|
-
const onAttachRef = useRef(null)
|
|
46
|
-
const onDeleteItemRef = useRef(null)
|
|
47
|
-
const onItemChangeRef = useRef(null)
|
|
48
|
-
const onCloseInfoDialogRef = useRef(null)
|
|
49
|
-
const onValidateRef = useRef(null)
|
|
50
|
-
const onPressCheckboxShowToCustRef = useRef(null)
|
|
51
|
-
const onPressCheckboxSaveToDeviceRef = useRef(null)
|
|
52
50
|
const STORAGE_KEY_SKIP_DIALOG = '@MIP_UploadWarningsModal_Skip'
|
|
53
51
|
const allowSaveToDevicePlatform = Platform.OS !== 'android' // TODO: set to true when Android support is added
|
|
54
52
|
|
|
55
53
|
useEffect(() => {
|
|
56
54
|
return () => {
|
|
57
|
-
if (hasPublishedEditorRef.current) {
|
|
58
|
-
updateAddImagesProvider({
|
|
59
|
-
visible: false,
|
|
60
|
-
attaching: false,
|
|
61
|
-
editorProps: null
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
55
|
isMountedRef.current = false
|
|
65
56
|
}
|
|
66
|
-
}, [
|
|
57
|
+
}, [])
|
|
67
58
|
|
|
68
59
|
const setPickerRef = useCallback((node) => {
|
|
69
60
|
pickerRef.current = node
|
|
@@ -150,25 +141,19 @@ const AddImages = forwardRef((
|
|
|
150
141
|
return
|
|
151
142
|
}
|
|
152
143
|
|
|
144
|
+
setShowAttaching(false)
|
|
153
145
|
setShowAdd(false)
|
|
154
|
-
setShowAttaching(true)
|
|
155
146
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
callback()
|
|
167
|
-
}
|
|
168
|
-
} finally {
|
|
169
|
-
if (isMountedRef.current) {
|
|
170
|
-
setShowAttaching(false)
|
|
171
|
-
}
|
|
147
|
+
await addPicturesToProject()
|
|
148
|
+
if (allowEdit && allowSaveToDevice) {
|
|
149
|
+
await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
|
|
150
|
+
}
|
|
151
|
+
if (allowEdit && showToCustomerAllowed) {
|
|
152
|
+
await Api.getApi().setDefaultShowToCustomer(showToCust)
|
|
153
|
+
}
|
|
154
|
+
Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
|
|
155
|
+
if (callback) {
|
|
156
|
+
callback()
|
|
172
157
|
}
|
|
173
158
|
}, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
|
|
174
159
|
|
|
@@ -357,94 +342,165 @@ const AddImages = forwardRef((
|
|
|
357
342
|
}
|
|
358
343
|
}, [allowEdit, buildDefaultFilename, onAttach, showToCustomerAllowed])
|
|
359
344
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
onDeleteItemRef.current = handleDeleteItem
|
|
364
|
-
onItemChangeRef.current = onItemChange
|
|
365
|
-
onCloseInfoDialogRef.current = onCloseInfoDialog
|
|
366
|
-
onValidateRef.current = handleSetAllImageDataValid
|
|
367
|
-
onPressCheckboxShowToCustRef.current = onPressCheckbox_ShowToCust
|
|
368
|
-
onPressCheckboxSaveToDeviceRef.current = onPressCheckbox_SaveToDevice
|
|
369
|
-
}, [
|
|
370
|
-
handleDeleteItem,
|
|
371
|
-
handleSetAllImageDataValid,
|
|
372
|
-
onAttach,
|
|
373
|
-
onClose,
|
|
374
|
-
onCloseInfoDialog,
|
|
375
|
-
onItemChange,
|
|
376
|
-
onPressCheckbox_SaveToDevice,
|
|
377
|
-
onPressCheckbox_ShowToCust
|
|
378
|
-
])
|
|
379
|
-
|
|
380
|
-
const externalOnClose = useCallback((...args) => onCloseRef.current?.(...args), [])
|
|
381
|
-
const externalOnAttach = useCallback((...args) => onAttachRef.current?.(...args), [])
|
|
382
|
-
const externalOnDeleteItem = useCallback((...args) => onDeleteItemRef.current?.(...args), [])
|
|
383
|
-
const externalOnItemChange = useCallback((...args) => onItemChangeRef.current?.(...args), [])
|
|
384
|
-
const externalOnCloseInfoDialog = useCallback((...args) => onCloseInfoDialogRef.current?.(...args), [])
|
|
385
|
-
const externalOnValidate = useCallback((...args) => onValidateRef.current?.(...args), [])
|
|
386
|
-
const externalOnPressCheckboxShowToCust = useCallback((...args) => onPressCheckboxShowToCustRef.current?.(...args), [])
|
|
387
|
-
const externalOnPressCheckboxSaveToDevice = useCallback((...args) => onPressCheckboxSaveToDeviceRef.current?.(...args), [])
|
|
388
|
-
|
|
389
|
-
useEffect(() => {
|
|
390
|
-
if (showAdd || showAttaching) {
|
|
391
|
-
hasPublishedEditorRef.current = true
|
|
392
|
-
updateAddImagesProvider({
|
|
393
|
-
visible: showAdd,
|
|
394
|
-
attaching: showAttaching,
|
|
395
|
-
editorProps: {
|
|
396
|
-
items,
|
|
397
|
-
annotationAllowed,
|
|
398
|
-
showToCustomerAllowed,
|
|
399
|
-
allowSaveToDevice,
|
|
400
|
-
allImageDataValid,
|
|
401
|
-
showInfoDialog,
|
|
402
|
-
onClose: externalOnClose,
|
|
403
|
-
onAttach: externalOnAttach,
|
|
404
|
-
onDeleteItem: externalOnDeleteItem,
|
|
405
|
-
onItemChange: externalOnItemChange,
|
|
406
|
-
onCloseInfoDialog: externalOnCloseInfoDialog,
|
|
407
|
-
onValidate: externalOnValidate,
|
|
408
|
-
onPressCheckboxShowToCust: externalOnPressCheckboxShowToCust,
|
|
409
|
-
onPressCheckboxSaveToDevice: externalOnPressCheckboxSaveToDevice
|
|
410
|
-
}
|
|
411
|
-
})
|
|
412
|
-
return
|
|
345
|
+
const SaveOptions = () => {
|
|
346
|
+
if (!showToCustomerAllowed && !allowSaveToDevice) {
|
|
347
|
+
return null
|
|
413
348
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
349
|
+
const total = items.length
|
|
350
|
+
const saveCount = items.filter(i => !!i.saveToDevice).length
|
|
351
|
+
const showCount = items.filter(i => !!i.showToCust).length
|
|
352
|
+
const allSave = total > 0 && saveCount === total
|
|
353
|
+
const someSave = total > 0 && saveCount > 0 && saveCount < total
|
|
354
|
+
const allShow = total > 0 && showCount === total
|
|
355
|
+
const someShow = total > 0 && showCount > 0 && showCount < total
|
|
356
|
+
// console.log(`SaveOptions: total=${total}, saveCount=${saveCount}, showCount=${showCount}, allSave=${allSave}, someSave=${someSave}, allShow=${allShow}, someShow=${someShow}`)
|
|
357
|
+
|
|
358
|
+
return (
|
|
359
|
+
<View style={styles.SaveOptionsContainer}>
|
|
360
|
+
{showToCustomerAllowed
|
|
361
|
+
? <ListItem
|
|
362
|
+
key='showToCust'
|
|
363
|
+
leftContent={
|
|
364
|
+
<View style={styles.IconCircle}>
|
|
365
|
+
<Icons.IconEye_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
366
|
+
</View>
|
|
367
|
+
}
|
|
368
|
+
mainAction={onPressCheckbox_ShowToCust}
|
|
369
|
+
rightAction={onPressCheckbox_ShowToCust}
|
|
370
|
+
title='Show all to customer'
|
|
371
|
+
subtitle='Select to share all w/ customer.'
|
|
372
|
+
rightContent={<CheckBox
|
|
373
|
+
checked={allShow}
|
|
374
|
+
indeterminate={someShow}
|
|
375
|
+
onChange={onPressCheckbox_ShowToCust}
|
|
376
|
+
/>}
|
|
377
|
+
height={55}
|
|
378
|
+
paddingLeft={20}
|
|
379
|
+
rightContentWidth={40}
|
|
380
|
+
paddingRight={16}
|
|
381
|
+
topSeparator={false}
|
|
382
|
+
/>
|
|
383
|
+
: null}
|
|
384
|
+
{allowSaveToDevice
|
|
385
|
+
? <ListItem
|
|
386
|
+
key='saveToDevice'
|
|
387
|
+
leftContent={
|
|
388
|
+
<View style={styles.IconCircle}>
|
|
389
|
+
<Icons.IconSave_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
390
|
+
</View>
|
|
391
|
+
}
|
|
392
|
+
mainAction={onPressCheckbox_SaveToDevice}
|
|
393
|
+
rightAction={onPressCheckbox_SaveToDevice}
|
|
394
|
+
title='Download all to device'
|
|
395
|
+
rightContent={<CheckBox
|
|
396
|
+
checked={allSave}
|
|
397
|
+
indeterminate={someSave}
|
|
398
|
+
onChange={onPressCheckbox_SaveToDevice}
|
|
399
|
+
/>}
|
|
400
|
+
height={56}
|
|
401
|
+
paddingLeft={20}
|
|
402
|
+
rightContentWidth={40}
|
|
403
|
+
paddingRight={16}
|
|
404
|
+
topSeparator={showToCustomerAllowed}
|
|
405
|
+
/>
|
|
406
|
+
: null}
|
|
407
|
+
</View>
|
|
408
|
+
)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (showAttaching) {
|
|
412
|
+
return (
|
|
413
|
+
<LoadingOverlay />
|
|
414
|
+
)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (showAdd) {
|
|
418
|
+
return (
|
|
419
|
+
<Modal presentationStyle='fullScreen' animationType='slide'>
|
|
420
|
+
<SafeAreaView style={styles.Page}>
|
|
421
|
+
<AppBarH8
|
|
422
|
+
variant='regular'
|
|
423
|
+
title='Photos to Add'
|
|
424
|
+
subtitle={items.length + ' Photo' + (items.length > 1 ? 's' : '')}
|
|
425
|
+
leftContentType='closeButton'
|
|
426
|
+
callback={onClose}
|
|
427
|
+
bgColor={colors.backgroundMedium}
|
|
428
|
+
bottomShadow
|
|
429
|
+
/>
|
|
430
|
+
<SaveOptions />
|
|
431
|
+
<KeyboardAvoidingView behavior='padding' enabled style={styles.Content}>
|
|
432
|
+
<ScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='handled'>
|
|
433
|
+
<SelectedImages
|
|
434
|
+
items={items}
|
|
435
|
+
callback={handleSetAllImageDataValid}
|
|
436
|
+
annotationAllowed={annotationAllowed}
|
|
437
|
+
onDeleteItem={handleDeleteItem}
|
|
438
|
+
onItemChange={onItemChange}
|
|
439
|
+
allowSaveToDevice={allowSaveToDevice}
|
|
440
|
+
allowShowToCustomer={showToCustomerAllowed}
|
|
441
|
+
/>
|
|
442
|
+
</ScrollView>
|
|
443
|
+
</KeyboardAvoidingView>
|
|
444
|
+
<View style={styles.ButtonContainer}>
|
|
445
|
+
<CommonButton
|
|
446
|
+
variant='filled'
|
|
447
|
+
size='medium'
|
|
448
|
+
fullWidth
|
|
449
|
+
label='Attach'
|
|
450
|
+
endIcon={<Icons.IconUploadAll />}
|
|
451
|
+
onPress={onAttach}
|
|
452
|
+
disabled={!allImageDataValid}
|
|
453
|
+
/>
|
|
454
|
+
</View>
|
|
455
|
+
</SafeAreaView>
|
|
456
|
+
|
|
457
|
+
<UploadWarningModal
|
|
458
|
+
visible={showInfoDialog}
|
|
459
|
+
onClose={onCloseInfoDialog}
|
|
460
|
+
/>
|
|
461
|
+
</Modal>
|
|
462
|
+
)
|
|
463
|
+
}
|
|
442
464
|
|
|
443
465
|
return (
|
|
444
|
-
|
|
466
|
+
<MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
|
|
445
467
|
{children}
|
|
446
468
|
</MultiImagePicker>
|
|
447
469
|
)
|
|
448
470
|
})
|
|
449
471
|
|
|
472
|
+
const styles = StyleSheet.create({
|
|
473
|
+
Page: {
|
|
474
|
+
backgroundColor: colors.backgroundMedium,
|
|
475
|
+
flex: 1
|
|
476
|
+
},
|
|
477
|
+
Content: {
|
|
478
|
+
flex: 1
|
|
479
|
+
},
|
|
480
|
+
ScrollViewContainer: {
|
|
481
|
+
paddingBottom: 100,
|
|
482
|
+
marginTop: 8
|
|
483
|
+
},
|
|
484
|
+
SaveOptionsContainer: {
|
|
485
|
+
backgroundColor: colors.white,
|
|
486
|
+
margin: 16,
|
|
487
|
+
borderRadius: 16
|
|
488
|
+
},
|
|
489
|
+
IconCircle: {
|
|
490
|
+
width: 32,
|
|
491
|
+
height: 32,
|
|
492
|
+
borderRadius: 16,
|
|
493
|
+
backgroundColor: colors.buttonPrimaryLight,
|
|
494
|
+
justifyContent: 'center',
|
|
495
|
+
alignItems: 'center'
|
|
496
|
+
},
|
|
497
|
+
ButtonContainer: {
|
|
498
|
+
height: 56,
|
|
499
|
+
paddingHorizontal: 16,
|
|
500
|
+
paddingVertical: 8,
|
|
501
|
+
borderTopWidth: 1,
|
|
502
|
+
borderTopColor: colors.black05
|
|
503
|
+
}
|
|
504
|
+
})
|
|
505
|
+
|
|
450
506
|
export default AddImages
|