@supportworks/multi-imagepicker 8.2.0 → 8.3.0
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 +210 -32
- package/changes.md +7 -0
- package/index.js +2 -0
- package/package.json +1 -1
- package/src/components/AddImages.js +119 -176
- package/src/components/AddImagesProvider.js +269 -0
- package/src/components/AddImagesView.js +173 -0
package/README.md
CHANGED
|
@@ -1,58 +1,232 @@
|
|
|
1
|
-
|
|
2
1
|
# @supportworks/Multi-ImagePicker
|
|
3
2
|
|
|
4
|
-
This library
|
|
3
|
+
This library wraps `react-native-image-crop-picker` for React Native apps and provides a shared image-picking flow with support for:
|
|
4
|
+
|
|
5
|
+
- selecting one or more images
|
|
6
|
+
- editing image titles/descriptions before attach
|
|
7
|
+
- per-image metadata such as `showToCust` and `saveToDevice`
|
|
8
|
+
- attaching images to a project, appointment, or other app-specific target
|
|
5
9
|
|
|
6
10
|
## Getting started
|
|
7
11
|
|
|
8
|
-
See
|
|
12
|
+
See `peerDependencies` in `package.json` and install the required libraries in the app.
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
Install with:
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
```bash
|
|
17
|
+
npm install @supportworks/Multi-ImagePicker
|
|
18
|
+
```
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
Version `3.x` has breaking changes for React Native `>= 0.60`.
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
iOS note: when building the app the first time, in Xcode under `Embedded Binaries`, add:
|
|
23
|
+
|
|
24
|
+
- `RSKImageCropper.framework`
|
|
25
|
+
- `QBImagePicker.framework`
|
|
26
|
+
|
|
27
|
+
## Current AddImages architecture
|
|
28
|
+
|
|
29
|
+
`AddImages` no longer presents itself with a native React Native `Modal`.
|
|
30
|
+
|
|
31
|
+
Instead:
|
|
32
|
+
|
|
33
|
+
- `AddImages` is the trigger/controller
|
|
34
|
+
- `AddImagesProvider` renders the full-screen overlay host
|
|
35
|
+
|
|
36
|
+
This avoids nested native modal presentation problems on iOS, especially when `AddImages` is launched from a sheet, bottom modal, or other modal-like container.
|
|
37
|
+
|
|
38
|
+
`AddImages` must be rendered inside an `AddImagesProvider`. If it is not, the component will throw:
|
|
39
|
+
|
|
40
|
+
```txt
|
|
41
|
+
AddImages must be used within an AddImagesProvider.
|
|
19
42
|
```
|
|
20
43
|
|
|
21
|
-
##
|
|
22
|
-
|
|
44
|
+
## Usage - imports
|
|
45
|
+
|
|
23
46
|
```javascript
|
|
47
|
+
import {
|
|
48
|
+
AddImages,
|
|
49
|
+
AddImagesProvider,
|
|
50
|
+
MultiImagePicker,
|
|
51
|
+
SelectedImages
|
|
52
|
+
} from '@supportworks/Multi-ImagePicker'
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Info.plist additions for iOS
|
|
56
|
+
|
|
57
|
+
Saving to Camera Roll currently applies to iOS only.
|
|
58
|
+
|
|
59
|
+
```xml
|
|
24
60
|
<key>NSPhotoLibraryAddUsageDescription</key>
|
|
25
61
|
<string>We allow you to save photos into your media library that were taken within the app.</string>
|
|
26
62
|
<key>NSPhotoLibraryUsageDescription</key>
|
|
27
63
|
<string>We access your media library to let you upload pictures you already took to your appointments.</string>
|
|
28
64
|
```
|
|
29
65
|
|
|
66
|
+
## Library Usage 1 - AddImages with AddImagesProvider
|
|
67
|
+
## How to use AddImagesProvider
|
|
68
|
+
|
|
69
|
+
Wrap `AddImagesProvider` around the highest React subtree that the image picker needs to cover.
|
|
70
|
+
|
|
71
|
+
That is the key rule.
|
|
30
72
|
|
|
31
|
-
|
|
32
|
-
|
|
73
|
+
Examples:
|
|
74
|
+
|
|
75
|
+
- normal screen: wrap the screen root
|
|
76
|
+
- tabbed screen: wrap the tab container, not just the tab body
|
|
77
|
+
- modal or sheet: wrap the modal or sheet content tree itself
|
|
78
|
+
- bottom modal inside another screen: wrap inside that bottom modal host, not only at app root
|
|
79
|
+
|
|
80
|
+
Do not assume a single provider in `App.js` is always enough. If `AddImages` is used inside a modal or sheet, an app-root provider can render behind that host instead of above it.
|
|
81
|
+
|
|
82
|
+
Multiple providers in different parts of the app are acceptable when `AddImages` is used in different host layers.
|
|
83
|
+
|
|
84
|
+
## How to choose the correct provider location
|
|
85
|
+
|
|
86
|
+
Start at the `AddImages` call site and walk up the render tree.
|
|
87
|
+
|
|
88
|
+
Place the provider around the component that owns the highest piece of UI that should be hidden behind the picker.
|
|
89
|
+
|
|
90
|
+
### Signs the provider is too low
|
|
91
|
+
|
|
92
|
+
- the picker is clipped to a smaller area
|
|
93
|
+
- headers or tabs are still visible above it
|
|
94
|
+
- part of the current screen remains tappable
|
|
95
|
+
|
|
96
|
+
### Signs the provider is too high or outside the wrong host
|
|
97
|
+
|
|
98
|
+
- the picker renders behind a modal or sheet
|
|
99
|
+
- touches go to the underlying modal instead of the picker
|
|
100
|
+
|
|
101
|
+
## Basic screen example
|
|
102
|
+
|
|
103
|
+
Use this pattern when `AddImages` is launched from a normal full-screen page.
|
|
33
104
|
|
|
34
|
-
1: AddImages - used to easily add a button/icon/link to your app that allows you to select multiple images, with custom titles and descriptions, per image. This option eliminatres the need to use the Multi-ImagePicker option below.
|
|
35
105
|
```javascript
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
106
|
+
import React from 'react'
|
|
107
|
+
import { View } from 'react-native'
|
|
108
|
+
import { AddImages, AddImagesProvider } from '@supportworks/Multi-ImagePicker'
|
|
39
109
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
110
|
+
const ProjectScreen = ({ Project, Api }) => {
|
|
111
|
+
const onImagesAdded = () => {
|
|
112
|
+
// refresh screen state after attach
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<AddImagesProvider>
|
|
117
|
+
<View style={{ flex: 1 }}>
|
|
118
|
+
<Header />
|
|
119
|
+
<Content />
|
|
120
|
+
|
|
121
|
+
<AddImages
|
|
122
|
+
parentStyle={styles.AddPhoto}
|
|
123
|
+
prospectInst={Project}
|
|
124
|
+
addPicture={Api.addOnePictureToProject}
|
|
125
|
+
callback={onImagesAdded}
|
|
126
|
+
>
|
|
127
|
+
<CameraButton />
|
|
128
|
+
</AddImages>
|
|
129
|
+
</View>
|
|
130
|
+
</AddImagesProvider>
|
|
131
|
+
)
|
|
53
132
|
}
|
|
54
133
|
```
|
|
55
|
-
|
|
134
|
+
|
|
135
|
+
## Modal or sheet example
|
|
136
|
+
|
|
137
|
+
Use this pattern when `AddImages` is launched from inside a bottom sheet or modal-like container.
|
|
138
|
+
|
|
139
|
+
If the underlying modal chrome is still visible at the top, set `sheetTopInset={0}`.
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
import React from 'react'
|
|
143
|
+
import { AddImagesProvider } from '@supportworks/Multi-ImagePicker'
|
|
144
|
+
import SwipeModal from '@supportworks/core-controls/src/SwipeModal'
|
|
145
|
+
|
|
146
|
+
const SheetAddImagesProvider = ({ children }) => (
|
|
147
|
+
<AddImagesProvider sheetTopInset={0}>
|
|
148
|
+
{children}
|
|
149
|
+
</AddImagesProvider>
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
const MyScreen = () => (
|
|
153
|
+
<SwipeModal
|
|
154
|
+
contentWrapper={SheetAddImagesProvider}
|
|
155
|
+
visible={showBottomModal}
|
|
156
|
+
close={closeBottomModal}
|
|
157
|
+
>
|
|
158
|
+
<BottomModalContent />
|
|
159
|
+
</SwipeModal>
|
|
160
|
+
)
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## AddImages props
|
|
164
|
+
|
|
165
|
+
`AddImages` is still the main trigger component. Common props include:
|
|
166
|
+
|
|
167
|
+
- `parentStyle`: style passed to `MultiImagePicker`
|
|
168
|
+
- `prospectInst`: project/appointment instance passed back to `addPicture`
|
|
169
|
+
- `addPicture`: async handler for saving one image
|
|
170
|
+
- `callback`: called after images are attached
|
|
171
|
+
- `hitSlop`: passed to the picker trigger
|
|
172
|
+
- `allowEdit`: whether filenames/descriptions can be edited
|
|
173
|
+
- `annotationAllowed`: whether annotations are allowed
|
|
174
|
+
- `showToCustomerAllowed`: whether "show to customer" is available
|
|
175
|
+
- `maxCount`: max images selectable
|
|
176
|
+
- `children`: the button/icon/link users tap to open the picker
|
|
177
|
+
|
|
178
|
+
## Troubleshooting
|
|
179
|
+
|
|
180
|
+
### The picker is not full screen
|
|
181
|
+
|
|
182
|
+
The provider is probably too low in the tree.
|
|
183
|
+
|
|
184
|
+
Move `AddImagesProvider` higher, around the component that owns the header/tabs/navigation you want covered.
|
|
185
|
+
|
|
186
|
+
### The picker appears behind a modal or sheet
|
|
187
|
+
|
|
188
|
+
The provider is probably outside the modal or sheet host.
|
|
189
|
+
|
|
190
|
+
Move the provider inside that modal or sheet content tree.
|
|
191
|
+
|
|
192
|
+
### The top of the old modal is still visible
|
|
193
|
+
|
|
194
|
+
Use:
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
<AddImagesProvider sheetTopInset={0}>
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
This is useful when the picker is hosted inside an existing modal or bottom-sheet style container and should fully cover that host.
|
|
201
|
+
|
|
202
|
+
## ChatGPT / implementation prompt
|
|
203
|
+
|
|
204
|
+
This section is intentionally written so it can be pasted into a ChatGPT or Codex prompt when integrating `AddImages` into an app.
|
|
205
|
+
|
|
206
|
+
```txt
|
|
207
|
+
The Multi-ImagePicker library uses AddImagesProvider and AddImages.
|
|
208
|
+
|
|
209
|
+
AddImages is only the trigger/controller. It does not use a native Modal to present itself.
|
|
210
|
+
AddImagesProvider is the overlay host that renders the full-screen picker UI.
|
|
211
|
+
|
|
212
|
+
When integrating AddImages:
|
|
213
|
+
1. Find every AddImages call site.
|
|
214
|
+
2. Trace the render tree upward from each call site.
|
|
215
|
+
3. Place AddImagesProvider around the highest React subtree that the picker needs to cover.
|
|
216
|
+
4. If AddImages is used inside a modal, bottom sheet, SwipeModal, react-native-modal, or other sheet host, place AddImagesProvider inside that host's content tree, not only at app root.
|
|
217
|
+
5. If the picker is clipped or headers/tabs still show above it, the provider is too low.
|
|
218
|
+
6. If the picker renders behind a modal or sheet, the provider is outside the correct host.
|
|
219
|
+
7. If the underlying modal chrome is still visible at the top, use AddImagesProvider with sheetTopInset={0}.
|
|
220
|
+
|
|
221
|
+
Use AddImages + AddImagesProvider as the default integration path. Only use MultiImagePicker or SelectedImages directly when custom flow control is required.
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Library Usage 2 - MultiImagePicker
|
|
225
|
+
`MultiImagePicker` allows you to select multiple images and return the results in arrays.
|
|
226
|
+
The child you include (AddButton in this example) should display an icon that will be touched to open the picker.
|
|
227
|
+
Note that your child component will be wrapped with a TouchableOpacity component, so any props you supply for
|
|
228
|
+
MultiImagePicker will be passed to that TouchableOpacity component.
|
|
229
|
+
|
|
56
230
|
```javascript
|
|
57
231
|
onImageSelect(payload) {
|
|
58
232
|
//handle return of selected images from MultiImagePicker
|
|
@@ -74,7 +248,11 @@ render() {
|
|
|
74
248
|
...
|
|
75
249
|
}
|
|
76
250
|
```
|
|
77
|
-
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
## Library Usage 3 - SelectedImages
|
|
254
|
+
`SelectedImages` allows you to display the images that were selected, before saving them, so you can edit their titles and descriptions.
|
|
255
|
+
|
|
78
256
|
```javascript
|
|
79
257
|
|
|
80
258
|
onItemChange (idx, patch) {
|
package/changes.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
# v8.3.0 2026-04-20
|
|
3
|
+
* added AddImagesProvider, required to wrap AddImages. Updated AddImages to use context from that provider.
|
|
4
|
+
* updated ReadMe with explanation and AI prompt to use to implement AddImages elsewhere in apps
|
|
5
|
+
|
|
6
|
+
# v8.2.1 2026-04-10
|
|
7
|
+
* temporary changes to test AddImages changes on device
|
|
8
|
+
|
|
2
9
|
# v8.2.0 2026-04-09
|
|
3
10
|
* reverted back to v8.0.16
|
|
4
11
|
* then changed UploadWarningModal to just be a regular component instead of a modal, to fix multiple nested modals issue on older iPads
|
package/index.js
CHANGED
|
@@ -6,11 +6,13 @@ import ImageIndicators from './src/components/ImageIndicators'
|
|
|
6
6
|
import ActionBar from './src/components/ActionBar'
|
|
7
7
|
import ImageDetailsModal from './src/components/ImageDetailsModal'
|
|
8
8
|
import CameraModal from './src/components/CameraModal'
|
|
9
|
+
import AddImagesProvider from './src/components/AddImagesProvider'
|
|
9
10
|
|
|
10
11
|
export {
|
|
11
12
|
MultiImagePicker,
|
|
12
13
|
SelectedImages,
|
|
13
14
|
AddImages,
|
|
15
|
+
AddImagesProvider,
|
|
14
16
|
MIPickerApi,
|
|
15
17
|
ImageIndicators,
|
|
16
18
|
ActionBar,
|
package/package.json
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useState, useRef, forwardRef, useImperativeHandle } from 'react'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
Modal,
|
|
5
|
-
StyleSheet, ScrollView, KeyboardAvoidingView, Platform, PermissionsAndroid, Alert
|
|
3
|
+
Platform, PermissionsAndroid, Alert
|
|
6
4
|
} from 'react-native'
|
|
7
5
|
import Moment from 'moment'
|
|
8
|
-
import { Icons } from '@supportworks/icon-library'
|
|
9
6
|
import loaderHandler from './loaderHandler'
|
|
10
7
|
import MultiImagePicker from './MultiImagePicker'
|
|
11
|
-
import SelectedImages from './SelectedImages'
|
|
12
|
-
import { colors } from '@supportworks/app-styler'
|
|
13
|
-
import { LoadingOverlay } from '@supportworks/navbars'
|
|
14
|
-
import { CheckBox, AppBarH8, CommonButton, ListItem, ScreenSafeAreaView } from '@supportworks/core-controls'
|
|
15
8
|
import { CameraRoll } from '@react-native-camera-roll/camera-roll'
|
|
16
9
|
import { Api } from '@supportworks/api-core'
|
|
17
10
|
import { Analytics } from '@supportworks/analytics'
|
|
18
11
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
19
|
-
import
|
|
12
|
+
import { useAddImagesProvider } from './AddImagesProvider'
|
|
20
13
|
|
|
21
14
|
const AddImages = forwardRef((
|
|
22
15
|
{
|
|
@@ -31,6 +24,7 @@ const AddImages = forwardRef((
|
|
|
31
24
|
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.
|
|
32
25
|
children
|
|
33
26
|
}, ref) => {
|
|
27
|
+
const updateAddImagesProvider = useAddImagesProvider()
|
|
34
28
|
const [showAttaching, setShowAttaching] = useState(false)
|
|
35
29
|
const [showAdd, setShowAdd] = useState(false)
|
|
36
30
|
const [showInfoDialog, setShowInfoDialog] = useState(false)
|
|
@@ -46,14 +40,30 @@ const AddImages = forwardRef((
|
|
|
46
40
|
const imgSourceRef = useRef(null) // temp value designating picker type used, if image was "taken" from device now, or image(s) chosen from "library"
|
|
47
41
|
const pickerRef = useRef(null)
|
|
48
42
|
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)
|
|
49
52
|
const STORAGE_KEY_SKIP_DIALOG = '@MIP_UploadWarningsModal_Skip'
|
|
50
53
|
const allowSaveToDevicePlatform = Platform.OS !== 'android' // TODO: set to true when Android support is added
|
|
51
54
|
|
|
52
55
|
useEffect(() => {
|
|
53
56
|
return () => {
|
|
57
|
+
if (hasPublishedEditorRef.current) {
|
|
58
|
+
updateAddImagesProvider({
|
|
59
|
+
visible: false,
|
|
60
|
+
attaching: false,
|
|
61
|
+
editorProps: null
|
|
62
|
+
})
|
|
63
|
+
}
|
|
54
64
|
isMountedRef.current = false
|
|
55
65
|
}
|
|
56
|
-
}, [])
|
|
66
|
+
}, [updateAddImagesProvider])
|
|
57
67
|
|
|
58
68
|
const setPickerRef = useCallback((node) => {
|
|
59
69
|
pickerRef.current = node
|
|
@@ -140,19 +150,25 @@ const AddImages = forwardRef((
|
|
|
140
150
|
return
|
|
141
151
|
}
|
|
142
152
|
|
|
143
|
-
setShowAttaching(false)
|
|
144
153
|
setShowAdd(false)
|
|
154
|
+
setShowAttaching(true)
|
|
145
155
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
callback
|
|
156
|
+
try {
|
|
157
|
+
await addPicturesToProject()
|
|
158
|
+
if (allowEdit && allowSaveToDevice) {
|
|
159
|
+
await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
|
|
160
|
+
}
|
|
161
|
+
if (allowEdit && showToCustomerAllowed) {
|
|
162
|
+
await Api.getApi().setDefaultShowToCustomer(showToCust)
|
|
163
|
+
}
|
|
164
|
+
Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
|
|
165
|
+
if (callback) {
|
|
166
|
+
callback()
|
|
167
|
+
}
|
|
168
|
+
} finally {
|
|
169
|
+
if (isMountedRef.current) {
|
|
170
|
+
setShowAttaching(false)
|
|
171
|
+
}
|
|
156
172
|
}
|
|
157
173
|
}, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
|
|
158
174
|
|
|
@@ -341,167 +357,94 @@ const AddImages = forwardRef((
|
|
|
341
357
|
}
|
|
342
358
|
}, [allowEdit, buildDefaultFilename, onAttach, showToCustomerAllowed])
|
|
343
359
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
360
|
+
useEffect(() => {
|
|
361
|
+
onCloseRef.current = onClose
|
|
362
|
+
onAttachRef.current = onAttach
|
|
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
|
|
347
413
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
height={55}
|
|
377
|
-
paddingLeft={20}
|
|
378
|
-
rightContentWidth={40}
|
|
379
|
-
paddingRight={16}
|
|
380
|
-
topSeparator={false}
|
|
381
|
-
/>
|
|
382
|
-
: null}
|
|
383
|
-
{allowSaveToDevice
|
|
384
|
-
? <ListItem
|
|
385
|
-
key='saveToDevice'
|
|
386
|
-
leftContent={
|
|
387
|
-
<View style={styles.IconCircle}>
|
|
388
|
-
<Icons.IconSave_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
389
|
-
</View>
|
|
390
|
-
}
|
|
391
|
-
mainAction={onPressCheckbox_SaveToDevice}
|
|
392
|
-
rightAction={onPressCheckbox_SaveToDevice}
|
|
393
|
-
title='Download all to device'
|
|
394
|
-
rightContent={<CheckBox
|
|
395
|
-
checked={allSave}
|
|
396
|
-
indeterminate={someSave}
|
|
397
|
-
onChange={onPressCheckbox_SaveToDevice}
|
|
398
|
-
/>}
|
|
399
|
-
height={56}
|
|
400
|
-
paddingLeft={20}
|
|
401
|
-
rightContentWidth={40}
|
|
402
|
-
paddingRight={16}
|
|
403
|
-
topSeparator={showToCustomerAllowed}
|
|
404
|
-
/>
|
|
405
|
-
: null}
|
|
406
|
-
</View>
|
|
407
|
-
)
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (showAttaching) {
|
|
411
|
-
return (
|
|
412
|
-
<LoadingOverlay />
|
|
413
|
-
)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (showAdd) {
|
|
417
|
-
return (
|
|
418
|
-
<Modal presentationStyle='fullScreen' animationType='slide'>
|
|
419
|
-
<ScreenSafeAreaView style={styles.Page} edges={['top','bottom']} includeProvider>
|
|
420
|
-
<AppBarH8
|
|
421
|
-
variant='regular'
|
|
422
|
-
title='Photos to Add'
|
|
423
|
-
subtitle={items.length + ' Photo' + (items.length > 1 ? 's' : '')}
|
|
424
|
-
leftContentType='closeButton'
|
|
425
|
-
callback={onClose}
|
|
426
|
-
bgColor={colors.backgroundMedium}
|
|
427
|
-
bottomShadow
|
|
428
|
-
/>
|
|
429
|
-
<SaveOptions />
|
|
430
|
-
<KeyboardAvoidingView behavior='padding' enabled style={styles.Content}>
|
|
431
|
-
<ScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='handled'>
|
|
432
|
-
<SelectedImages
|
|
433
|
-
items={items}
|
|
434
|
-
callback={handleSetAllImageDataValid}
|
|
435
|
-
annotationAllowed={annotationAllowed}
|
|
436
|
-
onDeleteItem={handleDeleteItem}
|
|
437
|
-
onItemChange={onItemChange}
|
|
438
|
-
allowSaveToDevice={allowSaveToDevice}
|
|
439
|
-
allowShowToCustomer={showToCustomerAllowed}
|
|
440
|
-
/>
|
|
441
|
-
</ScrollView>
|
|
442
|
-
</KeyboardAvoidingView>
|
|
443
|
-
<View style={styles.ButtonContainer}>
|
|
444
|
-
<CommonButton
|
|
445
|
-
variant='filled'
|
|
446
|
-
size='medium'
|
|
447
|
-
fullWidth
|
|
448
|
-
label='Attach'
|
|
449
|
-
endIcon={<Icons.IconUploadAll />}
|
|
450
|
-
onPress={onAttach}
|
|
451
|
-
disabled={!allImageDataValid}
|
|
452
|
-
/>
|
|
453
|
-
</View>
|
|
454
|
-
|
|
455
|
-
{Api.getApi().sendPhotosToCRM() && (
|
|
456
|
-
<UploadWarningModal
|
|
457
|
-
visible={showInfoDialog}
|
|
458
|
-
onClose={onCloseInfoDialog}
|
|
459
|
-
/>
|
|
460
|
-
)}
|
|
461
|
-
</ScreenSafeAreaView>
|
|
462
|
-
</Modal>
|
|
463
|
-
)
|
|
464
|
-
}
|
|
414
|
+
|
|
415
|
+
if (hasPublishedEditorRef.current) {
|
|
416
|
+
hasPublishedEditorRef.current = false
|
|
417
|
+
updateAddImagesProvider({
|
|
418
|
+
visible: false,
|
|
419
|
+
attaching: false,
|
|
420
|
+
editorProps: null
|
|
421
|
+
})
|
|
422
|
+
}
|
|
423
|
+
}, [
|
|
424
|
+
allowSaveToDevice,
|
|
425
|
+
allImageDataValid,
|
|
426
|
+
annotationAllowed,
|
|
427
|
+
externalOnAttach,
|
|
428
|
+
externalOnClose,
|
|
429
|
+
externalOnCloseInfoDialog,
|
|
430
|
+
externalOnDeleteItem,
|
|
431
|
+
externalOnItemChange,
|
|
432
|
+
externalOnPressCheckboxSaveToDevice,
|
|
433
|
+
externalOnPressCheckboxShowToCust,
|
|
434
|
+
externalOnValidate,
|
|
435
|
+
items,
|
|
436
|
+
showAdd,
|
|
437
|
+
showAttaching,
|
|
438
|
+
showInfoDialog,
|
|
439
|
+
showToCustomerAllowed,
|
|
440
|
+
updateAddImagesProvider
|
|
441
|
+
])
|
|
465
442
|
|
|
466
443
|
return (
|
|
467
|
-
<MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
|
|
444
|
+
!showAdd && !showAttaching && <MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
|
|
468
445
|
{children}
|
|
469
446
|
</MultiImagePicker>
|
|
470
447
|
)
|
|
471
448
|
})
|
|
472
449
|
|
|
473
|
-
const styles = StyleSheet.create({
|
|
474
|
-
Page: {
|
|
475
|
-
backgroundColor: colors.backgroundMedium,
|
|
476
|
-
flex: 1
|
|
477
|
-
},
|
|
478
|
-
Content: {
|
|
479
|
-
flex: 1
|
|
480
|
-
},
|
|
481
|
-
ScrollViewContainer: {
|
|
482
|
-
paddingBottom: 100,
|
|
483
|
-
marginTop: 8
|
|
484
|
-
},
|
|
485
|
-
SaveOptionsContainer: {
|
|
486
|
-
backgroundColor: colors.white,
|
|
487
|
-
margin: 16,
|
|
488
|
-
borderRadius: 16
|
|
489
|
-
},
|
|
490
|
-
IconCircle: {
|
|
491
|
-
width: 32,
|
|
492
|
-
height: 32,
|
|
493
|
-
borderRadius: 16,
|
|
494
|
-
backgroundColor: colors.buttonPrimaryLight,
|
|
495
|
-
justifyContent: 'center',
|
|
496
|
-
alignItems: 'center'
|
|
497
|
-
},
|
|
498
|
-
ButtonContainer: {
|
|
499
|
-
height: 56,
|
|
500
|
-
paddingHorizontal: 16,
|
|
501
|
-
paddingVertical: 8,
|
|
502
|
-
borderTopWidth: 1,
|
|
503
|
-
borderTopColor: colors.black05
|
|
504
|
-
}
|
|
505
|
-
})
|
|
506
|
-
|
|
507
450
|
export default AddImages
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import React, { createContext, useCallback, useContext, useState } from 'react'
|
|
2
|
+
import { View, StyleSheet, ScrollView, KeyboardAvoidingView, Pressable } from 'react-native'
|
|
3
|
+
import { Icons } from '@supportworks/icon-library'
|
|
4
|
+
import SelectedImages from './SelectedImages'
|
|
5
|
+
import { colors } from '@supportworks/app-styler'
|
|
6
|
+
import { LoadingOverlay } from '@supportworks/navbars'
|
|
7
|
+
import { CheckBox, AppBarH8, CommonButton, ListItem, ScreenSafeAreaView } from '@supportworks/core-controls'
|
|
8
|
+
import { Api } from '@supportworks/api-core'
|
|
9
|
+
import UploadWarningModal from './UploadWarningModal'
|
|
10
|
+
|
|
11
|
+
const AddImagesProviderContext = createContext(null)
|
|
12
|
+
|
|
13
|
+
export const useAddImagesProvider = () => {
|
|
14
|
+
const context = useContext(AddImagesProviderContext)
|
|
15
|
+
|
|
16
|
+
if (!context) {
|
|
17
|
+
throw new Error('AddImages must be used within an AddImagesProvider. See the ReadMe for examples, help and an AI prompt for your usage.')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return context
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const SaveOptions = ({
|
|
24
|
+
items = [],
|
|
25
|
+
showToCustomerAllowed = false,
|
|
26
|
+
allowSaveToDevice = false,
|
|
27
|
+
onPressCheckboxShowToCust = null,
|
|
28
|
+
onPressCheckboxSaveToDevice = null
|
|
29
|
+
}) => {
|
|
30
|
+
if (!showToCustomerAllowed && !allowSaveToDevice) {
|
|
31
|
+
return null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const total = items.length
|
|
35
|
+
const saveCount = items.filter(i => !!i.saveToDevice).length
|
|
36
|
+
const showCount = items.filter(i => !!i.showToCust).length
|
|
37
|
+
const allSave = total > 0 && saveCount === total
|
|
38
|
+
const someSave = total > 0 && saveCount > 0 && saveCount < total
|
|
39
|
+
const allShow = total > 0 && showCount === total
|
|
40
|
+
const someShow = total > 0 && showCount > 0 && showCount < total
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<View style={styles.SaveOptionsContainer}>
|
|
44
|
+
{showToCustomerAllowed
|
|
45
|
+
? <ListItem
|
|
46
|
+
key='showToCust'
|
|
47
|
+
leftContent={
|
|
48
|
+
<View style={styles.IconCircle}>
|
|
49
|
+
<Icons.IconEye_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
50
|
+
</View>
|
|
51
|
+
}
|
|
52
|
+
mainAction={onPressCheckboxShowToCust}
|
|
53
|
+
rightAction={onPressCheckboxShowToCust}
|
|
54
|
+
title='Show all to customer'
|
|
55
|
+
subtitle='Select to share all w/ customer.'
|
|
56
|
+
rightContent={<CheckBox
|
|
57
|
+
checked={allShow}
|
|
58
|
+
indeterminate={someShow}
|
|
59
|
+
onChange={onPressCheckboxShowToCust}
|
|
60
|
+
/>}
|
|
61
|
+
height={55}
|
|
62
|
+
paddingLeft={20}
|
|
63
|
+
rightContentWidth={40}
|
|
64
|
+
paddingRight={16}
|
|
65
|
+
topSeparator={false}
|
|
66
|
+
/>
|
|
67
|
+
: null}
|
|
68
|
+
{allowSaveToDevice
|
|
69
|
+
? <ListItem
|
|
70
|
+
key='saveToDevice'
|
|
71
|
+
leftContent={
|
|
72
|
+
<View style={styles.IconCircle}>
|
|
73
|
+
<Icons.IconSave_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
74
|
+
</View>
|
|
75
|
+
}
|
|
76
|
+
mainAction={onPressCheckboxSaveToDevice}
|
|
77
|
+
rightAction={onPressCheckboxSaveToDevice}
|
|
78
|
+
title='Download all to device'
|
|
79
|
+
rightContent={<CheckBox
|
|
80
|
+
checked={allSave}
|
|
81
|
+
indeterminate={someSave}
|
|
82
|
+
onChange={onPressCheckboxSaveToDevice}
|
|
83
|
+
/>}
|
|
84
|
+
height={56}
|
|
85
|
+
paddingLeft={20}
|
|
86
|
+
rightContentWidth={40}
|
|
87
|
+
paddingRight={16}
|
|
88
|
+
topSeparator={showToCustomerAllowed}
|
|
89
|
+
/>
|
|
90
|
+
: null}
|
|
91
|
+
</View>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const AddImagesEditor = ({ editorProps }) => {
|
|
96
|
+
if (!editorProps) {
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const {
|
|
101
|
+
items = [],
|
|
102
|
+
annotationAllowed = false,
|
|
103
|
+
showToCustomerAllowed = false,
|
|
104
|
+
allowSaveToDevice = false,
|
|
105
|
+
allImageDataValid = true,
|
|
106
|
+
showInfoDialog = false,
|
|
107
|
+
onClose = null,
|
|
108
|
+
onAttach = null,
|
|
109
|
+
onDeleteItem = null,
|
|
110
|
+
onItemChange = null,
|
|
111
|
+
onCloseInfoDialog = null,
|
|
112
|
+
onValidate = null,
|
|
113
|
+
onPressCheckboxShowToCust = null,
|
|
114
|
+
onPressCheckboxSaveToDevice = null
|
|
115
|
+
} = editorProps
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<ScreenSafeAreaView style={styles.Page} edges={['top', 'bottom']} includeProvider>
|
|
119
|
+
<Pressable style={styles.KnobWrapper} onPress={onClose}>
|
|
120
|
+
<View style={styles.Knob} />
|
|
121
|
+
</Pressable>
|
|
122
|
+
<AppBarH8
|
|
123
|
+
variant='regular'
|
|
124
|
+
title='Photos to Add'
|
|
125
|
+
subtitle={items.length + ' Photo' + (items.length > 1 ? 's' : '')}
|
|
126
|
+
leftContentType='closeButton'
|
|
127
|
+
callback={onClose}
|
|
128
|
+
bgColor={colors.backgroundMedium}
|
|
129
|
+
bottomShadow
|
|
130
|
+
/>
|
|
131
|
+
<SaveOptions
|
|
132
|
+
items={items}
|
|
133
|
+
showToCustomerAllowed={showToCustomerAllowed}
|
|
134
|
+
allowSaveToDevice={allowSaveToDevice}
|
|
135
|
+
onPressCheckboxShowToCust={onPressCheckboxShowToCust}
|
|
136
|
+
onPressCheckboxSaveToDevice={onPressCheckboxSaveToDevice}
|
|
137
|
+
/>
|
|
138
|
+
<KeyboardAvoidingView behavior='padding' enabled style={styles.Content}>
|
|
139
|
+
<ScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='handled'>
|
|
140
|
+
<SelectedImages
|
|
141
|
+
items={items}
|
|
142
|
+
callback={onValidate}
|
|
143
|
+
annotationAllowed={annotationAllowed}
|
|
144
|
+
onDeleteItem={onDeleteItem}
|
|
145
|
+
onItemChange={onItemChange}
|
|
146
|
+
allowSaveToDevice={allowSaveToDevice}
|
|
147
|
+
allowShowToCustomer={showToCustomerAllowed}
|
|
148
|
+
/>
|
|
149
|
+
</ScrollView>
|
|
150
|
+
</KeyboardAvoidingView>
|
|
151
|
+
<View style={styles.ButtonContainer}>
|
|
152
|
+
<CommonButton
|
|
153
|
+
variant='filled'
|
|
154
|
+
size='medium'
|
|
155
|
+
fullWidth
|
|
156
|
+
label='Attach'
|
|
157
|
+
endIcon={<Icons.IconUploadAll />}
|
|
158
|
+
onPress={onAttach}
|
|
159
|
+
disabled={!allImageDataValid}
|
|
160
|
+
/>
|
|
161
|
+
</View>
|
|
162
|
+
|
|
163
|
+
{Api.getApi().sendPhotosToCRM() && (
|
|
164
|
+
<UploadWarningModal
|
|
165
|
+
visible={showInfoDialog}
|
|
166
|
+
onClose={onCloseInfoDialog}
|
|
167
|
+
/>
|
|
168
|
+
)}
|
|
169
|
+
</ScreenSafeAreaView>
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const AddImagesProvider = ({ children, sheetTopInset = 32 }) => {
|
|
174
|
+
const [editorState, setEditorState] = useState({
|
|
175
|
+
visible: false,
|
|
176
|
+
attaching: false,
|
|
177
|
+
editorProps: null
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
const updateEditorState = useCallback((nextState) => {
|
|
181
|
+
setEditorState({
|
|
182
|
+
visible: !!nextState?.visible,
|
|
183
|
+
attaching: !!nextState?.attaching,
|
|
184
|
+
editorProps: nextState?.editorProps || null
|
|
185
|
+
})
|
|
186
|
+
}, [])
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<AddImagesProviderContext.Provider value={updateEditorState}>
|
|
190
|
+
<View style={styles.ProviderContainer}>
|
|
191
|
+
{children}
|
|
192
|
+
{editorState.visible && (
|
|
193
|
+
<View style={styles.Overlay}>
|
|
194
|
+
<Pressable style={styles.Backdrop} onPress={editorState.editorProps?.onClose} />
|
|
195
|
+
<View style={[styles.Sheet, { marginTop: sheetTopInset }]}>
|
|
196
|
+
<AddImagesEditor editorProps={editorState.editorProps} />
|
|
197
|
+
</View>
|
|
198
|
+
</View>
|
|
199
|
+
)}
|
|
200
|
+
{editorState.attaching && <LoadingOverlay />}
|
|
201
|
+
</View>
|
|
202
|
+
</AddImagesProviderContext.Provider>
|
|
203
|
+
)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const styles = StyleSheet.create({
|
|
207
|
+
ProviderContainer: {
|
|
208
|
+
flex: 1
|
|
209
|
+
},
|
|
210
|
+
Overlay: {
|
|
211
|
+
...StyleSheet.absoluteFillObject,
|
|
212
|
+
justifyContent: 'flex-end',
|
|
213
|
+
zIndex: 1000,
|
|
214
|
+
elevation: 1000
|
|
215
|
+
},
|
|
216
|
+
Backdrop: {
|
|
217
|
+
...StyleSheet.absoluteFillObject,
|
|
218
|
+
backgroundColor: 'rgba(0,0,0,0.45)'
|
|
219
|
+
},
|
|
220
|
+
Sheet: {
|
|
221
|
+
flex: 1,
|
|
222
|
+
borderTopLeftRadius: 16,
|
|
223
|
+
borderTopRightRadius: 16,
|
|
224
|
+
overflow: 'hidden'
|
|
225
|
+
},
|
|
226
|
+
Page: {
|
|
227
|
+
backgroundColor: colors.backgroundMedium,
|
|
228
|
+
flex: 1
|
|
229
|
+
},
|
|
230
|
+
KnobWrapper: {
|
|
231
|
+
alignItems: 'center',
|
|
232
|
+
paddingVertical: 9
|
|
233
|
+
},
|
|
234
|
+
Knob: {
|
|
235
|
+
backgroundColor: colors.black18,
|
|
236
|
+
borderRadius: 2,
|
|
237
|
+
height: 4,
|
|
238
|
+
width: 28
|
|
239
|
+
},
|
|
240
|
+
Content: {
|
|
241
|
+
flex: 1
|
|
242
|
+
},
|
|
243
|
+
ScrollViewContainer: {
|
|
244
|
+
paddingBottom: 100,
|
|
245
|
+
marginTop: 8
|
|
246
|
+
},
|
|
247
|
+
SaveOptionsContainer: {
|
|
248
|
+
backgroundColor: colors.white,
|
|
249
|
+
margin: 16,
|
|
250
|
+
borderRadius: 16
|
|
251
|
+
},
|
|
252
|
+
IconCircle: {
|
|
253
|
+
width: 32,
|
|
254
|
+
height: 32,
|
|
255
|
+
borderRadius: 16,
|
|
256
|
+
backgroundColor: colors.buttonPrimaryLight,
|
|
257
|
+
justifyContent: 'center',
|
|
258
|
+
alignItems: 'center'
|
|
259
|
+
},
|
|
260
|
+
ButtonContainer: {
|
|
261
|
+
height: 56,
|
|
262
|
+
paddingHorizontal: 16,
|
|
263
|
+
paddingVertical: 8,
|
|
264
|
+
borderTopWidth: 1,
|
|
265
|
+
borderTopColor: colors.black05
|
|
266
|
+
}
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
export default AddImagesProvider
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View, StyleSheet, ScrollView, KeyboardAvoidingView } from 'react-native'
|
|
3
|
+
import { Icons } from '@supportworks/icon-library'
|
|
4
|
+
import SelectedImages from './SelectedImages'
|
|
5
|
+
import { colors } from '@supportworks/app-styler'
|
|
6
|
+
import { CheckBox, AppBarH8, CommonButton, ListItem, ScreenSafeAreaView } from '@supportworks/core-controls'
|
|
7
|
+
import { Api } from '@supportworks/api-core'
|
|
8
|
+
import UploadWarningModal from './UploadWarningModal'
|
|
9
|
+
|
|
10
|
+
const AddImagesView = ({
|
|
11
|
+
items = [],
|
|
12
|
+
annotationAllowed = false,
|
|
13
|
+
showToCustomerAllowed = false,
|
|
14
|
+
allowSaveToDevice = false,
|
|
15
|
+
allImageDataValid = true,
|
|
16
|
+
showInfoDialog = false,
|
|
17
|
+
onClose = null,
|
|
18
|
+
onAttach = null,
|
|
19
|
+
onDeleteItem = null,
|
|
20
|
+
onItemChange = null,
|
|
21
|
+
onCloseInfoDialog = null,
|
|
22
|
+
onValidate = null,
|
|
23
|
+
onPressCheckboxShowToCust = null,
|
|
24
|
+
onPressCheckboxSaveToDevice = null
|
|
25
|
+
}) => {
|
|
26
|
+
const SaveOptions = () => {
|
|
27
|
+
if (!showToCustomerAllowed && !allowSaveToDevice) {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const total = items.length
|
|
32
|
+
const saveCount = items.filter(i => !!i.saveToDevice).length
|
|
33
|
+
const showCount = items.filter(i => !!i.showToCust).length
|
|
34
|
+
const allSave = total > 0 && saveCount === total
|
|
35
|
+
const someSave = total > 0 && saveCount > 0 && saveCount < total
|
|
36
|
+
const allShow = total > 0 && showCount === total
|
|
37
|
+
const someShow = total > 0 && showCount > 0 && showCount < total
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<View style={styles.SaveOptionsContainer}>
|
|
41
|
+
{showToCustomerAllowed
|
|
42
|
+
? <ListItem
|
|
43
|
+
key='showToCust'
|
|
44
|
+
leftContent={
|
|
45
|
+
<View style={styles.IconCircle}>
|
|
46
|
+
<Icons.IconEye_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
47
|
+
</View>
|
|
48
|
+
}
|
|
49
|
+
mainAction={onPressCheckboxShowToCust}
|
|
50
|
+
rightAction={onPressCheckboxShowToCust}
|
|
51
|
+
title='Show all to customer'
|
|
52
|
+
subtitle='Select to share all w/ customer.'
|
|
53
|
+
rightContent={<CheckBox
|
|
54
|
+
checked={allShow}
|
|
55
|
+
indeterminate={someShow}
|
|
56
|
+
onChange={onPressCheckboxShowToCust}
|
|
57
|
+
/>}
|
|
58
|
+
height={55}
|
|
59
|
+
paddingLeft={20}
|
|
60
|
+
rightContentWidth={40}
|
|
61
|
+
paddingRight={16}
|
|
62
|
+
topSeparator={false}
|
|
63
|
+
/>
|
|
64
|
+
: null}
|
|
65
|
+
{allowSaveToDevice
|
|
66
|
+
? <ListItem
|
|
67
|
+
key='saveToDevice'
|
|
68
|
+
leftContent={
|
|
69
|
+
<View style={styles.IconCircle}>
|
|
70
|
+
<Icons.IconSave_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
|
|
71
|
+
</View>
|
|
72
|
+
}
|
|
73
|
+
mainAction={onPressCheckboxSaveToDevice}
|
|
74
|
+
rightAction={onPressCheckboxSaveToDevice}
|
|
75
|
+
title='Download all to device'
|
|
76
|
+
rightContent={<CheckBox
|
|
77
|
+
checked={allSave}
|
|
78
|
+
indeterminate={someSave}
|
|
79
|
+
onChange={onPressCheckboxSaveToDevice}
|
|
80
|
+
/>}
|
|
81
|
+
height={56}
|
|
82
|
+
paddingLeft={20}
|
|
83
|
+
rightContentWidth={40}
|
|
84
|
+
paddingRight={16}
|
|
85
|
+
topSeparator={showToCustomerAllowed}
|
|
86
|
+
/>
|
|
87
|
+
: null}
|
|
88
|
+
</View>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<ScreenSafeAreaView style={styles.Page} edges={['top', 'bottom']} includeProvider>
|
|
94
|
+
<AppBarH8
|
|
95
|
+
variant='regular'
|
|
96
|
+
title='Photos to Add'
|
|
97
|
+
subtitle={items.length + ' Photo' + (items.length > 1 ? 's' : '')}
|
|
98
|
+
leftContentType='closeButton'
|
|
99
|
+
callback={onClose}
|
|
100
|
+
bgColor={colors.backgroundMedium}
|
|
101
|
+
bottomShadow
|
|
102
|
+
/>
|
|
103
|
+
<SaveOptions />
|
|
104
|
+
<KeyboardAvoidingView behavior='padding' enabled style={styles.Content}>
|
|
105
|
+
<ScrollView contentContainerStyle={styles.ScrollViewContainer} keyboardShouldPersistTaps='handled'>
|
|
106
|
+
<SelectedImages
|
|
107
|
+
items={items}
|
|
108
|
+
callback={onValidate}
|
|
109
|
+
annotationAllowed={annotationAllowed}
|
|
110
|
+
onDeleteItem={onDeleteItem}
|
|
111
|
+
onItemChange={onItemChange}
|
|
112
|
+
allowSaveToDevice={allowSaveToDevice}
|
|
113
|
+
allowShowToCustomer={showToCustomerAllowed}
|
|
114
|
+
/>
|
|
115
|
+
</ScrollView>
|
|
116
|
+
</KeyboardAvoidingView>
|
|
117
|
+
<View style={styles.ButtonContainer}>
|
|
118
|
+
<CommonButton
|
|
119
|
+
variant='filled'
|
|
120
|
+
size='medium'
|
|
121
|
+
fullWidth
|
|
122
|
+
label='Attach'
|
|
123
|
+
endIcon={<Icons.IconUploadAll />}
|
|
124
|
+
onPress={onAttach}
|
|
125
|
+
disabled={!allImageDataValid}
|
|
126
|
+
/>
|
|
127
|
+
</View>
|
|
128
|
+
|
|
129
|
+
{Api.getApi().sendPhotosToCRM() && (
|
|
130
|
+
<UploadWarningModal
|
|
131
|
+
visible={showInfoDialog}
|
|
132
|
+
onClose={onCloseInfoDialog}
|
|
133
|
+
/>
|
|
134
|
+
)}
|
|
135
|
+
</ScreenSafeAreaView>
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const styles = StyleSheet.create({
|
|
140
|
+
Page: {
|
|
141
|
+
backgroundColor: colors.backgroundMedium,
|
|
142
|
+
flex: 1
|
|
143
|
+
},
|
|
144
|
+
Content: {
|
|
145
|
+
flex: 1
|
|
146
|
+
},
|
|
147
|
+
ScrollViewContainer: {
|
|
148
|
+
paddingBottom: 100,
|
|
149
|
+
marginTop: 8
|
|
150
|
+
},
|
|
151
|
+
SaveOptionsContainer: {
|
|
152
|
+
backgroundColor: colors.white,
|
|
153
|
+
margin: 16,
|
|
154
|
+
borderRadius: 16
|
|
155
|
+
},
|
|
156
|
+
IconCircle: {
|
|
157
|
+
width: 32,
|
|
158
|
+
height: 32,
|
|
159
|
+
borderRadius: 16,
|
|
160
|
+
backgroundColor: colors.buttonPrimaryLight,
|
|
161
|
+
justifyContent: 'center',
|
|
162
|
+
alignItems: 'center'
|
|
163
|
+
},
|
|
164
|
+
ButtonContainer: {
|
|
165
|
+
height: 56,
|
|
166
|
+
paddingHorizontal: 16,
|
|
167
|
+
paddingVertical: 8,
|
|
168
|
+
borderTopWidth: 1,
|
|
169
|
+
borderTopColor: colors.black05
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
export default AddImagesView
|