@supportworks/multi-imagepicker 8.4.1 → 8.4.2
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 +8 -0
- package/changes.md +6 -0
- package/package.json +3 -2
- package/src/components/AddImages.js +13 -5
- package/src/components/AddImagesProvider.js +13 -18
- package/src/components/CameraModal.tsx +51 -14
- package/src/components/FramingGuideOverlay.tsx +111 -0
- package/src/components/MultiImagePicker.js +121 -188
- package/src/components/SelectedImages.js +20 -4
- package/src/components/SingleImage.js +37 -3
- package/src/components/photoOperation.js +14 -0
package/README.md
CHANGED
|
@@ -41,6 +41,14 @@ This avoids nested native modal presentation problems on iOS, especially when `A
|
|
|
41
41
|
AddImages must be used within an AddImagesProvider.
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
## Thumbnail previews
|
|
45
|
+
|
|
46
|
+
Attach and the camera Session Roll render small previews in virtualized lists. The full-size files remain available to the viewer, annotation, and save callbacks.
|
|
47
|
+
|
|
48
|
+
The API instance may provide `makeThumbnail(path)` and `deleteThumbnail(path)` for persistent thumbnail caching. Consumers without those optional methods use temporary previews, generated serially and removed when the preview unmounts. Existing `RNFS`, file-path, and annotation APIs are still required.
|
|
49
|
+
|
|
50
|
+
Version 8.4.2 requires `@supportworks/navbars >=3.0.0` for `LoadingOverlayHost` and the shared loading service. Keep `AddImagesProvider` mounted around the editor flow.
|
|
51
|
+
|
|
44
52
|
## Usage - imports
|
|
45
53
|
|
|
46
54
|
```javascript
|
package/changes.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# v8.4.2 2026-09-17
|
|
2
|
+
* DEV-9953: Use virtualized thumbnail previews in Attach and the camera Session Roll; clean up temporary previews.
|
|
3
|
+
* Serialize selection/processing/attachment across picker instances, await camera dismissal and save callbacks, and show processing/saving feedback.
|
|
4
|
+
* Refresh only edited photo previews; metadata changes no longer invalidate every image.
|
|
5
|
+
* Preserve the optional camera angle guide previously carried by the Ripple patch.
|
|
6
|
+
* Require navbars >=3.0.0 for the shared loading overlay. Use host thumbnail caching when available, with serial temporary thumbnails for other consumers.
|
|
1
7
|
|
|
2
8
|
# v8.4.1 2026-07-20
|
|
3
9
|
* DEV-9618: Fixed issue with image indicator not clipping background properly
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supportworks/multi-imagepicker",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.2",
|
|
4
4
|
"description": "Android and iOS customized multiple image picker. For react-native >= 0.60.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": {
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"@supportworks/camera": ">=0.2.3",
|
|
21
21
|
"@supportworks/core-controls": ">=5.0.0",
|
|
22
22
|
"@supportworks/icon-library": ">=1.4.3",
|
|
23
|
-
"@supportworks/navbars": ">=0.
|
|
23
|
+
"@supportworks/navbars": ">=3.0.0",
|
|
24
|
+
"expo-sensors": "*",
|
|
24
25
|
"@supportworks/swmaterialdesign": ">=1.1.3",
|
|
25
26
|
"react-native-image-crop-picker": ">=0.25.0",
|
|
26
27
|
"react-native-responsive-layout": "git@github.com:InspiredAgency/react-native-responsive-layout.git",
|
|
@@ -10,6 +10,7 @@ import { Api } from '@supportworks/api-core'
|
|
|
10
10
|
import { Analytics } from '@supportworks/analytics'
|
|
11
11
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
|
12
12
|
import { useAddImagesProvider } from './AddImagesProvider'
|
|
13
|
+
import { beginPhotoOperation, endPhotoOperation } from './photoOperation'
|
|
13
14
|
|
|
14
15
|
const AddImages = forwardRef((
|
|
15
16
|
{
|
|
@@ -41,6 +42,7 @@ const AddImages = forwardRef((
|
|
|
41
42
|
const imgSourceRef = useRef(null) // temp value designating picker type used, if image was "taken" from device now, or image(s) chosen from "library"
|
|
42
43
|
const pickerRef = useRef(null)
|
|
43
44
|
const isMountedRef = useRef(true)
|
|
45
|
+
const isAttachingRef = useRef(false)
|
|
44
46
|
const hasPublishedEditorRef = useRef(false)
|
|
45
47
|
const onCloseRef = useRef(null)
|
|
46
48
|
const onAttachRef = useRef(null)
|
|
@@ -146,10 +148,14 @@ const AddImages = forwardRef((
|
|
|
146
148
|
}
|
|
147
149
|
}, [addPicture, prospectInst, hasAndroidWritePermission, showToCust, saveToDevice, allowSaveToDevice])
|
|
148
150
|
|
|
149
|
-
const onAttach = useCallback(async () => {
|
|
150
|
-
if (!isMountedRef.current) {
|
|
151
|
+
const onAttach = useCallback(async (fromPicker = false) => {
|
|
152
|
+
if (!isMountedRef.current || isAttachingRef.current) {
|
|
151
153
|
return
|
|
152
154
|
}
|
|
155
|
+
// When editing is skipped, MultiImagePicker already owns the operation until this resolves.
|
|
156
|
+
const operation = fromPicker === true ? null : beginPhotoOperation()
|
|
157
|
+
if (fromPicker !== true && !operation) return
|
|
158
|
+
isAttachingRef.current = true
|
|
153
159
|
|
|
154
160
|
setShowAdd(false)
|
|
155
161
|
setShowAttaching(true)
|
|
@@ -164,9 +170,11 @@ const AddImages = forwardRef((
|
|
|
164
170
|
}
|
|
165
171
|
Analytics.logEvent('mip_addImages_onAttach', { source_page: 'MultiImagePicker' })
|
|
166
172
|
if (callback) {
|
|
167
|
-
callback()
|
|
173
|
+
await callback()
|
|
168
174
|
}
|
|
169
175
|
} finally {
|
|
176
|
+
isAttachingRef.current = false
|
|
177
|
+
if (operation) endPhotoOperation(operation)
|
|
170
178
|
if (isMountedRef.current) {
|
|
171
179
|
setShowAttaching(false)
|
|
172
180
|
}
|
|
@@ -174,7 +182,7 @@ const AddImages = forwardRef((
|
|
|
174
182
|
}, [addPicturesToProject, allowEdit, callback, saveToDevice, allowSaveToDevice, showToCust, showToCustomerAllowed])
|
|
175
183
|
|
|
176
184
|
const onClose = useCallback(() => {
|
|
177
|
-
if (!isMountedRef.current) {
|
|
185
|
+
if (!isMountedRef.current || isAttachingRef.current) {
|
|
178
186
|
return
|
|
179
187
|
}
|
|
180
188
|
setShowAttaching(false)
|
|
@@ -354,7 +362,7 @@ const AddImages = forwardRef((
|
|
|
354
362
|
if (isMountedRef.current) {
|
|
355
363
|
setItems([...itemsRef.current])
|
|
356
364
|
}
|
|
357
|
-
await onAttach()
|
|
365
|
+
await onAttach(true)
|
|
358
366
|
}
|
|
359
367
|
}, [allowEdit, buildDefaultFilename, onAttach, showToCustomerAllowed])
|
|
360
368
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { createContext, useCallback, useContext, useState } from 'react'
|
|
2
|
-
import { View, StyleSheet,
|
|
2
|
+
import { View, StyleSheet, KeyboardAvoidingView, Pressable } from 'react-native'
|
|
3
3
|
import { Icons } from '@supportworks/icon-library'
|
|
4
4
|
import SelectedImages from './SelectedImages'
|
|
5
5
|
import { colors } from '@supportworks/app-styler'
|
|
6
|
-
import { LoadingOverlay } from '@supportworks/navbars'
|
|
6
|
+
import { LoadingOverlay, LoadingOverlayHost } from '@supportworks/navbars'
|
|
7
7
|
import { CheckBox, AppBarH8, CommonButton, ListItem, ScreenSafeAreaView } from '@supportworks/core-controls'
|
|
8
8
|
import { Api } from '@supportworks/api-core'
|
|
9
9
|
import UploadWarningModal from './UploadWarningModal'
|
|
@@ -136,17 +136,15 @@ const AddImagesEditor = ({ editorProps }) => {
|
|
|
136
136
|
onPressCheckboxSaveToDevice={onPressCheckboxSaveToDevice}
|
|
137
137
|
/>
|
|
138
138
|
<KeyboardAvoidingView behavior='padding' enabled style={styles.Content}>
|
|
139
|
-
<
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
/>
|
|
149
|
-
</ScrollView>
|
|
139
|
+
<SelectedImages
|
|
140
|
+
items={items}
|
|
141
|
+
callback={onValidate}
|
|
142
|
+
annotationAllowed={annotationAllowed}
|
|
143
|
+
onDeleteItem={onDeleteItem}
|
|
144
|
+
onItemChange={onItemChange}
|
|
145
|
+
allowSaveToDevice={allowSaveToDevice}
|
|
146
|
+
allowShowToCustomer={showToCustomerAllowed}
|
|
147
|
+
/>
|
|
150
148
|
</KeyboardAvoidingView>
|
|
151
149
|
<View style={styles.ButtonContainer}>
|
|
152
150
|
<CommonButton
|
|
@@ -197,7 +195,8 @@ const AddImagesProvider = ({ children, sheetTopInset = 0 }) => {
|
|
|
197
195
|
</View>
|
|
198
196
|
</View>
|
|
199
197
|
)}
|
|
200
|
-
{editorState.attaching && <LoadingOverlay />}
|
|
198
|
+
{editorState.attaching && <LoadingOverlay message='Saving Photos...' />}
|
|
199
|
+
<LoadingOverlayHost />
|
|
201
200
|
</View>
|
|
202
201
|
</AddImagesProviderContext.Provider>
|
|
203
202
|
)
|
|
@@ -248,10 +247,6 @@ const styles = StyleSheet.create({
|
|
|
248
247
|
Content: {
|
|
249
248
|
flex: 1
|
|
250
249
|
},
|
|
251
|
-
ScrollViewContainer: {
|
|
252
|
-
paddingBottom: 100,
|
|
253
|
-
marginTop: 8
|
|
254
|
-
},
|
|
255
250
|
SaveOptionsContainer: {
|
|
256
251
|
backgroundColor: colors.white,
|
|
257
252
|
margin: 16,
|
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
ZoomLevel
|
|
16
16
|
} from '@supportworks/camera'
|
|
17
17
|
import React, { useRef, useState } from 'react'
|
|
18
|
+
import ImageResizer from '@bam.tech/react-native-image-resizer'
|
|
19
|
+
import { Api } from '@supportworks/api-core'
|
|
20
|
+
import FramingGuideOverlay from './FramingGuideOverlay'
|
|
18
21
|
import {
|
|
19
22
|
AppState,
|
|
20
23
|
ActivityIndicator,
|
|
@@ -25,7 +28,7 @@ import {
|
|
|
25
28
|
Pressable,
|
|
26
29
|
Alert,
|
|
27
30
|
Image,
|
|
28
|
-
|
|
31
|
+
FlatList,
|
|
29
32
|
Animated,
|
|
30
33
|
PanResponder,
|
|
31
34
|
Platform,
|
|
@@ -44,12 +47,44 @@ interface CapturedImage {
|
|
|
44
47
|
timestamp: string
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
const CameraThumbnail = ({ uri, style }: { uri: string; style: any }) => {
|
|
51
|
+
const [thumbnailUri, setThumbnailUri] = useState<string | null>(null)
|
|
52
|
+
|
|
53
|
+
React.useEffect(() => {
|
|
54
|
+
let cancelled = false
|
|
55
|
+
let thumbnailPath: string | undefined
|
|
56
|
+
const removeThumbnail = () => {
|
|
57
|
+
if (thumbnailPath) Api.getApi().RNFS.unlink(thumbnailPath).catch(() => {})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setThumbnailUri(null)
|
|
61
|
+
ImageResizer.createResizedImage(uri, 200, 200, 'JPEG', 80)
|
|
62
|
+
.then(image => {
|
|
63
|
+
thumbnailPath = image.path
|
|
64
|
+
if (cancelled) removeThumbnail()
|
|
65
|
+
else setThumbnailUri(image.uri)
|
|
66
|
+
})
|
|
67
|
+
.catch(() => {})
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
cancelled = true
|
|
71
|
+
removeThumbnail()
|
|
72
|
+
}
|
|
73
|
+
}, [uri])
|
|
74
|
+
|
|
75
|
+
return thumbnailUri
|
|
76
|
+
? <Image source={{ uri: thumbnailUri }} style={style} resizeMode="cover" />
|
|
77
|
+
: <View style={style} />
|
|
78
|
+
}
|
|
79
|
+
|
|
47
80
|
interface CameraTestModalProps {
|
|
48
81
|
onDone: (images: { imageURI: string; depthMapURI?: string }[]) => void
|
|
49
82
|
onCancel: () => void
|
|
50
83
|
cameraRef?: React.RefObject<CameraViewRef | null>
|
|
51
84
|
/** If set to 1, only allows a single photo. New photos will replace the existing one. */
|
|
52
85
|
limit?: number
|
|
86
|
+
/** Shows a live tilt indicator nudging the user away from steep, floor-only close-ups. */
|
|
87
|
+
angleGuideEnabled?: boolean
|
|
53
88
|
}
|
|
54
89
|
|
|
55
90
|
// Event types are now imported from the camera module
|
|
@@ -195,7 +230,7 @@ const FlipCameraIcon: React.FC<{ size?: number; color?: string }> = ({ size = 28
|
|
|
195
230
|
</Svg>
|
|
196
231
|
)
|
|
197
232
|
|
|
198
|
-
const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraRef: externalCameraRef, limit }) => {
|
|
233
|
+
const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraRef: externalCameraRef, limit, angleGuideEnabled }) => {
|
|
199
234
|
const internalCameraRef = useRef<CameraViewRef>(null)
|
|
200
235
|
const cameraRef = externalCameraRef || internalCameraRef
|
|
201
236
|
const insets = useSafeAreaInsets()
|
|
@@ -790,6 +825,7 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
790
825
|
/>
|
|
791
826
|
) : null}
|
|
792
827
|
</Pressable>
|
|
828
|
+
<FramingGuideOverlay enabled={!!angleGuideEnabled} topOffset={insets.top + 52} />
|
|
793
829
|
</View>
|
|
794
830
|
|
|
795
831
|
<View
|
|
@@ -840,7 +876,7 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
840
876
|
activeOpacity={0.9}
|
|
841
877
|
>
|
|
842
878
|
{latestCapturedImage ? (
|
|
843
|
-
<
|
|
879
|
+
<CameraThumbnail uri={latestCapturedImage.uri} style={[styles.galleryPreviewImage, { borderRadius: Math.max(6, galleryPreviewBorderRadius - 2) }]} />
|
|
844
880
|
) : (
|
|
845
881
|
<View style={[styles.galleryPreviewPlaceholder, { borderRadius: Math.max(6, galleryPreviewBorderRadius - 2) }]} />
|
|
846
882
|
)}
|
|
@@ -967,28 +1003,29 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
967
1003
|
|
|
968
1004
|
<View style={styles.galleryDivider} />
|
|
969
1005
|
|
|
970
|
-
<
|
|
1006
|
+
{isGalleryModalVisible && <FlatList
|
|
971
1007
|
horizontal
|
|
972
1008
|
showsHorizontalScrollIndicator={false}
|
|
973
1009
|
contentContainerStyle={styles.galleryScrollContainer}
|
|
974
1010
|
decelerationRate="fast"
|
|
975
|
-
|
|
976
|
-
{
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1011
|
+
data={capturedImages.slice().reverse()}
|
|
1012
|
+
keyExtractor={image => image.uri}
|
|
1013
|
+
initialNumToRender={6}
|
|
1014
|
+
maxToRenderPerBatch={4}
|
|
1015
|
+
windowSize={3}
|
|
1016
|
+
renderItem={({ item: image }) => (
|
|
1017
|
+
<View style={styles.galleryImageItem}>
|
|
1018
|
+
<CameraThumbnail uri={image.uri} style={styles.galleryModalImage} />
|
|
982
1019
|
<TouchableOpacity
|
|
983
1020
|
style={styles.removeButton}
|
|
984
|
-
onPress={() => removeImage(capturedImages.
|
|
1021
|
+
onPress={() => removeImage(capturedImages.findIndex(item => item.uri === image.uri))}
|
|
985
1022
|
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
|
|
986
1023
|
>
|
|
987
1024
|
<Icons.IconClose_WithPad size={16} fill={colors.black} fillOpacity={0.72} />
|
|
988
1025
|
</TouchableOpacity>
|
|
989
1026
|
</View>
|
|
990
|
-
)
|
|
991
|
-
|
|
1027
|
+
)}
|
|
1028
|
+
/>}
|
|
992
1029
|
</View>
|
|
993
1030
|
</SwipeModal>
|
|
994
1031
|
</View>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native'
|
|
3
|
+
import { DeviceMotion } from 'expo-sensors'
|
|
4
|
+
|
|
5
|
+
// Target zones for camera pitch (0deg = held upright/eye-level, 90deg = pointed straight down at the floor).
|
|
6
|
+
// Steep downward angles crop the shot to a floor close-up; the visualizer wants a broad view of the
|
|
7
|
+
// wall/corner/room, so we nudge users back toward eye-level rather than enforcing an exact angle.
|
|
8
|
+
const GOOD_MAX_DEG = 35
|
|
9
|
+
const WARN_MAX_DEG = 60
|
|
10
|
+
|
|
11
|
+
type Zone = 'good' | 'warn' | 'bad'
|
|
12
|
+
|
|
13
|
+
const zoneForTilt = (deg: number): Zone => {
|
|
14
|
+
if (deg <= GOOD_MAX_DEG) return 'good'
|
|
15
|
+
if (deg <= WARN_MAX_DEG) return 'warn'
|
|
16
|
+
return 'bad'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const ZONE_COPY: Record<Zone, string> = {
|
|
20
|
+
good: 'Good — full area in frame',
|
|
21
|
+
warn: 'Tilt up to capture more of the area',
|
|
22
|
+
bad: 'Too close — tilt up for the full wall or corner'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const ZONE_COLOR: Record<Zone, string> = {
|
|
26
|
+
good: '#34C759',
|
|
27
|
+
warn: '#FFCC00',
|
|
28
|
+
bad: '#FF3B30'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const UPDATE_INTERVAL_MS = 150
|
|
32
|
+
|
|
33
|
+
interface FramingGuideOverlayProps {
|
|
34
|
+
enabled: boolean
|
|
35
|
+
topOffset: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const FramingGuideOverlay: React.FC<FramingGuideOverlayProps> = ({ enabled, topOffset }) => {
|
|
39
|
+
const [tiltDeg, setTiltDeg] = React.useState<number | null>(null)
|
|
40
|
+
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
if (!enabled) {
|
|
43
|
+
setTiltDeg(null)
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
let isMounted = true
|
|
48
|
+
DeviceMotion.setUpdateInterval(UPDATE_INTERVAL_MS)
|
|
49
|
+
const subscription = DeviceMotion.addListener((data) => {
|
|
50
|
+
const beta = data?.rotation?.beta
|
|
51
|
+
if (typeof beta !== 'number' || !isMounted) {
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
const degrees = Math.min(90, Math.abs(beta) * (180 / Math.PI))
|
|
55
|
+
setTiltDeg(degrees)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
return () => {
|
|
59
|
+
isMounted = false
|
|
60
|
+
subscription.remove()
|
|
61
|
+
}
|
|
62
|
+
}, [enabled])
|
|
63
|
+
|
|
64
|
+
if (!enabled || tiltDeg === null) {
|
|
65
|
+
return null
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const zone = zoneForTilt(tiltDeg)
|
|
69
|
+
const color = ZONE_COLOR[zone]
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<View pointerEvents='none' style={[styles.container, { top: topOffset }]}>
|
|
73
|
+
<View style={[styles.pill, { borderColor: color }]}>
|
|
74
|
+
<View style={[styles.dot, { backgroundColor: color }]} />
|
|
75
|
+
<Text style={styles.text}>{ZONE_COPY[zone]}</Text>
|
|
76
|
+
</View>
|
|
77
|
+
</View>
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const styles = StyleSheet.create({
|
|
82
|
+
container: {
|
|
83
|
+
position: 'absolute',
|
|
84
|
+
left: 0,
|
|
85
|
+
right: 0,
|
|
86
|
+
alignItems: 'center',
|
|
87
|
+
zIndex: 8
|
|
88
|
+
},
|
|
89
|
+
pill: {
|
|
90
|
+
flexDirection: 'row',
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
paddingHorizontal: 14,
|
|
93
|
+
paddingVertical: 8,
|
|
94
|
+
borderRadius: 20,
|
|
95
|
+
borderWidth: 1.5,
|
|
96
|
+
backgroundColor: 'rgba(6, 7, 8, 0.55)'
|
|
97
|
+
},
|
|
98
|
+
dot: {
|
|
99
|
+
width: 8,
|
|
100
|
+
height: 8,
|
|
101
|
+
borderRadius: 4,
|
|
102
|
+
marginRight: 8
|
|
103
|
+
},
|
|
104
|
+
text: {
|
|
105
|
+
color: '#FFFFFF',
|
|
106
|
+
fontSize: 13,
|
|
107
|
+
fontWeight: '600'
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
export default FramingGuideOverlay
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useMemo, useRef, forwardRef, useImperativeHandle, useState } from 'react'
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useRef, forwardRef, useImperativeHandle, useState } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
AppState,
|
|
4
4
|
View,
|
|
@@ -14,7 +14,8 @@ import ImageResizer from '@bam.tech/react-native-image-resizer'
|
|
|
14
14
|
import { Api } from '@supportworks/api-core'
|
|
15
15
|
import { check, request, PERMISSIONS, RESULTS, openSettings } from 'react-native-permissions'
|
|
16
16
|
import CameraModal from './CameraModal'
|
|
17
|
-
import
|
|
17
|
+
import { showLoadingOverlay, hideLoadingOverlay } from '@supportworks/navbars'
|
|
18
|
+
import { beginPhotoOperation, endPhotoOperation, isPhotoOperationActive } from './photoOperation'
|
|
18
19
|
|
|
19
20
|
const waitForAppToBeActive = async () => {
|
|
20
21
|
if (AppState.currentState === 'active') {
|
|
@@ -43,21 +44,32 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
43
44
|
existingCount = 0, // number of images already attached outside of this picker session
|
|
44
45
|
callbackData = null, // data appended to payload and passed with callback function (optional)
|
|
45
46
|
callback = null, // callback function (optional)
|
|
47
|
+
angleGuideEnabled = false, // shows a live tilt indicator in CameraModal nudging away from steep floor-only close-ups (optional)
|
|
46
48
|
children,
|
|
47
49
|
...touchableProps // any other props passed into MultiImagePicker will be spread onto the TouchableOpacity below
|
|
48
50
|
} = props
|
|
49
51
|
|
|
50
52
|
const [showCameraModal, setShowCameraModal] = useState(false)
|
|
51
53
|
const [isCameraModalMounted, setIsCameraModalMounted] = useState(false)
|
|
52
|
-
const [
|
|
53
|
-
const [pendingCancelIndex, setPendingCancelIndex] = useState(null)
|
|
54
|
+
const [isBusy, setIsBusy] = useState(false)
|
|
54
55
|
const [actionSheetInstanceKey, setActionSheetInstanceKey] = useState(0)
|
|
55
56
|
|
|
56
57
|
const imgArrRef = useRef([]) // temp array for holding selected images to attach, before title & desc updated
|
|
57
58
|
const imgDescArrRef = useRef([]) // temp array for holding descriptions of selected images, before saved to project
|
|
58
59
|
const imgValidArrRef = useRef([]) // temp array for holding boolean value specifying whether each image title is valid or not
|
|
59
60
|
const actionSheetRef = useRef(null)
|
|
60
|
-
const pendingCameraResultRef = useRef(
|
|
61
|
+
const pendingCameraResultRef = useRef([])
|
|
62
|
+
const cameraResultResolverRef = useRef(null)
|
|
63
|
+
const isMountedRef = useRef(true)
|
|
64
|
+
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
isMountedRef.current = true
|
|
67
|
+
return () => {
|
|
68
|
+
isMountedRef.current = false
|
|
69
|
+
cameraResultResolverRef.current?.([])
|
|
70
|
+
cameraResultResolverRef.current = null
|
|
71
|
+
}
|
|
72
|
+
}, [])
|
|
61
73
|
|
|
62
74
|
const resolvedMaxCount = useMemo(() => {
|
|
63
75
|
const parsedMaxCount = Number(maxCount)
|
|
@@ -198,7 +210,7 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
198
210
|
|
|
199
211
|
const hasPermission = permission ? await requestPermissions(permission) : true
|
|
200
212
|
if (hasPermission) {
|
|
201
|
-
action(options) //
|
|
213
|
+
return action(options) // Keep the operation locked until selection and saving finish.
|
|
202
214
|
} else {
|
|
203
215
|
showPermissionAlert('Both Storage and the Photos and Videos')
|
|
204
216
|
}
|
|
@@ -213,10 +225,12 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
213
225
|
return
|
|
214
226
|
}
|
|
215
227
|
|
|
216
|
-
|
|
228
|
+
const loadingToken = showLoadingOverlay({ message: 'Processing Photos...' })
|
|
217
229
|
|
|
218
230
|
try {
|
|
231
|
+
await new Promise(resolve => requestAnimationFrame(resolve))
|
|
219
232
|
for (let i = 0; i < imgArrRef.current.length; i++) {
|
|
233
|
+
console.log('[MultiImagePicker] Processing image:', imgArrRef.current[i].path)
|
|
220
234
|
const resizedImage = await ImageResizer.createResizedImage(
|
|
221
235
|
imgArrRef.current[i].path,
|
|
222
236
|
2000,
|
|
@@ -225,6 +239,12 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
225
239
|
80
|
|
226
240
|
)
|
|
227
241
|
await Api.getApi().moveLocalFile(resizedImage.path, imgArrRef.current[i].path, true)
|
|
242
|
+
imgArrRef.current[i] = {
|
|
243
|
+
...imgArrRef.current[i],
|
|
244
|
+
mime: 'image/jpeg',
|
|
245
|
+
width: resizedImage.width,
|
|
246
|
+
height: resizedImage.height
|
|
247
|
+
}
|
|
228
248
|
}
|
|
229
249
|
|
|
230
250
|
await Promise.resolve(callback({
|
|
@@ -237,211 +257,123 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
237
257
|
callbackData
|
|
238
258
|
}))
|
|
239
259
|
} finally {
|
|
240
|
-
|
|
260
|
+
hideLoadingOverlay(loadingToken)
|
|
241
261
|
}
|
|
242
262
|
}, [callback, callbackData])
|
|
243
263
|
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
imgDescArrRef.current = []
|
|
247
|
-
imgValidArrRef.current = []
|
|
248
|
-
|
|
249
|
-
images.forEach((img) => {
|
|
250
|
-
const imageData = {
|
|
251
|
-
path: img.imageURI,
|
|
252
|
-
mime: 'image/jpeg',
|
|
253
|
-
width: 2000,
|
|
254
|
-
height: 2000
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (img.depthMapURI) {
|
|
258
|
-
imageData.depthMapUri = img.depthMapURI
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
imgArrRef.current.push(imageData)
|
|
262
|
-
imgDescArrRef.current.push('')
|
|
263
|
-
imgValidArrRef.current.push(true)
|
|
264
|
-
})
|
|
265
|
-
|
|
266
|
-
pickerDone(pickerIndex, cancelIndex, 'taken')
|
|
267
|
-
}, [pickerDone])
|
|
268
|
-
|
|
269
|
-
const handleCameraModalDone = useCallback(async (images = []) => {
|
|
270
|
-
// Handle images returned from CameraModal
|
|
271
|
-
console.log('SWSI Camera modal done, images:', images)
|
|
272
|
-
|
|
273
|
-
const pickerIndex = pendingPickerIndex
|
|
274
|
-
const cancelIndex = pendingCancelIndex
|
|
275
|
-
|
|
276
|
-
pendingCameraResultRef.current = {
|
|
277
|
-
images,
|
|
278
|
-
pickerIndex,
|
|
279
|
-
cancelIndex
|
|
280
|
-
}
|
|
281
|
-
|
|
264
|
+
const handleCameraModalDone = useCallback((images = []) => {
|
|
265
|
+
pendingCameraResultRef.current = images
|
|
282
266
|
setShowCameraModal(false)
|
|
283
267
|
resetActionSheet()
|
|
284
|
-
}, [
|
|
268
|
+
}, [resetActionSheet])
|
|
285
269
|
|
|
286
270
|
const handleCameraModalDismiss = useCallback(() => {
|
|
287
|
-
const pendingResult = pendingCameraResultRef.current
|
|
288
|
-
pendingCameraResultRef.current = null
|
|
289
|
-
|
|
290
271
|
setIsCameraModalMounted(false)
|
|
272
|
+
// Do not open the editor until the native camera modal has finished dismissing.
|
|
273
|
+
cameraResultResolverRef.current?.(pendingCameraResultRef.current)
|
|
274
|
+
cameraResultResolverRef.current = null
|
|
275
|
+
pendingCameraResultRef.current = []
|
|
276
|
+
}, [])
|
|
291
277
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
278
|
+
const takePictures = useCallback(async (options) => {
|
|
279
|
+
const images = []
|
|
280
|
+
while (images.length < remainingCount && isMountedRef.current) {
|
|
281
|
+
const hasPermission = await requestCameraPermission()
|
|
282
|
+
if (!hasPermission) {
|
|
283
|
+
showPermissionAlert('Camera')
|
|
284
|
+
break
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
images.push(await ImagePicker.openCamera(options))
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (error.code !== 'E_PICKER_CANCELLED') throw error
|
|
290
|
+
break
|
|
303
291
|
}
|
|
304
292
|
}
|
|
305
|
-
|
|
306
|
-
setPendingPickerIndex(null)
|
|
307
|
-
setPendingCancelIndex(null)
|
|
308
|
-
}, [processCameraModalImages])
|
|
309
|
-
|
|
310
|
-
const takeOnePicture = useCallback(async (
|
|
311
|
-
index,
|
|
312
|
-
cancelIndex,
|
|
313
|
-
options,
|
|
314
|
-
depth,
|
|
315
|
-
done
|
|
316
|
-
) => {
|
|
317
|
-
if (depth > remainingCount) {
|
|
318
|
-
done()
|
|
319
|
-
return
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
const hasPermission = await requestCameraPermission()
|
|
323
|
-
if (!hasPermission) {
|
|
324
|
-
showPermissionAlert('Camera')
|
|
325
|
-
done()
|
|
326
|
-
return
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
try {
|
|
330
|
-
const image = await ImagePicker.openCamera(options)
|
|
331
|
-
console.log('SWSI take photo, image: ' + JSON.stringify(image))
|
|
332
|
-
imgArrRef.current.push(image)
|
|
333
|
-
imgDescArrRef.current.push('')
|
|
334
|
-
imgValidArrRef.current.push(true)
|
|
335
|
-
await takeOnePicture(index, cancelIndex, options, depth + 1, done)
|
|
336
|
-
} catch (e) {
|
|
337
|
-
done()
|
|
338
|
-
}
|
|
293
|
+
return images
|
|
339
294
|
}, [remainingCount, requestCameraPermission, showPermissionAlert])
|
|
340
295
|
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
// initializes cRef.imgValidArr to an array of booleans (all true) for all selected images, to be used/updated by calling code as needed
|
|
347
|
-
|
|
348
|
-
const options = {
|
|
349
|
-
multiple: true,
|
|
350
|
-
maxFiles: remainingCount, // ios only
|
|
351
|
-
cropping: false,
|
|
352
|
-
mediaType: 'photo'
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
imgArrRef.current = [] // clear selected images
|
|
356
|
-
imgDescArrRef.current = [] // clear descriptions for selected images
|
|
357
|
-
imgValidArrRef.current = [] // clear valid flags for selected images
|
|
358
|
-
|
|
359
|
-
const takePhotoIndex = cancelIndex - 2
|
|
360
|
-
const chooseLibIndex = cancelIndex - 1
|
|
361
|
-
let imageSource = null
|
|
296
|
+
const handleUsePicker = useCallback(async (index, cancelIndex) => {
|
|
297
|
+
if (index === cancelIndex) return
|
|
298
|
+
const operation = beginPhotoOperation()
|
|
299
|
+
if (!operation) return
|
|
300
|
+
setIsBusy(true)
|
|
362
301
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
302
|
+
try {
|
|
303
|
+
const options = {
|
|
304
|
+
multiple: true,
|
|
305
|
+
maxFiles: remainingCount,
|
|
306
|
+
cropping: false,
|
|
307
|
+
mediaType: 'photo'
|
|
308
|
+
}
|
|
309
|
+
imgArrRef.current = []
|
|
310
|
+
imgDescArrRef.current = []
|
|
311
|
+
imgValidArrRef.current = []
|
|
312
|
+
const takePhotoIndex = cancelIndex - 2
|
|
313
|
+
const chooseLibIndex = cancelIndex - 1
|
|
314
|
+
|
|
315
|
+
if (index !== takePhotoIndex && index !== chooseLibIndex) {
|
|
316
|
+
await pickerDone(index, cancelIndex)
|
|
317
|
+
return
|
|
318
|
+
}
|
|
319
|
+
if (remainingCount <= 0) {
|
|
320
|
+
showSelectionLimitAlert()
|
|
321
|
+
return
|
|
322
|
+
}
|
|
371
323
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (!
|
|
324
|
+
let images
|
|
325
|
+
if (index === takePhotoIndex) {
|
|
326
|
+
if (Platform.OS === 'ios' && parseInt(Platform.Version, 10) >= 26) {
|
|
327
|
+
if (!await requestCameraPermission()) {
|
|
376
328
|
showPermissionAlert('Camera')
|
|
377
|
-
|
|
329
|
+
return
|
|
378
330
|
}
|
|
379
331
|
await waitForAppToBeActive()
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
332
|
+
if (!isMountedRef.current) return
|
|
333
|
+
const captured = await new Promise(resolve => {
|
|
334
|
+
cameraResultResolverRef.current = resolve
|
|
335
|
+
resetActionSheet()
|
|
336
|
+
setIsCameraModalMounted(true)
|
|
337
|
+
setShowCameraModal(true)
|
|
338
|
+
})
|
|
339
|
+
images = captured.map(img => ({
|
|
340
|
+
path: img.imageURI,
|
|
341
|
+
mime: 'image/jpeg',
|
|
342
|
+
...(img.depthMapURI ? { depthMapUri: img.depthMapURI } : {})
|
|
343
|
+
}))
|
|
385
344
|
} else {
|
|
386
|
-
|
|
387
|
-
checkAndOpenPicker(options, () =>
|
|
388
|
-
takeOnePicture(index, cancelIndex, options, 1, () => {
|
|
389
|
-
if (imgArrRef.current.length > 0) {
|
|
390
|
-
imageSource = 'taken'
|
|
391
|
-
pickerDone(index, cancelIndex, imageSource)
|
|
392
|
-
}
|
|
393
|
-
})
|
|
394
|
-
)
|
|
345
|
+
images = await checkAndOpenPicker(options, takePictures)
|
|
395
346
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
.catch((err) => {
|
|
418
|
-
console.log(`----usePicker Image Picker Error: ${err.message}`)
|
|
419
|
-
})
|
|
420
|
-
)
|
|
421
|
-
break
|
|
422
|
-
case cancelIndex:
|
|
423
|
-
console.log('----usePicker User pressed cancel')
|
|
424
|
-
break
|
|
425
|
-
default:
|
|
426
|
-
console.log('----usePicker User pressed custom button')
|
|
427
|
-
pickerDone(index, cancelIndex)
|
|
347
|
+
} else {
|
|
348
|
+
images = await checkAndOpenPicker(options, pickerOptions => ImagePicker.openPicker(pickerOptions))
|
|
349
|
+
}
|
|
350
|
+
if (!isMountedRef.current || !images) return
|
|
351
|
+
images = Array.isArray(images) ? images : [images]
|
|
352
|
+
if (images.length === 0) return
|
|
353
|
+
if (images.length > remainingCount) {
|
|
354
|
+
showSelectionLimitAlert()
|
|
355
|
+
return
|
|
356
|
+
}
|
|
357
|
+
imgArrRef.current = images
|
|
358
|
+
imgDescArrRef.current = Array(images.length).fill('')
|
|
359
|
+
imgValidArrRef.current = Array(images.length).fill(true)
|
|
360
|
+
await pickerDone(index, cancelIndex, index === takePhotoIndex ? 'taken' : 'library')
|
|
361
|
+
} catch (error) {
|
|
362
|
+
if (error.code !== 'E_PICKER_CANCELLED' && isMountedRef.current) {
|
|
363
|
+
Alert.alert('Unable to add photos', error.message || 'Please try again.')
|
|
364
|
+
}
|
|
365
|
+
} finally {
|
|
366
|
+
endPhotoOperation(operation)
|
|
367
|
+
if (isMountedRef.current) setIsBusy(false)
|
|
428
368
|
}
|
|
429
|
-
}, [
|
|
430
|
-
checkAndOpenPicker,
|
|
431
|
-
pickerDone,
|
|
432
|
-
remainingCount,
|
|
433
|
-
requestCameraPermission,
|
|
434
|
-
resetActionSheet,
|
|
435
|
-
showPermissionAlert,
|
|
436
|
-
showSelectionLimitAlert,
|
|
437
|
-
takeOnePicture
|
|
438
|
-
])
|
|
369
|
+
}, [checkAndOpenPicker, pickerDone, remainingCount, requestCameraPermission, resetActionSheet, showPermissionAlert, showSelectionLimitAlert, takePictures])
|
|
439
370
|
|
|
440
371
|
const showActionSheet = useCallback(() => {
|
|
372
|
+
if (isPhotoOperationActive() || touchableProps.disabled) return
|
|
441
373
|
if (actionSheetRef.current && typeof actionSheetRef.current.show === 'function') {
|
|
442
374
|
actionSheetRef.current.show()
|
|
443
375
|
}
|
|
444
|
-
}, [])
|
|
376
|
+
}, [touchableProps.disabled])
|
|
445
377
|
|
|
446
378
|
useImperativeHandle(ref, () => ({
|
|
447
379
|
showActionSheet
|
|
@@ -463,9 +395,9 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
463
395
|
title={title}
|
|
464
396
|
options={buttonArr}
|
|
465
397
|
cancelButtonIndex={cancelIndex}
|
|
466
|
-
onPress={(buttonIndex) =>
|
|
398
|
+
onPress={(buttonIndex) => handleUsePicker(buttonIndex, cancelIndex)}
|
|
467
399
|
/>
|
|
468
|
-
<TouchableOpacity {...touchableProps} onPress={showActionSheet}>
|
|
400
|
+
<TouchableOpacity {...touchableProps} disabled={touchableProps.disabled || isBusy} onPress={showActionSheet}>
|
|
469
401
|
{children}
|
|
470
402
|
</TouchableOpacity>
|
|
471
403
|
{Platform.OS === 'ios' && isCameraModalMounted && (
|
|
@@ -481,6 +413,7 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
481
413
|
onDone={handleCameraModalDone}
|
|
482
414
|
limit={remainingCount}
|
|
483
415
|
onCancel={() => handleCameraModalDone([])}
|
|
416
|
+
angleGuideEnabled={angleGuideEnabled}
|
|
484
417
|
/>
|
|
485
418
|
</Modal>
|
|
486
419
|
)}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useCallback, useMemo, useEffect, useState } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
|
+
FlatList,
|
|
4
5
|
Modal
|
|
5
6
|
} from 'react-native'
|
|
6
7
|
import SingleImage from './SingleImage'
|
|
@@ -46,6 +47,7 @@ const SelectedImages = (
|
|
|
46
47
|
const [mediaOpen, setMediaOpen] = useState(false)
|
|
47
48
|
const [mediaIndex, setMediaIndex] = useState(0)
|
|
48
49
|
const [version, setVersion] = useState(0)
|
|
50
|
+
const [imageVersions, setImageVersions] = useState({})
|
|
49
51
|
|
|
50
52
|
const resourceList = useMemo(() => {
|
|
51
53
|
return items.map((img, idx) => ({
|
|
@@ -65,7 +67,11 @@ const SelectedImages = (
|
|
|
65
67
|
const closeMedia = useCallback(() => setMediaOpen(false), [])
|
|
66
68
|
|
|
67
69
|
// When MediaPlayer saves an annotated image, refresh the list and bust cache
|
|
68
|
-
const handleMediaUpdated = useCallback((newPath) => {
|
|
70
|
+
const handleMediaUpdated = useCallback(async (newPath) => {
|
|
71
|
+
if (newPath) {
|
|
72
|
+
await Api.getApi().deleteThumbnail?.(newPath)
|
|
73
|
+
setImageVersions(current => ({ ...current, [newPath]: (current[newPath] || 0) + 1 }))
|
|
74
|
+
}
|
|
69
75
|
if (typeof onItemChange === 'function' && newPath) {
|
|
70
76
|
onItemChange(mediaIndex, { path: newPath })
|
|
71
77
|
}
|
|
@@ -96,7 +102,16 @@ const SelectedImages = (
|
|
|
96
102
|
|
|
97
103
|
return (
|
|
98
104
|
<>
|
|
99
|
-
|
|
105
|
+
<FlatList
|
|
106
|
+
data={items}
|
|
107
|
+
extraData={{ version, imageVersions }}
|
|
108
|
+
keyExtractor={item => item.path}
|
|
109
|
+
initialNumToRender={6}
|
|
110
|
+
maxToRenderPerBatch={4}
|
|
111
|
+
windowSize={3}
|
|
112
|
+
contentContainerStyle={{ paddingBottom: 100, paddingTop: 8 }}
|
|
113
|
+
keyboardShouldPersistTaps='handled'
|
|
114
|
+
renderItem={({ item: o, index: idx }) => (
|
|
100
115
|
<View key={idx}>
|
|
101
116
|
<SingleImage
|
|
102
117
|
imgObject={o}
|
|
@@ -113,10 +128,11 @@ const SelectedImages = (
|
|
|
113
128
|
onDelete={() => { if (typeof onDeleteItem === 'function') onDeleteItem(idx) }}
|
|
114
129
|
disableDelete={items.length <= 1}
|
|
115
130
|
initialDesc={o.desc || ''}
|
|
116
|
-
cacheVersion={
|
|
131
|
+
cacheVersion={imageVersions[o.path] || 0}
|
|
117
132
|
/>
|
|
118
133
|
</View>
|
|
119
|
-
|
|
134
|
+
)}
|
|
135
|
+
/>
|
|
120
136
|
{mediaOpen && (
|
|
121
137
|
<Modal
|
|
122
138
|
presentationStyle='fullScreen'
|
|
@@ -18,6 +18,14 @@ import ImageDetailsModal from './ImageDetailsModal'
|
|
|
18
18
|
import ImageIndicators from './ImageIndicators'
|
|
19
19
|
import { ScreenSafeAreaView } from '@supportworks/core-controls'
|
|
20
20
|
|
|
21
|
+
// Hosts without a persistent thumbnail API still resize one preview at a time.
|
|
22
|
+
let thumbnailQueue = Promise.resolve()
|
|
23
|
+
const createTemporaryThumbnail = path => {
|
|
24
|
+
const job = thumbnailQueue.then(() => ImageResizer.createResizedImage(path, 200, 200, 'JPEG', 80))
|
|
25
|
+
thumbnailQueue = job.catch(() => {})
|
|
26
|
+
return job
|
|
27
|
+
}
|
|
28
|
+
|
|
21
29
|
const SingleImage = (
|
|
22
30
|
{
|
|
23
31
|
imgObject = {}, // object
|
|
@@ -65,6 +73,31 @@ const SingleImage = (
|
|
|
65
73
|
const [annotationJson, setAnnotationJson] = useState({ history: [], settings: {} })
|
|
66
74
|
const [filePath, setFilePath] = useState('')
|
|
67
75
|
const [version, setVersion] = useState(1)
|
|
76
|
+
const [thumbnailUri, setThumbnailUri] = useState(null)
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
let active = true
|
|
80
|
+
let temporaryPath
|
|
81
|
+
const api = Api.getApi()
|
|
82
|
+
const removeTemporaryThumbnail = () => {
|
|
83
|
+
if (temporaryPath) api.RNFS.unlink(temporaryPath).catch(() => {})
|
|
84
|
+
}
|
|
85
|
+
setThumbnailUri(null)
|
|
86
|
+
const thumbnail = typeof api.makeThumbnail === 'function'
|
|
87
|
+
? api.makeThumbnail(api.fullPath(imagePath)).then(path => path && api.fullImagePath(path, true))
|
|
88
|
+
: createTemporaryThumbnail(imagePath).then(image => {
|
|
89
|
+
temporaryPath = image.path
|
|
90
|
+
if (!active) removeTemporaryThumbnail()
|
|
91
|
+
return image.uri
|
|
92
|
+
})
|
|
93
|
+
thumbnail.then(uri => {
|
|
94
|
+
if (active && uri) setThumbnailUri(uri + (uri.includes('?') ? '&' : '?') + 'v=' + version + '-' + cacheVersion)
|
|
95
|
+
}).catch(() => {})
|
|
96
|
+
return () => {
|
|
97
|
+
active = false
|
|
98
|
+
removeTemporaryThumbnail()
|
|
99
|
+
}
|
|
100
|
+
}, [imagePath, version, cacheVersion])
|
|
68
101
|
const [showDetailsModal, setShowDetailsModal] = useState(false)
|
|
69
102
|
|
|
70
103
|
const initTitleRef = useRef(defaultTitle)
|
|
@@ -152,6 +185,7 @@ const SingleImage = (
|
|
|
152
185
|
await Api.getApi().moveLocalFile(info.fileName, filePath, true)
|
|
153
186
|
await Api.getApi().writeFile(filePath + '.json', JSON.stringify({ history: info.history, settings: info.settings }), 'utf8')
|
|
154
187
|
await Api.getApi().setCanvasSettings(info.settings)
|
|
188
|
+
await Api.getApi().deleteThumbnail?.(filePath)
|
|
155
189
|
setVersion(prev => prev + 1)
|
|
156
190
|
setShowCanvas(false)
|
|
157
191
|
setCanvasData('')
|
|
@@ -207,11 +241,11 @@ const SingleImage = (
|
|
|
207
241
|
<Block xsSize='100%' smSize={92}>
|
|
208
242
|
<TouchableOpacity onPress={() => { if (onOpenMedia) { onOpenMedia(imgIndex) } }}>
|
|
209
243
|
<View style={[styles.ImageContainer, { width: imageWidth, height: imageHeight }]}>
|
|
210
|
-
<Image
|
|
244
|
+
{thumbnailUri && <Image
|
|
211
245
|
resizeMode='cover'
|
|
212
246
|
style={[styles.Image, { width: '100%', height: '100%' }]}
|
|
213
|
-
source={{ uri:
|
|
214
|
-
/>
|
|
247
|
+
source={{ uri: thumbnailUri }}
|
|
248
|
+
/>}
|
|
215
249
|
<ImageIndicators
|
|
216
250
|
allowShowToCustomer={allowShowToCustomer}
|
|
217
251
|
showToCust={showToCust}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Shared by picker instances and the Attach step, including pickers inside different modals.
|
|
2
|
+
let activeOperation = null
|
|
3
|
+
|
|
4
|
+
export const beginPhotoOperation = () => {
|
|
5
|
+
if (activeOperation) return null
|
|
6
|
+
activeOperation = {}
|
|
7
|
+
return activeOperation
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const endPhotoOperation = operation => {
|
|
11
|
+
if (activeOperation === operation) activeOperation = null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const isPhotoOperationActive = () => activeOperation !== null
|