@supportworks/multi-imagepicker 6.0.0 → 7.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/changes.md +5 -0
- package/index.js +15 -9
- package/package.json +2 -2
- package/src/components/ActionBar.js +104 -0
- package/src/components/AddImages.js +473 -304
- package/src/components/ImageDetailsModal.js +134 -0
- package/src/components/ImageIndicators.js +85 -0
- package/src/components/MultiImagePicker.js +284 -264
- package/src/components/SelectedImages.js +130 -67
- package/src/components/SingleImage.js +320 -182
- package/src/components/UploadWarningModal.js +105 -0
- package/src/components/loaderHandler.js +5 -5
- package/src/lib/MIPickerApi.js +78 -39
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import React, { useEffect, useState, useRef, useCallback } from 'react'
|
|
2
|
+
import { Modal, SafeAreaView, View, Image, StyleSheet, TouchableOpacity, Text, KeyboardAvoidingView, Platform } from 'react-native'
|
|
3
|
+
import { AppBarH8 } from '@supportworks/core-controls'
|
|
4
|
+
import { colors, stdStyles } from '@supportworks/app-styler'
|
|
5
|
+
import { TextInputSWMD } from '@supportworks/swmaterialdesign'
|
|
6
|
+
|
|
7
|
+
const ImageDetailsModal = (
|
|
8
|
+
{
|
|
9
|
+
visible = false,
|
|
10
|
+
onClose = null,
|
|
11
|
+
imageUri = null,
|
|
12
|
+
initialTitle = '',
|
|
13
|
+
initialDesc = '',
|
|
14
|
+
titleEditable = true,
|
|
15
|
+
onSubmit = null
|
|
16
|
+
}) => {
|
|
17
|
+
const [localTitle, setLocalTitle] = useState(initialTitle)
|
|
18
|
+
const [localDesc, setLocalDesc] = useState(initialDesc)
|
|
19
|
+
const [inputResetKey, setInputResetKey] = useState(0)
|
|
20
|
+
const titleValidRef = useRef(true)
|
|
21
|
+
|
|
22
|
+
const handleClose = useCallback(() => {
|
|
23
|
+
if (onClose) onClose()
|
|
24
|
+
}, [initialTitle, initialDesc, onClose])
|
|
25
|
+
|
|
26
|
+
const onDone = useCallback(() => {
|
|
27
|
+
if (onSubmit) onSubmit({ title: localTitle, desc: localDesc, isTitleValid: titleValidRef.current })
|
|
28
|
+
}, [localTitle, localDesc, onSubmit])
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
// Sync inputs with the latest upstream values and remount so TextInputSWMD picks them up
|
|
32
|
+
setLocalTitle(initialTitle)
|
|
33
|
+
setLocalDesc(initialDesc)
|
|
34
|
+
titleValidRef.current = true
|
|
35
|
+
setInputResetKey(k => k + 1)
|
|
36
|
+
}, [visible, initialTitle, initialDesc])
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Modal
|
|
40
|
+
presentationStyle='fullScreen'
|
|
41
|
+
animationType='slide'
|
|
42
|
+
visible={visible}
|
|
43
|
+
onRequestClose={handleClose}
|
|
44
|
+
>
|
|
45
|
+
<SafeAreaView style={styles.Page}>
|
|
46
|
+
<AppBarH8
|
|
47
|
+
variant='regular'
|
|
48
|
+
title=''
|
|
49
|
+
leftContentType='closeButton'
|
|
50
|
+
callback={handleClose}
|
|
51
|
+
rightContent={
|
|
52
|
+
<TouchableOpacity
|
|
53
|
+
onPress={onDone}
|
|
54
|
+
disabled={!titleValidRef.current}
|
|
55
|
+
>
|
|
56
|
+
<Text style={[styles.DoneText, !titleValidRef.current ? styles.DoneTextDisabled : null]}>Done</Text>
|
|
57
|
+
</TouchableOpacity>
|
|
58
|
+
}
|
|
59
|
+
bottomShadow
|
|
60
|
+
/>
|
|
61
|
+
<View style={styles.ImageContainer}>
|
|
62
|
+
<Image
|
|
63
|
+
source={{ uri: imageUri }}
|
|
64
|
+
resizeMode='cover'
|
|
65
|
+
style={[styles.Image]}
|
|
66
|
+
/>
|
|
67
|
+
</View>
|
|
68
|
+
<KeyboardAvoidingView style={styles.KeyboardAvoidingView} behavior={Platform.OS === 'ios' ? 'padding' : 'position'} enabled>
|
|
69
|
+
<View style={styles.InputContainer}>
|
|
70
|
+
<TextInputSWMD
|
|
71
|
+
key={`title-${inputResetKey}`}
|
|
72
|
+
label='Title*'
|
|
73
|
+
value={localTitle}
|
|
74
|
+
multiline={false}
|
|
75
|
+
maxLength={30}
|
|
76
|
+
validationType='1'
|
|
77
|
+
clearButtonMode='always'
|
|
78
|
+
required
|
|
79
|
+
autoFocus={titleEditable && visible}
|
|
80
|
+
validationFailMsg='Title contains invalid characters'
|
|
81
|
+
callback={(payload) => {
|
|
82
|
+
setLocalTitle(payload.inputValue)
|
|
83
|
+
titleValidRef.current = payload.isValueValid
|
|
84
|
+
}}
|
|
85
|
+
editable={titleEditable}
|
|
86
|
+
disabled={!titleEditable}
|
|
87
|
+
/>
|
|
88
|
+
<TextInputSWMD
|
|
89
|
+
key={`desc-${inputResetKey}`}
|
|
90
|
+
label='Description'
|
|
91
|
+
value={localDesc}
|
|
92
|
+
multiline
|
|
93
|
+
maxLength={255}
|
|
94
|
+
validationType='0'
|
|
95
|
+
callback={(payload) => setLocalDesc(payload.inputValue)}
|
|
96
|
+
/>
|
|
97
|
+
</View>
|
|
98
|
+
</KeyboardAvoidingView>
|
|
99
|
+
</SafeAreaView>
|
|
100
|
+
</Modal>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const styles = StyleSheet.create({
|
|
105
|
+
Page: {
|
|
106
|
+
flex: 1,
|
|
107
|
+
backgroundColor: colors.white
|
|
108
|
+
},
|
|
109
|
+
ImageContainer: {
|
|
110
|
+
flex: 1,
|
|
111
|
+
margin: 16
|
|
112
|
+
},
|
|
113
|
+
Image: {
|
|
114
|
+
flex: 1,
|
|
115
|
+
borderRadius: 16
|
|
116
|
+
},
|
|
117
|
+
KeyboardAvoidingView: {
|
|
118
|
+
flex: 1,
|
|
119
|
+
justifyContent: 'flex-end'
|
|
120
|
+
},
|
|
121
|
+
InputContainer: {
|
|
122
|
+
paddingHorizontal: 16,
|
|
123
|
+
paddingTop: 8
|
|
124
|
+
},
|
|
125
|
+
DoneText: {
|
|
126
|
+
...stdStyles.S1,
|
|
127
|
+
color: colors.buttonPrimary
|
|
128
|
+
},
|
|
129
|
+
DoneTextDisabled: {
|
|
130
|
+
color: colors.buttonPrimaryLight
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
export default ImageDetailsModal
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Platform
|
|
6
|
+
} from 'react-native'
|
|
7
|
+
import { colors } from '@supportworks/app-styler'
|
|
8
|
+
import { Icons } from '@supportworks/icon-library'
|
|
9
|
+
import { BlurView } from '@react-native-community/blur'
|
|
10
|
+
|
|
11
|
+
const ImageIndicators = (
|
|
12
|
+
{
|
|
13
|
+
saveToDevice = false,
|
|
14
|
+
allowSaveToDevice = null,
|
|
15
|
+
allowShowToCustomer = null,
|
|
16
|
+
showToCust = false
|
|
17
|
+
}) => {
|
|
18
|
+
return (
|
|
19
|
+
((allowShowToCustomer && showToCust) || (allowSaveToDevice && saveToDevice)) && (
|
|
20
|
+
Platform.OS === 'ios'
|
|
21
|
+
? (
|
|
22
|
+
<BlurView
|
|
23
|
+
blurType='light' blurAmount={15}
|
|
24
|
+
style={[styles.ImageOverlayPill, { width: showToCust && saveToDevice ? 50 : 24 }]}
|
|
25
|
+
pointerEvents='none'
|
|
26
|
+
>
|
|
27
|
+
{allowShowToCustomer && showToCust && (
|
|
28
|
+
<View style={[styles.OverlayIconCircle, styles.OverlayIconCircleEye]}>
|
|
29
|
+
<Icons.IconEye_WithPad size={16} fill={colors.white} fillOpacity={1} />
|
|
30
|
+
</View>
|
|
31
|
+
)}
|
|
32
|
+
{allowSaveToDevice && saveToDevice && (
|
|
33
|
+
<View style={[styles.OverlayIconCircle]}>
|
|
34
|
+
<Icons.IconDownloadDone2 size={16} fill={colors.white} fillOpacity={1} />
|
|
35
|
+
</View>
|
|
36
|
+
)}
|
|
37
|
+
</BlurView>)
|
|
38
|
+
: (
|
|
39
|
+
<View
|
|
40
|
+
style={[styles.ImageOverlayPill, {
|
|
41
|
+
width: showToCust && saveToDevice ? 50 : 24,
|
|
42
|
+
backgroundColor: 'rgba(0,0,0,0.35)'
|
|
43
|
+
}]} pointerEvents='none'
|
|
44
|
+
>
|
|
45
|
+
{allowShowToCustomer && showToCust && (
|
|
46
|
+
<View style={[styles.OverlayIconCircle, styles.OverlayIconCircleEye]}>
|
|
47
|
+
<Icons.IconEye_WithPad size={16} fill={colors.white} fillOpacity={1} />
|
|
48
|
+
</View>
|
|
49
|
+
)}
|
|
50
|
+
{allowSaveToDevice && saveToDevice && (
|
|
51
|
+
<View style={[styles.OverlayIconCircle]}>
|
|
52
|
+
<Icons.IconDownloadDone2 size={16} fill={colors.white} fillOpacity={1} />
|
|
53
|
+
</View>
|
|
54
|
+
)}
|
|
55
|
+
</View>
|
|
56
|
+
)
|
|
57
|
+
)
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const styles = StyleSheet.create({
|
|
62
|
+
ImageOverlayPill: {
|
|
63
|
+
position: 'absolute',
|
|
64
|
+
left: 4,
|
|
65
|
+
bottom: 4,
|
|
66
|
+
width: 50,
|
|
67
|
+
height: 24,
|
|
68
|
+
borderRadius: 12,
|
|
69
|
+
flexDirection: 'row',
|
|
70
|
+
alignItems: 'center',
|
|
71
|
+
justifyContent: 'space-between'
|
|
72
|
+
},
|
|
73
|
+
OverlayIconCircle: {
|
|
74
|
+
width: 24,
|
|
75
|
+
height: 24,
|
|
76
|
+
borderRadius: 12,
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
justifyContent: 'center'
|
|
79
|
+
},
|
|
80
|
+
OverlayIconCircleEye: {
|
|
81
|
+
backgroundColor: colors.emphasisMedium
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
export default ImageIndicators
|