@supportworks/multi-imagepicker 7.0.7 → 7.3.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 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.
72
+
73
+ Examples:
30
74
 
31
- ## Usage - JSX Component Examples
32
- There are 3 pieces to this library, of which one or more can be used.
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,23 +248,25 @@ 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
- setAllImageDataValid(allValid) {
80
- //handle return of selected images from MultiImagePicker <SelectedImages>
81
- //payload expected: (boolean) true if all selected images are valid, false otherwise
82
- let cRef = this;
83
- let initAllValid = cRef.state.allImageDataValid;
84
- if (allValid !== initAllValid) {
85
- //need to set state since overall validity flipped
86
- cRef.setState({allImageDataValid: allValid});
87
- }
257
+
258
+ onItemChange (idx, patch) {
259
+ this.setState((prevState) => {
260
+ const items = prevState.items.map((item, i) => (i === idx ? {...item, ...patch} : item))
261
+ const allValid = items.every(it => it?.isValid !== false)
262
+ return {items, allImageDataValid: allValid}
263
+ })
88
264
  }
89
-
265
+
90
266
  render() {
91
267
  ...
92
268
  <KeyboardAwareScrollView>
93
- <SelectedImages imgArr={cRef.imgArr} imgDescArr={cRef.imgDescArr} imgValidArr={cRef.imgValidArr} callback={cRef.setAllImageDataValid}/>
269
+ <SelectedImages items={cRef.state.items} onItemChange={cRef.onItemChange}/>
94
270
  </KeyboardAwareScrollView>
95
271
  ...
96
272
  }
package/changes.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ # NOTE: v7 is only for non-expo react-native apps since v8 has CameraModal which is for expo only
3
+
4
+ # v7.3.1 2026-04-21
5
+ * SYNCED UP WITH V8, EXCEPT CAMERAMODAL STUFF SINCE THAT IS FOR EXPO ONLY
6
+ * added AddImagesProvider, required to wrap AddImages. Updated AddImages to use context from that provider.
7
+ * updated ReadMe with explanation and AI prompt to use to implement AddImages elsewhere in apps
8
+ * changed UploadWarningModal to just be a regular component instead of a modal, to fix multiple nested modals issue on older iPads
9
+
2
10
  # v7.0.7 2026-01-22
3
11
  * replaced deprecated SafeAreaViews
4
12
 
package/index.js CHANGED
@@ -5,11 +5,13 @@ import MIPickerApi from './src/lib/MIPickerApi'
5
5
  import ImageIndicators from './src/components/ImageIndicators'
6
6
  import ActionBar from './src/components/ActionBar'
7
7
  import ImageDetailsModal from './src/components/ImageDetailsModal'
8
+ import AddImagesProvider from './src/components/AddImagesProvider'
8
9
 
9
10
  export {
10
11
  MultiImagePicker,
11
12
  SelectedImages,
12
13
  AddImages,
14
+ AddImagesProvider,
13
15
  MIPickerApi,
14
16
  ImageIndicators,
15
17
  ActionBar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supportworks/multi-imagepicker",
3
- "version": "7.0.7",
3
+ "version": "7.3.1",
4
4
  "description": "Android and iOS customized multiple image picker. For react-native >= 0.60.",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -1,22 +1,15 @@
1
1
  import React, { useCallback, useEffect, useState, useRef, forwardRef, useImperativeHandle } from 'react'
2
2
  import {
3
- View,
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 UploadWarningModal from './UploadWarningModal'
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
- await addPicturesToProject()
147
- if (allowEdit && allowSaveToDevice) {
148
- await Api.getApi().setDefaultSavePhotosToDevice(saveToDevice)
149
- }
150
- if (allowEdit && showToCustomerAllowed) {
151
- await Api.getApi().setDefaultShowToCustomer(showToCust)
152
- }
153
- Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
154
- if (callback) {
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
- const SaveOptions = () => {
345
- if (!showToCustomerAllowed && !allowSaveToDevice) {
346
- return null
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
- const total = items.length
349
- const saveCount = items.filter(i => !!i.saveToDevice).length
350
- const showCount = items.filter(i => !!i.showToCust).length
351
- const allSave = total > 0 && saveCount === total
352
- const someSave = total > 0 && saveCount > 0 && saveCount < total
353
- const allShow = total > 0 && showCount === total
354
- const someShow = total > 0 && showCount > 0 && showCount < total
355
- // console.log(`SaveOptions: total=${total}, saveCount=${saveCount}, showCount=${showCount}, allSave=${allSave}, someSave=${someSave}, allShow=${allShow}, someShow=${someShow}`)
356
-
357
- return (
358
- <View style={styles.SaveOptionsContainer}>
359
- {showToCustomerAllowed
360
- ? <ListItem
361
- key='showToCust'
362
- leftContent={
363
- <View style={styles.IconCircle}>
364
- <Icons.IconEye_WithPad fill={colors.buttonPrimary} fillOpacity={1} />
365
- </View>
366
- }
367
- mainAction={onPressCheckbox_ShowToCust}
368
- rightAction={onPressCheckbox_ShowToCust}
369
- title='Show all to customer'
370
- subtitle='Select to share all w/ customer.'
371
- rightContent={<CheckBox
372
- checked={allShow}
373
- indeterminate={someShow}
374
- onChange={onPressCheckbox_ShowToCust}
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
- </ScreenSafeAreaView>
455
-
456
- {Api.getApi().sendPhotosToCRM() && (
457
- <UploadWarningModal
458
- visible={showInfoDialog}
459
- onClose={onCloseInfoDialog}
460
- />
461
- )}
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
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useState } from 'react'
2
- import { Modal, View, StyleSheet, Text, Platform } from 'react-native'
2
+ import { View, StyleSheet, Text, Platform } from 'react-native'
3
3
  import { colors, stdStyles } from '@supportworks/app-styler'
4
4
  import { CheckBox, CommonButton } from '@supportworks/core-controls'
5
5
  import { Icons } from '@supportworks/icon-library'
@@ -15,53 +15,56 @@ const UploadWarningModal = (
15
15
  if (onClose) onClose(skipInfoDialog)
16
16
  }, [onClose, skipInfoDialog])
17
17
 
18
+ if (!visible) {
19
+ return null
20
+ }
21
+
18
22
  return (
19
- <Modal
20
- animationType='fade'
21
- transparent
22
- visible={visible}
23
- onRequestClose={handleClose}
24
- >
25
- <View style={styles.ModalView}>
26
- <View style={styles.InfoDialogContent}>
27
- <View style={styles.InfoDialogIconRow}>
28
- <Icons.IconPencilLock fill={colors.brandPrimary} fillOpacity={1} />
29
- </View>
30
- <View style={styles.InfoDialogTitleRow}>
31
- <Text style={styles.TitleText}>
32
- Captions can't be updated in CRM after upload
33
- </Text>
34
- </View>
35
- <Text style={stdStyles.Body2}>
36
- Photo captions can be edited now, but not after submitting to the CRM. Please review before uploading.
23
+ <View style={styles.ModalView}>
24
+ <View style={styles.Backdrop} />
25
+ <View style={styles.InfoDialogContent}>
26
+ <View style={styles.InfoDialogIconRow}>
27
+ <Icons.IconPencilLock fill={colors.brandPrimary} fillOpacity={1} />
28
+ </View>
29
+ <View style={styles.InfoDialogTitleRow}>
30
+ <Text style={styles.TitleText}>
31
+ Captions can't be updated in CRM after upload
37
32
  </Text>
38
- <View style={styles.InfoDialogCheckboxRow}>
39
- <CheckBox
40
- label="Don't show this message again"
41
- checked={!!skipInfoDialog}
42
- onChange={(newVal) => setSkipInfoDialog(newVal)}
43
- />
44
- </View>
45
- <View style={styles.InfoDialogButtonRow}>
46
- <CommonButton
47
- variant='filled'
48
- size='medium'
49
- label='Got it'
50
- fullWidth
51
- onPress={handleClose}
52
- />
53
- </View>
33
+ </View>
34
+ <Text style={stdStyles.Body2}>
35
+ Photo captions can be edited now, but not after submitting to the CRM. Please review before uploading.
36
+ </Text>
37
+ <View style={styles.InfoDialogCheckboxRow}>
38
+ <CheckBox
39
+ label="Don't show this message again"
40
+ checked={!!skipInfoDialog}
41
+ onChange={(newVal) => setSkipInfoDialog(newVal)}
42
+ />
43
+ </View>
44
+ <View style={styles.InfoDialogButtonRow}>
45
+ <CommonButton
46
+ variant='filled'
47
+ size='medium'
48
+ label='Got it'
49
+ fullWidth
50
+ onPress={handleClose}
51
+ />
54
52
  </View>
55
53
  </View>
56
- </Modal>
54
+ </View>
57
55
  )
58
56
  }
59
57
 
60
58
  const styles = StyleSheet.create({
61
59
  ModalView: {
62
- flex: 1,
60
+ ...StyleSheet.absoluteFillObject,
63
61
  justifyContent: 'center',
64
62
  alignItems: 'center',
63
+ zIndex: 10
64
+ },
65
+ Backdrop: {
66
+ ...StyleSheet.absoluteFillObject,
67
+ backgroundColor: colors.black36
65
68
  },
66
69
  InfoDialogContent: {
67
70
  backgroundColor: 'white',
@@ -68,19 +68,22 @@ export default class MIPickerApi {
68
68
  }
69
69
 
70
70
  async getDefaultShowToCustomer () {
71
- console.log('in getDefaultShowToCustomer')
72
- if ((this._defaultShowToCustomer !== null) && (this._defaultShowToCustomer !== undefined)) {
73
- return this._defaultShowToCustomer
74
- }
75
- console.log('in getDefaultShowToCustomer, trying to get value from AsyncStorage')
76
- // not a value yet, so look in AsyncStorage
77
- const retVal = await AsyncStorage.getItem('@MIP_ShowToCustomer')
78
- if (retVal === 'N') {
79
- console.log('getDefaultShowToCustomer: return false')
80
- return false
81
- } else {
82
- console.log('getDefaultShowToCustomer: return true')
83
- return true
84
- }
71
+ return true
72
+
73
+ /*
74
+ console.log('in getDefaultShowToCustomer')
75
+ if ((this._defaultShowToCustomer !== null) && (this._defaultShowToCustomer !== undefined)) {
76
+ return this._defaultShowToCustomer
77
+ }
78
+ console.log('in getDefaultShowToCustomer, trying to get value from AsyncStorage')
79
+ // not a value yet, so look in AsyncStorage
80
+ const retVal = await AsyncStorage.getItem('@MIP_ShowToCustomer')
81
+ if (retVal === 'N') {
82
+ console.log('getDefaultShowToCustomer: return false')
83
+ return false
84
+ } else {
85
+ console.log('getDefaultShowToCustomer: return true')
86
+ return true
87
+ }*/
85
88
  }
86
89
  }