@supportworks/multi-imagepicker 8.2.1 → 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 CHANGED
@@ -1,58 +1,232 @@
1
-
2
1
  # @supportworks/Multi-ImagePicker
3
2
 
4
- This library is used to implement react-native-image-crop-picker in iOS and Android apps built with react-native >= 0.60, which allows selection of multiple images at once.
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 'peerDependencies' list in package.json. Make sure to install all of those libraries, or add them to your app's package.json.
12
+ See `peerDependencies` in `package.json` and install the required libraries in the app.
9
13
 
10
- Run `npm install @supportworks/Multi-ImagePicker` or add it to your package.json
14
+ Install with:
11
15
 
12
- NOTE: version 3.0 has breaking changes, is only for react-native >= 0.60.0, so be sure to use 'react-native-image-crop-picker' version >=0.25.0 instead of the older '@supportworks/react-native-image-crop-picker'. No other changes besides this should be needed to the code.
16
+ ```bash
17
+ npm install @supportworks/Multi-ImagePicker
18
+ ```
13
19
 
14
- iOS: When building app the first time, in XCode, Under 'Embedded Binaries', add RSKImageCropper.framework and QBImagePicker.framework.
20
+ Version `3.x` has breaking changes for React Native `>= 0.60`.
15
21
 
16
- ## Usage - import
17
- ```javascript
18
- import {AddImages, MultiImagePicker} from '@supportworks/Multi-ImagePicker';
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
- ## Info.plist additions needed to add photos to Camera Roll for iOS
22
- ## (Saving to CameraRoll only works for iOS currently):
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
- ## Usage - JSX Component Examples
32
- There are 3 pieces to this library, of which one or more can be used.
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
- onImagesAdded() {
37
- //callback from MultiImagePicker, after images added
38
- let cRef = this;
106
+ import React from 'react'
107
+ import { View } from 'react-native'
108
+ import { AddImages, AddImagesProvider } from '@supportworks/Multi-ImagePicker'
39
109
 
40
- if (cRef.props.callback) {
41
- cRef.props.callback("photos added");
42
- }
43
- }
44
-
45
- render() {
46
- ...
47
- <AddImages parentStyle={styles.AddPhoto} prospectInst={Project} addPicture={Api.addOnePictureToProject} callback={cRef.onImagesAdded}>
48
- <View style={styles.AddPhotoIcon}>
49
- <Icons.IconCameraFill width="24" height="24" fill={colors.blue} fillOpacity="1" />
50
- </View>
51
- </AddImages>
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
- 2: Multi-Image Picker - this allows you to select multiple images and return the results in arrays. The child you include (AddButton in this example) should display an icon that will be touched to open the picker. Note that your child component will be wrapped with a TouchableOpacity component, so any props you supply for MultiImagePicker will be passed to that TouchableOpacity component.
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
- 3: Selected Image component - this allows you to display the images that were selected, before saving them, so you can edit their titles and descriptions.
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,6 +1,10 @@
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
+
2
6
  # v8.2.1 2026-04-10
3
- * temporary attempt to fix multiple nested modals issue on older iPads
7
+ * temporary changes to test AddImages changes on device
4
8
 
5
9
  # v8.2.0 2026-04-09
6
10
  * reverted back to v8.0.16
package/index.js CHANGED
@@ -6,13 +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 AddImagesView from './src/components/AddImagesView'
9
+ import AddImagesProvider from './src/components/AddImagesProvider'
10
10
 
11
11
  export {
12
12
  MultiImagePicker,
13
13
  SelectedImages,
14
14
  AddImages,
15
- AddImagesView,
15
+ AddImagesProvider,
16
16
  MIPickerApi,
17
17
  ImageIndicators,
18
18
  ActionBar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supportworks/multi-imagepicker",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "Android and iOS customized multiple image picker. For react-native >= 0.60.",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -1,17 +1,15 @@
1
1
  import React, { useCallback, useEffect, useState, useRef, forwardRef, useImperativeHandle } from 'react'
2
2
  import {
3
- View,
4
- StyleSheet, Platform, PermissionsAndroid, Alert
3
+ Platform, PermissionsAndroid, Alert
5
4
  } from 'react-native'
6
5
  import Moment from 'moment'
7
6
  import loaderHandler from './loaderHandler'
8
7
  import MultiImagePicker from './MultiImagePicker'
9
- import { LoadingOverlay } from '@supportworks/navbars'
10
8
  import { CameraRoll } from '@react-native-camera-roll/camera-roll'
11
9
  import { Api } from '@supportworks/api-core'
12
10
  import { Analytics } from '@supportworks/analytics'
13
11
  import AsyncStorage from '@react-native-async-storage/async-storage'
14
- import AddImagesView from './AddImagesView'
12
+ import { useAddImagesProvider } from './AddImagesProvider'
15
13
 
16
14
  const AddImages = forwardRef((
17
15
  {
@@ -23,11 +21,10 @@ const AddImages = forwardRef((
23
21
  allowEdit = true, // whether to allow user to edit file names and descriptions
24
22
  annotationAllowed = false, // whether to allow annotations on images
25
23
  showToCustomerAllowed = false, // whether to allow "show to customer" option
26
- renderInlineEditor = true, // backward-compatible inline editor rendering; disable to mount AddImagesView elsewhere
27
- onEditorStateChange = null, // optional callback for externally mounting AddImagesView in a caller-controlled full-screen container
28
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.
29
25
  children
30
26
  }, ref) => {
27
+ const updateAddImagesProvider = useAddImagesProvider()
31
28
  const [showAttaching, setShowAttaching] = useState(false)
32
29
  const [showAdd, setShowAdd] = useState(false)
33
30
  const [showInfoDialog, setShowInfoDialog] = useState(false)
@@ -43,6 +40,7 @@ const AddImages = forwardRef((
43
40
  const imgSourceRef = useRef(null) // temp value designating picker type used, if image was "taken" from device now, or image(s) chosen from "library"
44
41
  const pickerRef = useRef(null)
45
42
  const isMountedRef = useRef(true)
43
+ const hasPublishedEditorRef = useRef(false)
46
44
  const onCloseRef = useRef(null)
47
45
  const onAttachRef = useRef(null)
48
46
  const onDeleteItemRef = useRef(null)
@@ -56,9 +54,16 @@ const AddImages = forwardRef((
56
54
 
57
55
  useEffect(() => {
58
56
  return () => {
57
+ if (hasPublishedEditorRef.current) {
58
+ updateAddImagesProvider({
59
+ visible: false,
60
+ attaching: false,
61
+ editorProps: null
62
+ })
63
+ }
59
64
  isMountedRef.current = false
60
65
  }
61
- }, [])
66
+ }, [updateAddImagesProvider])
62
67
 
63
68
  const setPickerRef = useCallback((node) => {
64
69
  pickerRef.current = node
@@ -145,19 +150,25 @@ const AddImages = forwardRef((
145
150
  return
146
151
  }
147
152
 
148
- setShowAttaching(false)
149
153
  setShowAdd(false)
154
+ setShowAttaching(true)
150
155
 
151
- await addPicturesToProject()
152
- if (allowEdit && allowSaveToDevice) {
153
- await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
154
- }
155
- if (allowEdit && showToCustomerAllowed) {
156
- await Api.getApi().setDefaultShowToCustomer(showToCust)
157
- }
158
- Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
159
- if (callback) {
160
- 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
+ }
161
172
  }
162
173
  }, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
163
174
 
@@ -346,27 +357,6 @@ const AddImages = forwardRef((
346
357
  }
347
358
  }, [allowEdit, buildDefaultFilename, onAttach, showToCustomerAllowed])
348
359
 
349
- const addImagesEditor = (
350
- <View style={styles.Overlay}>
351
- <AddImagesView
352
- items={items}
353
- annotationAllowed={annotationAllowed}
354
- showToCustomerAllowed={showToCustomerAllowed}
355
- allowSaveToDevice={allowSaveToDevice}
356
- allImageDataValid={allImageDataValid}
357
- showInfoDialog={showInfoDialog}
358
- onClose={onClose}
359
- onAttach={onAttach}
360
- onDeleteItem={handleDeleteItem}
361
- onItemChange={onItemChange}
362
- onCloseInfoDialog={onCloseInfoDialog}
363
- onValidate={handleSetAllImageDataValid}
364
- onPressCheckboxShowToCust={onPressCheckbox_ShowToCust}
365
- onPressCheckboxSaveToDevice={onPressCheckbox_SaveToDevice}
366
- />
367
- </View>
368
- )
369
-
370
360
  useEffect(() => {
371
361
  onCloseRef.current = onClose
372
362
  onAttachRef.current = onAttach
@@ -397,30 +387,39 @@ const AddImages = forwardRef((
397
387
  const externalOnPressCheckboxSaveToDevice = useCallback((...args) => onPressCheckboxSaveToDeviceRef.current?.(...args), [])
398
388
 
399
389
  useEffect(() => {
400
- if (typeof onEditorStateChange !== 'function') {
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
+ })
401
412
  return
402
413
  }
403
414
 
404
- onEditorStateChange({
405
- visible: showAdd,
406
- attaching: showAttaching,
407
- editorProps: {
408
- items,
409
- annotationAllowed,
410
- showToCustomerAllowed,
411
- allowSaveToDevice,
412
- allImageDataValid,
413
- showInfoDialog,
414
- onClose: externalOnClose,
415
- onAttach: externalOnAttach,
416
- onDeleteItem: externalOnDeleteItem,
417
- onItemChange: externalOnItemChange,
418
- onCloseInfoDialog: externalOnCloseInfoDialog,
419
- onValidate: externalOnValidate,
420
- onPressCheckboxShowToCust: externalOnPressCheckboxShowToCust,
421
- onPressCheckboxSaveToDevice: externalOnPressCheckboxSaveToDevice
422
- }
423
- })
415
+ if (hasPublishedEditorRef.current) {
416
+ hasPublishedEditorRef.current = false
417
+ updateAddImagesProvider({
418
+ visible: false,
419
+ attaching: false,
420
+ editorProps: null
421
+ })
422
+ }
424
423
  }, [
425
424
  allowSaveToDevice,
426
425
  allImageDataValid,
@@ -434,30 +433,18 @@ const AddImages = forwardRef((
434
433
  externalOnPressCheckboxShowToCust,
435
434
  externalOnValidate,
436
435
  items,
437
- onEditorStateChange,
438
436
  showAdd,
439
437
  showAttaching,
440
438
  showInfoDialog,
441
- showToCustomerAllowed
439
+ showToCustomerAllowed,
440
+ updateAddImagesProvider
442
441
  ])
443
442
 
444
443
  return (
445
- <>
446
- {!showAdd && !showAttaching && <MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
447
- {children}
448
- </MultiImagePicker>}
449
- {renderInlineEditor && showAdd && addImagesEditor}
450
- {renderInlineEditor && showAttaching && <LoadingOverlay />}
451
- </>
444
+ !showAdd && !showAttaching && <MultiImagePicker ref={setPickerRef} hitSlop={hitSlop} maxCount={maxCount} parentStyle={parentStyle} callback={onImageSelect}>
445
+ {children}
446
+ </MultiImagePicker>
452
447
  )
453
448
  })
454
449
 
455
- const styles = StyleSheet.create({
456
- Overlay: {
457
- ...StyleSheet.absoluteFillObject,
458
- zIndex: 1000,
459
- elevation: 1000
460
- }
461
- })
462
-
463
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