@supportworks/multi-imagepicker 8.0.13 → 8.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changes.md
CHANGED
package/package.json
CHANGED
|
@@ -33,12 +33,12 @@ const ActionBar = (
|
|
|
33
33
|
{false && <TouchableOpacity style={styles.IconContainer} onPress={onPressDetails}>
|
|
34
34
|
<Icons.IconArrowRightTop />
|
|
35
35
|
</TouchableOpacity>}
|
|
36
|
-
<TouchableOpacity style={styles.IconContainer} onPress={onPressDetails}>
|
|
36
|
+
<TouchableOpacity style={[styles.IconContainer, (!allowSaveToDevice && !annotationAllowed && !allowShowToCustomer) ? styles.IconContainerLast : null]} onPress={onPressDetails}>
|
|
37
37
|
<Icons.IconNotesWrite />
|
|
38
38
|
</TouchableOpacity>
|
|
39
39
|
{allowSaveToDevice && (
|
|
40
40
|
<TouchableOpacity
|
|
41
|
-
style={styles.IconContainer}
|
|
41
|
+
style={[styles.IconContainer, (!annotationAllowed && !allowShowToCustomer) ? styles.IconContainerLast : null]}
|
|
42
42
|
onPress={onToggleSaveToDevice}
|
|
43
43
|
>
|
|
44
44
|
{saveToDevice
|
|
@@ -47,7 +47,7 @@ const ActionBar = (
|
|
|
47
47
|
</TouchableOpacity>
|
|
48
48
|
)}
|
|
49
49
|
{annotationAllowed && (
|
|
50
|
-
<TouchableOpacity style={styles.IconContainer} onPress={onAnnotate}>
|
|
50
|
+
<TouchableOpacity style={[styles.IconContainer, !allowShowToCustomer ? styles.IconContainerLast : null]} onPress={onAnnotate}>
|
|
51
51
|
<Icons.IconAnnotate />
|
|
52
52
|
</TouchableOpacity>
|
|
53
53
|
)}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
CameraView,
|
|
8
8
|
CameraViewRef,
|
|
9
9
|
OnStatusChangeEventPayload,
|
|
10
|
+
OnCamerasAvailableEventPayload,
|
|
10
11
|
OnPhotoCapturedEventPayload,
|
|
11
12
|
ZoomLevel
|
|
12
13
|
} from '@supportworks/camera'
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
Text,
|
|
17
18
|
StyleSheet,
|
|
18
19
|
TouchableOpacity,
|
|
20
|
+
Pressable,
|
|
19
21
|
Alert,
|
|
20
22
|
Image,
|
|
21
23
|
ScrollView,
|
|
@@ -44,39 +46,45 @@ interface CameraTestModalProps {
|
|
|
44
46
|
|
|
45
47
|
// Event types are now imported from the camera module
|
|
46
48
|
|
|
47
|
-
const ZOOM_LEVELS: ZoomLevel[] = ['1x', '2x', '3x', '4x', '5x']
|
|
48
49
|
const ZOOM_SLIDER_TRACK_LENGTH = 180
|
|
49
50
|
const ZOOM_SLIDER_WIDTH = 40
|
|
50
51
|
const ZOOM_SLIDER_THUMB_SIZE = 32
|
|
51
|
-
const
|
|
52
|
-
const
|
|
52
|
+
const MIN_ZOOM = 1
|
|
53
|
+
const MAX_ZOOM = 5
|
|
54
|
+
const ZOOM_STEP = 0.1
|
|
55
|
+
const ZOOM_RANGE = MAX_ZOOM - MIN_ZOOM
|
|
56
|
+
const DEFAULT_ZOOM = 1
|
|
57
|
+
const FOCUS_RING_SIZE = 72
|
|
53
58
|
|
|
54
59
|
const clamp = (value: number, min: number, max: number) => {
|
|
55
60
|
return Math.min(Math.max(value, min), max)
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
const formatZoomLabel = (zoom: number): ZoomLevel => {
|
|
64
|
+
const rounded = Math.round(zoom * 10) / 10
|
|
65
|
+
const isWhole = Math.abs(rounded - Math.round(rounded)) < 0.01
|
|
66
|
+
return `${isWhole ? rounded.toFixed(0) : rounded.toFixed(1)}x`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const getTopPositionForZoom = (zoom: number) => {
|
|
70
|
+
if (ZOOM_RANGE <= 0) {
|
|
64
71
|
return 0
|
|
65
72
|
}
|
|
66
|
-
|
|
67
|
-
const
|
|
68
|
-
return
|
|
73
|
+
const clampedZoom = clamp(zoom, MIN_ZOOM, MAX_ZOOM)
|
|
74
|
+
const normalized = (MAX_ZOOM - clampedZoom) / ZOOM_RANGE
|
|
75
|
+
return normalized * ZOOM_SLIDER_TRACK_LENGTH
|
|
69
76
|
}
|
|
70
77
|
|
|
71
|
-
const getZoomForTopPosition = (position: number):
|
|
72
|
-
if (
|
|
78
|
+
const getZoomForTopPosition = (position: number): number => {
|
|
79
|
+
if (ZOOM_RANGE <= 0) {
|
|
73
80
|
return DEFAULT_ZOOM
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
const clampedPosition = clamp(position, 0, ZOOM_SLIDER_TRACK_LENGTH)
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
84
|
+
const normalized = clampedPosition / ZOOM_SLIDER_TRACK_LENGTH
|
|
85
|
+
const zoom = MAX_ZOOM - normalized * ZOOM_RANGE
|
|
86
|
+
const stepped = Math.round(zoom / ZOOM_STEP) * ZOOM_STEP
|
|
87
|
+
return clamp(stepped, MIN_ZOOM, MAX_ZOOM)
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
const FlipCameraIcon: React.FC<{ size?: number; color?: string }> = ({ size = 28, color = colors.white }) => (
|
|
@@ -122,22 +130,45 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
122
130
|
}, [externalCameraRef, cameraRef])
|
|
123
131
|
const swipeModalRef = useRef<any>(null)
|
|
124
132
|
const shutterFlashAnim = useRef(new Animated.Value(0)).current
|
|
125
|
-
const [currentZoom, setCurrentZoom] = useState<
|
|
133
|
+
const [currentZoom, setCurrentZoom] = useState<number>(DEFAULT_ZOOM)
|
|
126
134
|
const [isDepthEnabled, setIsDepthEnabled] = useState<boolean>(true)
|
|
127
135
|
const [isFlashEnabled, setIsFlashEnabled] = useState<boolean>(false)
|
|
136
|
+
const [canZoomByPosition, setCanZoomByPosition] = useState<{ front: boolean; back: boolean }>({
|
|
137
|
+
front: false,
|
|
138
|
+
back: false
|
|
139
|
+
})
|
|
128
140
|
const [capturedImages, setCapturedImages] = useState<CapturedImage[]>([])
|
|
129
141
|
const [isFrontCamera, setIsFrontCamera] = useState<boolean>(false)
|
|
130
142
|
const [isGalleryModalVisible, setIsGalleryModalVisible] = useState<boolean>(false)
|
|
131
143
|
const [isDoneButtonDisabled, setIsDoneButtonDisabled] = useState<boolean>(false)
|
|
144
|
+
const [focusPoint, setFocusPoint] = useState<{ x: number; y: number } | null>(null)
|
|
132
145
|
const knobTop = useRef(new Animated.Value(getTopPositionForZoom(DEFAULT_ZOOM))).current
|
|
146
|
+
const focusAnim = useRef(new Animated.Value(0)).current
|
|
133
147
|
const dragStartOffset = useRef(0)
|
|
134
|
-
const
|
|
148
|
+
const zoomRailRef = useRef<View>(null)
|
|
149
|
+
const zoomRailTopRef = useRef<number | null>(null)
|
|
150
|
+
const isZoomAvailable = isFrontCamera ? canZoomByPosition.front : canZoomByPosition.back
|
|
151
|
+
const sliderDisabled = isFrontCamera || !isZoomAvailable
|
|
135
152
|
|
|
136
153
|
const handleStatusChange = (event: { nativeEvent: OnStatusChangeEventPayload }) => {
|
|
137
154
|
const newStatus = event?.nativeEvent?.status || 'Unknown'
|
|
138
|
-
console.log('CAMERA: Status changed to:', newStatus)
|
|
155
|
+
// console.log('CAMERA: Status changed to:', newStatus)
|
|
139
156
|
}
|
|
140
157
|
|
|
158
|
+
const handleCamerasAvailable = React.useCallback((event: { nativeEvent: OnCamerasAvailableEventPayload }) => {
|
|
159
|
+
const cameras = event?.nativeEvent?.cameras || []
|
|
160
|
+
const availability = { front: false, back: false }
|
|
161
|
+
cameras.forEach((camera) => {
|
|
162
|
+
const maxZoom = typeof camera.maxZoomFactor === 'number' ? camera.maxZoomFactor : 1
|
|
163
|
+
const minZoom = typeof camera.minZoomFactor === 'number' ? camera.minZoomFactor : 1
|
|
164
|
+
const hasZoom = maxZoom > 1.01 && maxZoom > minZoom
|
|
165
|
+
if (camera.position === 'front' || camera.position === 'back') {
|
|
166
|
+
availability[camera.position] = availability[camera.position] || hasZoom
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
setCanZoomByPosition(availability)
|
|
170
|
+
}, [])
|
|
171
|
+
|
|
141
172
|
const handlePhotoCaptured = (event: { nativeEvent: OnPhotoCapturedEventPayload }) => {
|
|
142
173
|
console.log('CAMERA: Photo captured event:', event)
|
|
143
174
|
const imageUri = event?.nativeEvent?.imageUri
|
|
@@ -179,6 +210,48 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
179
210
|
}
|
|
180
211
|
}
|
|
181
212
|
|
|
213
|
+
const handleZoomRailLayout = React.useCallback(() => {
|
|
214
|
+
zoomRailRef.current?.measureInWindow((_, y) => {
|
|
215
|
+
zoomRailTopRef.current = y
|
|
216
|
+
})
|
|
217
|
+
}, [])
|
|
218
|
+
|
|
219
|
+
const getZoomOffsetFromEvent = (event: { nativeEvent: { locationY: number; pageY: number } }) => {
|
|
220
|
+
const { locationY, pageY } = event.nativeEvent
|
|
221
|
+
const railTop = zoomRailTopRef.current
|
|
222
|
+
const rawOffset = railTop == null ? locationY : pageY - railTop
|
|
223
|
+
return clamp(rawOffset - ZOOM_SLIDER_THUMB_SIZE / 2, 0, ZOOM_SLIDER_TRACK_LENGTH)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const triggerFocusRing = React.useCallback(
|
|
227
|
+
(x: number, y: number) => {
|
|
228
|
+
setFocusPoint({ x, y })
|
|
229
|
+
focusAnim.stopAnimation()
|
|
230
|
+
focusAnim.setValue(0)
|
|
231
|
+
Animated.timing(focusAnim, {
|
|
232
|
+
toValue: 1,
|
|
233
|
+
duration: 700,
|
|
234
|
+
useNativeDriver: true
|
|
235
|
+
}).start(({ finished }) => {
|
|
236
|
+
if (finished) {
|
|
237
|
+
setFocusPoint(null)
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
},
|
|
241
|
+
[focusAnim]
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
const handleCameraPress = React.useCallback(
|
|
245
|
+
(event: { nativeEvent: { locationX: number; locationY: number } }) => {
|
|
246
|
+
const { locationX, locationY } = event.nativeEvent
|
|
247
|
+
triggerFocusRing(locationX, locationY)
|
|
248
|
+
if (cameraRef.current) {
|
|
249
|
+
cameraRef.current.focusAtPoint(locationX, locationY)
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
[cameraRef, triggerFocusRing]
|
|
253
|
+
)
|
|
254
|
+
|
|
182
255
|
const triggerShutterFlash = () => {
|
|
183
256
|
// Flash to black immediately
|
|
184
257
|
Animated.timing(shutterFlashAnim, {
|
|
@@ -242,8 +315,8 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
242
315
|
}
|
|
243
316
|
}
|
|
244
317
|
|
|
245
|
-
const handleZoomChange = React.useCallback((newZoom:
|
|
246
|
-
setCurrentZoom(newZoom)
|
|
318
|
+
const handleZoomChange = React.useCallback((newZoom: number) => {
|
|
319
|
+
setCurrentZoom(clamp(newZoom, MIN_ZOOM, MAX_ZOOM))
|
|
247
320
|
}, [])
|
|
248
321
|
|
|
249
322
|
React.useEffect(() => {
|
|
@@ -252,9 +325,15 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
252
325
|
}
|
|
253
326
|
}, [isFrontCamera, currentZoom])
|
|
254
327
|
|
|
328
|
+
React.useEffect(() => {
|
|
329
|
+
if (!isZoomAvailable && currentZoom !== DEFAULT_ZOOM) {
|
|
330
|
+
setCurrentZoom(DEFAULT_ZOOM)
|
|
331
|
+
}
|
|
332
|
+
}, [isZoomAvailable, currentZoom])
|
|
333
|
+
|
|
255
334
|
React.useEffect(() => {
|
|
256
335
|
if (cameraRef.current) {
|
|
257
|
-
cameraRef.current.setZoomLevel(currentZoom)
|
|
336
|
+
cameraRef.current.setZoomLevel(formatZoomLabel(currentZoom))
|
|
258
337
|
}
|
|
259
338
|
}, [cameraRef, currentZoom])
|
|
260
339
|
|
|
@@ -275,23 +354,23 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
275
354
|
onStartShouldSetPanResponder: () => !sliderDisabled,
|
|
276
355
|
onMoveShouldSetPanResponder: () => !sliderDisabled,
|
|
277
356
|
onPanResponderGrant: (evt) => {
|
|
278
|
-
const tapOffset =
|
|
357
|
+
const tapOffset = getZoomOffsetFromEvent(evt)
|
|
279
358
|
dragStartOffset.current = tapOffset
|
|
280
359
|
knobTop.setValue(tapOffset)
|
|
360
|
+
handleZoomChange(getZoomForTopPosition(tapOffset))
|
|
281
361
|
},
|
|
282
|
-
onPanResponderMove: (
|
|
283
|
-
const next =
|
|
362
|
+
onPanResponderMove: (evt) => {
|
|
363
|
+
const next = getZoomOffsetFromEvent(evt)
|
|
284
364
|
knobTop.setValue(next)
|
|
365
|
+
handleZoomChange(getZoomForTopPosition(next))
|
|
285
366
|
},
|
|
286
|
-
onPanResponderRelease: (
|
|
287
|
-
const next =
|
|
288
|
-
|
|
289
|
-
handleZoomChange(nextZoom)
|
|
367
|
+
onPanResponderRelease: (evt) => {
|
|
368
|
+
const next = getZoomOffsetFromEvent(evt)
|
|
369
|
+
handleZoomChange(getZoomForTopPosition(next))
|
|
290
370
|
},
|
|
291
|
-
onPanResponderTerminate: (
|
|
292
|
-
const next =
|
|
293
|
-
|
|
294
|
-
handleZoomChange(nextZoom)
|
|
371
|
+
onPanResponderTerminate: (evt) => {
|
|
372
|
+
const next = getZoomOffsetFromEvent(evt)
|
|
373
|
+
handleZoomChange(getZoomForTopPosition(next))
|
|
295
374
|
}
|
|
296
375
|
}),
|
|
297
376
|
[sliderDisabled, handleZoomChange, knobTop]
|
|
@@ -365,26 +444,59 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
365
444
|
|
|
366
445
|
{/* Camera View */}
|
|
367
446
|
<View style={styles.cameraContainer}>
|
|
368
|
-
<
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
447
|
+
<Pressable style={styles.cameraTouchLayer} onPress={handleCameraPress}>
|
|
448
|
+
<CameraView
|
|
449
|
+
ref={cameraRef}
|
|
450
|
+
isDepthEnabled={isDepthEnabled}
|
|
451
|
+
zoomLevel={formatZoomLabel(currentZoom)}
|
|
452
|
+
onStatusChange={handleStatusChange}
|
|
453
|
+
onCamerasAvailable={handleCamerasAvailable}
|
|
454
|
+
onPhotoCaptured={handlePhotoCaptured}
|
|
455
|
+
style={styles.camera}
|
|
456
|
+
/>
|
|
457
|
+
{focusPoint ? (
|
|
458
|
+
<Animated.View
|
|
459
|
+
style={[
|
|
460
|
+
styles.focusRing,
|
|
461
|
+
{
|
|
462
|
+
left: focusPoint.x - FOCUS_RING_SIZE / 2,
|
|
463
|
+
top: focusPoint.y - FOCUS_RING_SIZE / 2,
|
|
464
|
+
opacity: focusAnim.interpolate({
|
|
465
|
+
inputRange: [0, 0.7, 1],
|
|
466
|
+
outputRange: [1, 0.8, 0]
|
|
467
|
+
}),
|
|
468
|
+
transform: [
|
|
469
|
+
{
|
|
470
|
+
scale: focusAnim.interpolate({
|
|
471
|
+
inputRange: [0, 1],
|
|
472
|
+
outputRange: [1.4, 1]
|
|
473
|
+
})
|
|
474
|
+
}
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
]}
|
|
478
|
+
/>
|
|
479
|
+
) : null}
|
|
480
|
+
</Pressable>
|
|
376
481
|
</View>
|
|
377
482
|
|
|
378
|
-
|
|
379
|
-
<View style={[styles.
|
|
380
|
-
<View style={styles.
|
|
381
|
-
<View
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
483
|
+
{isZoomAvailable ? (
|
|
484
|
+
<View pointerEvents="box-none" style={[styles.zoomSliderContainer, { left: 20 + insets.left }]}>
|
|
485
|
+
<View style={[styles.zoomSlider, sliderDisabled && styles.zoomSliderDisabled]}>
|
|
486
|
+
<View
|
|
487
|
+
ref={zoomRailRef}
|
|
488
|
+
style={styles.zoomRailContainer}
|
|
489
|
+
onLayout={handleZoomRailLayout}
|
|
490
|
+
{...sliderPanResponder.panHandlers}
|
|
491
|
+
>
|
|
492
|
+
<View style={styles.zoomRail} />
|
|
493
|
+
<Animated.View style={[styles.zoomThumb, { top: knobTop }]}>
|
|
494
|
+
<Text style={styles.zoomThumbText}>{formatZoomLabel(currentZoom)}</Text>
|
|
495
|
+
</Animated.View>
|
|
496
|
+
</View>
|
|
385
497
|
</View>
|
|
386
498
|
</View>
|
|
387
|
-
|
|
499
|
+
) : null}
|
|
388
500
|
|
|
389
501
|
{/* Bottom Controls Container */}
|
|
390
502
|
<View style={styles.bottomControlsContainer}>
|
|
@@ -576,9 +688,21 @@ const styles = StyleSheet.create({
|
|
|
576
688
|
right: 0,
|
|
577
689
|
bottom: 0
|
|
578
690
|
},
|
|
691
|
+
cameraTouchLayer: {
|
|
692
|
+
flex: 1
|
|
693
|
+
},
|
|
579
694
|
camera: {
|
|
580
695
|
flex: 1
|
|
581
696
|
},
|
|
697
|
+
focusRing: {
|
|
698
|
+
position: 'absolute',
|
|
699
|
+
width: FOCUS_RING_SIZE,
|
|
700
|
+
height: FOCUS_RING_SIZE,
|
|
701
|
+
borderRadius: FOCUS_RING_SIZE / 2,
|
|
702
|
+
borderWidth: 2,
|
|
703
|
+
borderColor: colors.white,
|
|
704
|
+
backgroundColor: 'transparent'
|
|
705
|
+
},
|
|
582
706
|
bottomControlsContainer: {
|
|
583
707
|
position: 'absolute',
|
|
584
708
|
bottom: 30,
|