@supportworks/multi-imagepicker 8.3.7 → 8.3.8
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/package.json +1 -1
- package/src/components/CameraModal.tsx +188 -82
- package/src/components/MultiImagePicker.js +38 -40
package/package.json
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
OnStatusChangeEventPayload,
|
|
11
11
|
OnCamerasAvailableEventPayload,
|
|
12
12
|
OnPhotoCapturedEventPayload,
|
|
13
|
+
OnCaptureStateChangeEventPayload,
|
|
14
|
+
OnErrorEventPayload,
|
|
13
15
|
ZoomLevel
|
|
14
16
|
} from '@supportworks/camera'
|
|
15
17
|
import React, { useRef, useState } from 'react'
|
|
@@ -197,7 +199,47 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
197
199
|
const internalCameraRef = useRef<CameraViewRef>(null)
|
|
198
200
|
const cameraRef = externalCameraRef || internalCameraRef
|
|
199
201
|
const insets = useSafeAreaInsets()
|
|
200
|
-
const { height: windowHeight } = useWindowDimensions()
|
|
202
|
+
const { width: windowWidth, height: windowHeight } = useWindowDimensions()
|
|
203
|
+
const shortestSide = Math.min(windowWidth, windowHeight)
|
|
204
|
+
const isLandscape = windowWidth > windowHeight
|
|
205
|
+
const isPhoneSized = shortestSide < 500
|
|
206
|
+
const isTightLayout = isPhoneSized && isLandscape
|
|
207
|
+
const controlScale = isTightLayout
|
|
208
|
+
? clamp(windowHeight / 430, 0.72, 0.82)
|
|
209
|
+
: isPhoneSized
|
|
210
|
+
? clamp(shortestSide / 430, 0.88, 0.94)
|
|
211
|
+
: 1
|
|
212
|
+
const scaleMetric = (value: number, min = 0) => Math.max(min, Math.round(value * controlScale))
|
|
213
|
+
const focusRingSize = scaleMetric(FOCUS_RING_SIZE, 52)
|
|
214
|
+
const cancelButtonMinWidth = scaleMetric(56, 48)
|
|
215
|
+
const cancelButtonHeight = scaleMetric(34, 30)
|
|
216
|
+
const cancelButtonPaddingHorizontal = scaleMetric(14, 12)
|
|
217
|
+
const cancelButtonFontSize = scaleMetric(14, 12)
|
|
218
|
+
const captureBadgeSize = scaleMetric(26, 22)
|
|
219
|
+
const captureBadgeFontSize = scaleMetric(13, 11)
|
|
220
|
+
const sideButtonSize = scaleMetric(SIDE_BUTTON_SIZE, 38)
|
|
221
|
+
const sideButtonGap = scaleMetric(SIDE_BUTTON_GAP, 10)
|
|
222
|
+
const sideButtonIconSize = scaleMetric(SIDE_BUTTON_ICON_SIZE, 20)
|
|
223
|
+
const sideButtonTextSize = scaleMetric(SIDE_BUTTON_TEXT_SIZE, 12)
|
|
224
|
+
const sideActionGroupMarginBottom = scaleMetric(SIDE_ACTION_GROUP_MARGIN_BOTTOM, 16)
|
|
225
|
+
const galleryPreviewSize = scaleMetric(GALLERY_PREVIEW_SIZE, 34)
|
|
226
|
+
const galleryPreviewMarginBottom = scaleMetric(GALLERY_PREVIEW_MARGIN_BOTTOM, 16)
|
|
227
|
+
const galleryPreviewBorderRadius = scaleMetric(GALLERY_PREVIEW_BORDER_RADIUS, 10)
|
|
228
|
+
const galleryPreviewBadgeSize = scaleMetric(GALLERY_PREVIEW_BADGE_SIZE, 22)
|
|
229
|
+
const shutterButtonSize = scaleMetric(SHUTTER_BUTTON_SIZE, 58)
|
|
230
|
+
const shutterButtonMarginBottom = scaleMetric(SHUTTER_BUTTON_MARGIN_BOTTOM, 12)
|
|
231
|
+
const shutterInnerSize = scaleMetric(62, 46)
|
|
232
|
+
const doneButtonHeight = scaleMetric(DONE_BUTTON_HEIGHT, 30)
|
|
233
|
+
const doneButtonHorizontalPadding = scaleMetric(DONE_BUTTON_HORIZONTAL_PADDING, 16)
|
|
234
|
+
const doneButtonTextSize = scaleMetric(DONE_BUTTON_TEXT_SIZE, 16)
|
|
235
|
+
const doneButtonIconSize = scaleMetric(DONE_BUTTON_ICON_SIZE, 20)
|
|
236
|
+
const doneButtonMarginBottom = scaleMetric(30, 18)
|
|
237
|
+
const rightOverlayWidth = scaleMetric(RIGHT_OVERLAY_WIDTH, 96)
|
|
238
|
+
const topOverlayHorizontalInset = isTightLayout ? 10 : isPhoneSized ? 14 : 18
|
|
239
|
+
const overlaySideInset = isTightLayout ? 8 : isPhoneSized ? 10 : 16
|
|
240
|
+
const showFlashControl = !isTightLayout
|
|
241
|
+
const showCameraSwitchControl = !isTightLayout
|
|
242
|
+
const showSecondaryControls = showFlashControl || showCameraSwitchControl
|
|
201
243
|
|
|
202
244
|
// Debug logging
|
|
203
245
|
React.useEffect(() => {
|
|
@@ -229,12 +271,13 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
229
271
|
const zoomRailRef = useRef<View>(null)
|
|
230
272
|
const zoomRailTopRef = useRef<number | null>(null)
|
|
231
273
|
const capturePendingRef = useRef(false)
|
|
232
|
-
const capturePendingTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
233
274
|
const currentZoomRange = isFrontCamera ? zoomRangeByPosition.front : zoomRangeByPosition.back
|
|
234
275
|
const isZoomAvailable = currentZoomRange.max - currentZoomRange.min > 0.01
|
|
235
276
|
const captureLimit = typeof limit === 'number' && limit > 0 ? limit : null
|
|
236
277
|
const hasReachedCaptureLimit = captureLimit !== null && capturedImages.length >= captureLimit
|
|
237
278
|
const isShutterDisabled = isCapturePending || hasReachedCaptureLimit
|
|
279
|
+
const isCancelDisabled = isCapturePending
|
|
280
|
+
const isDoneDisabled = isDoneButtonDisabled || isCapturePending
|
|
238
281
|
const captureLimitMessage = captureLimit
|
|
239
282
|
? `Maximum of ${captureLimit} photo${captureLimit === 1 ? '' : 's'} reached`
|
|
240
283
|
: ''
|
|
@@ -247,27 +290,10 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
247
290
|
Alert.alert('Selection Limit', captureLimitMessage)
|
|
248
291
|
}, [captureLimit, captureLimitMessage])
|
|
249
292
|
|
|
250
|
-
const clearCapturePendingTimeout = React.useCallback(() => {
|
|
251
|
-
if (capturePendingTimeoutRef.current) {
|
|
252
|
-
clearTimeout(capturePendingTimeoutRef.current)
|
|
253
|
-
capturePendingTimeoutRef.current = null
|
|
254
|
-
}
|
|
255
|
-
}, [])
|
|
256
|
-
|
|
257
293
|
const updateCapturePending = React.useCallback((nextValue: boolean) => {
|
|
258
294
|
capturePendingRef.current = nextValue
|
|
259
295
|
setIsCapturePending(nextValue)
|
|
260
|
-
|
|
261
|
-
if (!nextValue) {
|
|
262
|
-
clearCapturePendingTimeout()
|
|
263
|
-
}
|
|
264
|
-
}, [clearCapturePendingTimeout])
|
|
265
|
-
|
|
266
|
-
React.useEffect(() => {
|
|
267
|
-
return () => {
|
|
268
|
-
clearCapturePendingTimeout()
|
|
269
|
-
}
|
|
270
|
-
}, [clearCapturePendingTimeout])
|
|
296
|
+
}, [])
|
|
271
297
|
|
|
272
298
|
React.useEffect(() => {
|
|
273
299
|
let isCancelled = false
|
|
@@ -331,7 +357,6 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
331
357
|
|
|
332
358
|
const handlePhotoCaptured = (event: { nativeEvent: OnPhotoCapturedEventPayload }) => {
|
|
333
359
|
console.log('CAMERA: Photo captured event:', event)
|
|
334
|
-
updateCapturePending(false)
|
|
335
360
|
const imageUri = event?.nativeEvent?.imageUri
|
|
336
361
|
const depthMapUri = event?.nativeEvent?.depthMapUri
|
|
337
362
|
const imageSize = event?.nativeEvent?.imageSize
|
|
@@ -376,6 +401,18 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
376
401
|
}
|
|
377
402
|
}
|
|
378
403
|
|
|
404
|
+
const handleCaptureStateChange = React.useCallback((event: { nativeEvent: OnCaptureStateChangeEventPayload }) => {
|
|
405
|
+
const nextValue = !!event?.nativeEvent?.isCapturing
|
|
406
|
+
console.log('CAMERA: Capture state changed:', nextValue)
|
|
407
|
+
updateCapturePending(nextValue)
|
|
408
|
+
}, [updateCapturePending])
|
|
409
|
+
|
|
410
|
+
const handleCameraError = React.useCallback((event: { nativeEvent: OnErrorEventPayload }) => {
|
|
411
|
+
const errorMessage = event?.nativeEvent?.error || 'Camera error'
|
|
412
|
+
console.log('CAMERA: Error event:', errorMessage)
|
|
413
|
+
updateCapturePending(false)
|
|
414
|
+
}, [updateCapturePending])
|
|
415
|
+
|
|
379
416
|
const triggerFocusRing = React.useCallback(
|
|
380
417
|
(x: number, y: number) => {
|
|
381
418
|
setFocusPoint({ x, y })
|
|
@@ -433,10 +470,6 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
433
470
|
|
|
434
471
|
console.log('CAMERA: Attempting to capture photo')
|
|
435
472
|
updateCapturePending(true)
|
|
436
|
-
clearCapturePendingTimeout()
|
|
437
|
-
capturePendingTimeoutRef.current = setTimeout(() => {
|
|
438
|
-
updateCapturePending(false)
|
|
439
|
-
}, 4000)
|
|
440
473
|
triggerShutterFlash() // Trigger the flash effect
|
|
441
474
|
if (cameraRef.current) {
|
|
442
475
|
try {
|
|
@@ -597,22 +630,27 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
597
630
|
|
|
598
631
|
const latestCapturedImage = capturedImages[capturedImages.length - 1]
|
|
599
632
|
const hasCapturedImages = capturedImages.length > 0
|
|
600
|
-
const shouldShowGalleryPreview = limit !== 1
|
|
633
|
+
const shouldShowGalleryPreview = limit !== 1 && !isTightLayout
|
|
601
634
|
const shouldShowDoneButton = limit !== 1
|
|
635
|
+
const shouldShowZoomSlider = isZoomAvailable && !isTightLayout
|
|
636
|
+
const visibleSideControlCount = (showFlashControl ? 1 : 0) + (showCameraSwitchControl ? 1 : 0)
|
|
602
637
|
const gallerySubtitle = `${capturedImages.length} ${capturedImages.length === 1 ? 'image' : 'images'}`
|
|
603
638
|
const rightOverlayHeight =
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
(shouldShowGalleryPreview ?
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
(shouldShowDoneButton ?
|
|
611
|
-
const rightOverlayTop = Math.max(insets.top + 96, Math.round(windowHeight * 0.5 - rightOverlayHeight / 2))
|
|
639
|
+
(visibleSideControlCount > 0
|
|
640
|
+
? sideButtonSize * visibleSideControlCount + sideButtonGap * Math.max(visibleSideControlCount - 1, 0) + sideActionGroupMarginBottom
|
|
641
|
+
: 0) +
|
|
642
|
+
(shouldShowGalleryPreview ? galleryPreviewSize + galleryPreviewMarginBottom : 0) +
|
|
643
|
+
shutterButtonSize +
|
|
644
|
+
shutterButtonMarginBottom +
|
|
645
|
+
(shouldShowDoneButton ? doneButtonHeight + doneButtonMarginBottom : 0)
|
|
646
|
+
const rightOverlayTop = Math.max(insets.top + (isTightLayout ? 64 : isPhoneSized ? 80 : 96), Math.round(windowHeight * 0.5 - rightOverlayHeight / 2))
|
|
612
647
|
const zoomSliderHeight = ZOOM_SLIDER_TRACK_LENGTH + ZOOM_SLIDER_THUMB_SIZE
|
|
613
|
-
const zoomSliderTop = Math.max(insets.top + 104, Math.round(windowHeight * 0.5 - zoomSliderHeight / 2))
|
|
648
|
+
const zoomSliderTop = Math.max(insets.top + (isPhoneSized ? 88 : 104), Math.round(windowHeight * 0.5 - zoomSliderHeight / 2))
|
|
614
649
|
|
|
615
650
|
const handleCancelPress = () => {
|
|
651
|
+
if (capturePendingRef.current) {
|
|
652
|
+
return
|
|
653
|
+
}
|
|
616
654
|
if (cameraRef.current) {
|
|
617
655
|
cameraRef.current.stopCamera()
|
|
618
656
|
}
|
|
@@ -620,7 +658,7 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
620
658
|
}
|
|
621
659
|
|
|
622
660
|
const handleDonePress = () => {
|
|
623
|
-
if (
|
|
661
|
+
if (isDoneDisabled) {
|
|
624
662
|
return
|
|
625
663
|
}
|
|
626
664
|
|
|
@@ -645,11 +683,15 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
645
683
|
<View
|
|
646
684
|
style={[
|
|
647
685
|
styles.topOverlay,
|
|
648
|
-
{ paddingTop: insets.top + 8, paddingLeft:
|
|
686
|
+
{ paddingTop: insets.top + 8, paddingLeft: topOverlayHorizontalInset + insets.left, paddingRight: topOverlayHorizontalInset + insets.right }
|
|
649
687
|
]}
|
|
650
688
|
>
|
|
651
|
-
<TouchableOpacity
|
|
652
|
-
|
|
689
|
+
<TouchableOpacity
|
|
690
|
+
style={[styles.cancelButton, { minWidth: cancelButtonMinWidth, height: cancelButtonHeight, paddingHorizontal: cancelButtonPaddingHorizontal, borderRadius: cancelButtonHeight / 2 }]}
|
|
691
|
+
hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
|
|
692
|
+
onPress={onCancel}
|
|
693
|
+
>
|
|
694
|
+
<Text style={[styles.cancelButtonText, { fontSize: cancelButtonFontSize }]}>Cancel</Text>
|
|
653
695
|
</TouchableOpacity>
|
|
654
696
|
</View>
|
|
655
697
|
|
|
@@ -687,23 +729,28 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
687
729
|
<View
|
|
688
730
|
style={[
|
|
689
731
|
styles.topOverlay,
|
|
690
|
-
{ paddingTop: insets.top + 8, paddingLeft:
|
|
732
|
+
{ paddingTop: insets.top + 8, paddingLeft: topOverlayHorizontalInset + insets.left, paddingRight: topOverlayHorizontalInset + insets.right }
|
|
691
733
|
]}
|
|
692
734
|
>
|
|
693
735
|
<TouchableOpacity
|
|
694
|
-
style={
|
|
736
|
+
style={[
|
|
737
|
+
styles.cancelButton,
|
|
738
|
+
{ minWidth: cancelButtonMinWidth, height: cancelButtonHeight, paddingHorizontal: cancelButtonPaddingHorizontal, borderRadius: cancelButtonHeight / 2 },
|
|
739
|
+
isCancelDisabled && styles.cancelButtonDisabled
|
|
740
|
+
]}
|
|
695
741
|
hitSlop={{ top: 12, bottom: 12, left: 12, right: 12 }}
|
|
696
742
|
onPress={handleCancelPress}
|
|
743
|
+
disabled={isCancelDisabled}
|
|
697
744
|
>
|
|
698
|
-
<Text style={styles.cancelButtonText}>Cancel</Text>
|
|
745
|
+
<Text style={[styles.cancelButtonText, { fontSize: cancelButtonFontSize }]}>Cancel</Text>
|
|
699
746
|
</TouchableOpacity>
|
|
700
747
|
|
|
701
748
|
{hasCapturedImages ? (
|
|
702
|
-
<View style={styles.captureCountBadge}>
|
|
703
|
-
<Text style={styles.captureCountBadgeText}>{capturedImages.length}</Text>
|
|
749
|
+
<View style={[styles.captureCountBadge, { width: captureBadgeSize, height: captureBadgeSize, borderRadius: captureBadgeSize / 2 }]}>
|
|
750
|
+
<Text style={[styles.captureCountBadgeText, { fontSize: captureBadgeFontSize }]}>{capturedImages.length}</Text>
|
|
704
751
|
</View>
|
|
705
752
|
) : (
|
|
706
|
-
<View style={styles.topOverlaySpacer} />
|
|
753
|
+
<View style={[styles.topOverlaySpacer, { width: captureBadgeSize, height: captureBadgeSize }]} />
|
|
707
754
|
)}
|
|
708
755
|
</View>
|
|
709
756
|
|
|
@@ -717,6 +764,8 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
717
764
|
onStatusChange={handleStatusChange}
|
|
718
765
|
onCamerasAvailable={handleCamerasAvailable}
|
|
719
766
|
onPhotoCaptured={handlePhotoCaptured}
|
|
767
|
+
onCaptureStateChange={handleCaptureStateChange}
|
|
768
|
+
onError={handleCameraError}
|
|
720
769
|
style={styles.camera}
|
|
721
770
|
/>
|
|
722
771
|
{focusPoint ? (
|
|
@@ -724,8 +773,11 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
724
773
|
style={[
|
|
725
774
|
styles.focusRing,
|
|
726
775
|
{
|
|
727
|
-
|
|
728
|
-
|
|
776
|
+
width: focusRingSize,
|
|
777
|
+
height: focusRingSize,
|
|
778
|
+
borderRadius: focusRingSize / 2,
|
|
779
|
+
left: focusPoint.x - focusRingSize / 2,
|
|
780
|
+
top: focusPoint.y - focusRingSize / 2,
|
|
729
781
|
opacity: focusAnim.interpolate({
|
|
730
782
|
inputRange: [0, 0.7, 1],
|
|
731
783
|
outputRange: [1, 0.8, 0]
|
|
@@ -747,62 +799,113 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
747
799
|
|
|
748
800
|
<View
|
|
749
801
|
pointerEvents="box-none"
|
|
750
|
-
style={[styles.rightOverlay, { right:
|
|
802
|
+
style={[styles.rightOverlay, { width: rightOverlayWidth, right: overlaySideInset + insets.right, top: rightOverlayTop }]}
|
|
751
803
|
>
|
|
752
|
-
|
|
753
|
-
<
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
804
|
+
{showSecondaryControls && (
|
|
805
|
+
<View style={[styles.sideActionGroup, { marginBottom: sideActionGroupMarginBottom }]}>
|
|
806
|
+
{showFlashControl && (
|
|
807
|
+
<TouchableOpacity
|
|
808
|
+
style={[
|
|
809
|
+
styles.sideButton,
|
|
810
|
+
{ width: sideButtonSize, height: sideButtonSize, borderRadius: sideButtonSize / 2 },
|
|
811
|
+
showCameraSwitchControl && { marginBottom: sideButtonGap },
|
|
812
|
+
isFlashEnabled && styles.sideButtonActive,
|
|
813
|
+
isFrontCamera && styles.sideButtonDisabled
|
|
814
|
+
]}
|
|
815
|
+
onPress={toggleFlash}
|
|
816
|
+
disabled={isFrontCamera}
|
|
817
|
+
>
|
|
818
|
+
<Text style={[styles.sideButtonText, { fontSize: sideButtonTextSize }]}>⚡</Text>
|
|
819
|
+
</TouchableOpacity>
|
|
820
|
+
)}
|
|
821
|
+
{showCameraSwitchControl && (
|
|
822
|
+
<TouchableOpacity
|
|
823
|
+
style={[styles.sideButton, { width: sideButtonSize, height: sideButtonSize, borderRadius: sideButtonSize / 2 }]}
|
|
824
|
+
onPress={toggleCamera}
|
|
825
|
+
>
|
|
826
|
+
<FlipCameraIcon size={sideButtonIconSize} color={colors.white} />
|
|
827
|
+
</TouchableOpacity>
|
|
828
|
+
)}
|
|
829
|
+
</View>
|
|
830
|
+
)}
|
|
769
831
|
|
|
770
832
|
{shouldShowGalleryPreview ? (
|
|
771
833
|
<TouchableOpacity
|
|
772
|
-
style={[
|
|
834
|
+
style={[
|
|
835
|
+
styles.galleryPreviewButton,
|
|
836
|
+
{
|
|
837
|
+
width: galleryPreviewSize,
|
|
838
|
+
height: galleryPreviewSize,
|
|
839
|
+
borderRadius: galleryPreviewBorderRadius,
|
|
840
|
+
marginBottom: galleryPreviewMarginBottom
|
|
841
|
+
},
|
|
842
|
+
!hasCapturedImages && styles.galleryPreviewButtonEmpty
|
|
843
|
+
]}
|
|
773
844
|
onPress={openGalleryModal}
|
|
774
845
|
activeOpacity={0.9}
|
|
775
846
|
>
|
|
776
847
|
{latestCapturedImage ? (
|
|
777
|
-
<Image source={{ uri: latestCapturedImage.uri }} style={styles.galleryPreviewImage} resizeMode="cover" />
|
|
848
|
+
<Image source={{ uri: latestCapturedImage.uri }} style={[styles.galleryPreviewImage, { borderRadius: Math.max(6, galleryPreviewBorderRadius - 2) }]} resizeMode="cover" />
|
|
778
849
|
) : (
|
|
779
|
-
<View style={styles.galleryPreviewPlaceholder} />
|
|
850
|
+
<View style={[styles.galleryPreviewPlaceholder, { borderRadius: Math.max(6, galleryPreviewBorderRadius - 2) }]} />
|
|
780
851
|
)}
|
|
781
852
|
{hasCapturedImages ? (
|
|
782
|
-
<View
|
|
853
|
+
<View
|
|
854
|
+
style={[
|
|
855
|
+
styles.galleryPreviewBadge,
|
|
856
|
+
{
|
|
857
|
+
right: Math.round(-8 * controlScale),
|
|
858
|
+
minWidth: galleryPreviewBadgeSize,
|
|
859
|
+
height: galleryPreviewBadgeSize,
|
|
860
|
+
borderRadius: galleryPreviewBadgeSize / 2
|
|
861
|
+
}
|
|
862
|
+
]}
|
|
863
|
+
pointerEvents="none"
|
|
864
|
+
>
|
|
783
865
|
<Text style={styles.galleryPreviewBadgeText}>{capturedImages.length}</Text>
|
|
784
866
|
</View>
|
|
785
867
|
) : null}
|
|
786
868
|
</TouchableOpacity>
|
|
787
869
|
) : null}
|
|
788
870
|
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
871
|
+
<TouchableOpacity
|
|
872
|
+
style={[
|
|
873
|
+
styles.shutterButton,
|
|
874
|
+
{ width: shutterButtonSize, height: shutterButtonSize, borderRadius: shutterButtonSize / 2, marginBottom: shutterButtonMarginBottom },
|
|
875
|
+
isShutterDisabled && styles.shutterButtonDisabled
|
|
876
|
+
]}
|
|
877
|
+
onPress={capturePhoto}
|
|
878
|
+
disabled={isShutterDisabled}
|
|
879
|
+
>
|
|
880
|
+
<View
|
|
881
|
+
style={[
|
|
882
|
+
styles.shutterButtonOuter,
|
|
883
|
+
{ width: shutterButtonSize, height: shutterButtonSize, borderRadius: shutterButtonSize / 2, borderWidth: Math.max(2, Math.round(3 * controlScale)) },
|
|
884
|
+
isShutterDisabled && styles.shutterButtonOuterDisabled
|
|
885
|
+
]}
|
|
886
|
+
/>
|
|
887
|
+
<View
|
|
888
|
+
style={[
|
|
889
|
+
styles.shutterInner,
|
|
890
|
+
{ width: shutterInnerSize, height: shutterInnerSize, borderRadius: shutterInnerSize / 2 },
|
|
891
|
+
isShutterDisabled && styles.shutterInnerDisabled
|
|
892
|
+
]}
|
|
893
|
+
/>
|
|
894
|
+
</TouchableOpacity>
|
|
796
895
|
|
|
797
896
|
{shouldShowDoneButton ? (
|
|
798
897
|
<TouchableOpacity
|
|
799
|
-
style={[
|
|
898
|
+
style={[
|
|
899
|
+
styles.doneButton,
|
|
900
|
+
{ height: doneButtonHeight, paddingHorizontal: doneButtonHorizontalPadding, borderRadius: doneButtonHeight / 2, marginBottom: doneButtonMarginBottom },
|
|
901
|
+
isDoneDisabled && styles.doneButtonDisabled
|
|
902
|
+
]}
|
|
800
903
|
onPress={handleDonePress}
|
|
801
|
-
disabled={
|
|
904
|
+
disabled={isDoneDisabled}
|
|
802
905
|
>
|
|
803
|
-
<Text style={styles.doneButtonText}>Done</Text>
|
|
804
|
-
<View style={styles.doneButtonIcon}>
|
|
805
|
-
<Icons.IconForward_WithPad size={
|
|
906
|
+
<Text style={[styles.doneButtonText, { fontSize: doneButtonTextSize }]}>Done</Text>
|
|
907
|
+
<View style={[styles.doneButtonIcon, { marginLeft: Math.max(6, Math.round(8 * controlScale)) }]}>
|
|
908
|
+
<Icons.IconForward_WithPad size={doneButtonIconSize} fill={colors.white} fillOpacity={1} />
|
|
806
909
|
</View>
|
|
807
910
|
</TouchableOpacity>
|
|
808
911
|
) : null}
|
|
@@ -816,7 +919,7 @@ const CameraModal: React.FC<CameraTestModalProps> = ({ onDone, onCancel, cameraR
|
|
|
816
919
|
</View>
|
|
817
920
|
) : null}
|
|
818
921
|
|
|
819
|
-
{
|
|
922
|
+
{shouldShowZoomSlider ? (
|
|
820
923
|
<View pointerEvents="box-none" style={[styles.zoomSliderContainer, { left: 12 + insets.left, top: zoomSliderTop }]}>
|
|
821
924
|
<View style={styles.zoomSlider}>
|
|
822
925
|
<View
|
|
@@ -969,6 +1072,9 @@ const styles = StyleSheet.create({
|
|
|
969
1072
|
alignItems: 'center',
|
|
970
1073
|
justifyContent: 'center'
|
|
971
1074
|
},
|
|
1075
|
+
cancelButtonDisabled: {
|
|
1076
|
+
opacity: 0.45
|
|
1077
|
+
},
|
|
972
1078
|
cancelButtonText: {
|
|
973
1079
|
color: colors.white,
|
|
974
1080
|
fontSize: 14,
|
|
@@ -51,12 +51,12 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
51
51
|
const [pendingPickerIndex, setPendingPickerIndex] = useState(null)
|
|
52
52
|
const [pendingCancelIndex, setPendingCancelIndex] = useState(null)
|
|
53
53
|
const [actionSheetInstanceKey, setActionSheetInstanceKey] = useState(0)
|
|
54
|
-
const [pendingCameraModalPayload, setPendingCameraModalPayload] = useState(null)
|
|
55
54
|
|
|
56
55
|
const imgArrRef = useRef([]) // temp array for holding selected images to attach, before title & desc updated
|
|
57
56
|
const imgDescArrRef = useRef([]) // temp array for holding descriptions of selected images, before saved to project
|
|
58
57
|
const imgValidArrRef = useRef([]) // temp array for holding boolean value specifying whether each image title is valid or not
|
|
59
58
|
const actionSheetRef = useRef(null)
|
|
59
|
+
const pendingCameraProcessTimeoutRef = useRef(null)
|
|
60
60
|
|
|
61
61
|
const resolvedMaxCount = useMemo(() => {
|
|
62
62
|
const parsedMaxCount = Number(maxCount)
|
|
@@ -84,6 +84,13 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
84
84
|
setActionSheetInstanceKey((prevKey) => prevKey + 1)
|
|
85
85
|
}, [])
|
|
86
86
|
|
|
87
|
+
const clearPendingCameraProcessTimeout = useCallback(() => {
|
|
88
|
+
if (pendingCameraProcessTimeoutRef.current) {
|
|
89
|
+
clearTimeout(pendingCameraProcessTimeoutRef.current)
|
|
90
|
+
pendingCameraProcessTimeoutRef.current = null
|
|
91
|
+
}
|
|
92
|
+
}, [])
|
|
93
|
+
|
|
87
94
|
const showSelectionLimitAlert = useCallback(() => {
|
|
88
95
|
const message = remainingCount <= 0
|
|
89
96
|
? `You already have the maximum of ${resolvedMaxCount} photo(s)`
|
|
@@ -240,38 +247,12 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
240
247
|
}
|
|
241
248
|
}, [callback, callbackData])
|
|
242
249
|
|
|
243
|
-
const
|
|
244
|
-
// Handle images returned from CameraModal
|
|
245
|
-
console.log('SWSI Camera modal done, images:', images)
|
|
246
|
-
|
|
247
|
-
const nextPayload =
|
|
248
|
-
images && images.length > 0 && pendingPickerIndex !== null && pendingCancelIndex !== null
|
|
249
|
-
? {
|
|
250
|
-
images,
|
|
251
|
-
pickerIndex: pendingPickerIndex,
|
|
252
|
-
cancelIndex: pendingCancelIndex
|
|
253
|
-
}
|
|
254
|
-
: null
|
|
255
|
-
|
|
256
|
-
setShowCameraModal(false)
|
|
257
|
-
resetActionSheet()
|
|
258
|
-
setPendingCameraModalPayload(nextPayload)
|
|
259
|
-
|
|
260
|
-
// Reset pending indices
|
|
261
|
-
setPendingPickerIndex(null)
|
|
262
|
-
setPendingCancelIndex(null)
|
|
263
|
-
}, [pendingCancelIndex, pendingPickerIndex, pickerDone, resetActionSheet])
|
|
264
|
-
|
|
265
|
-
const processPendingCameraModalPayload = useCallback(() => {
|
|
266
|
-
if (!pendingCameraModalPayload) {
|
|
267
|
-
return
|
|
268
|
-
}
|
|
269
|
-
|
|
250
|
+
const processCameraModalImages = useCallback((images, pickerIndex, cancelIndex) => {
|
|
270
251
|
imgArrRef.current = []
|
|
271
252
|
imgDescArrRef.current = []
|
|
272
253
|
imgValidArrRef.current = []
|
|
273
254
|
|
|
274
|
-
|
|
255
|
+
images.forEach((img) => {
|
|
275
256
|
const imageData = {
|
|
276
257
|
path: img.imageURI,
|
|
277
258
|
mime: 'image/jpeg',
|
|
@@ -288,24 +269,41 @@ const MultiImagePicker = forwardRef((props, ref) => {
|
|
|
288
269
|
imgValidArrRef.current.push(true)
|
|
289
270
|
})
|
|
290
271
|
|
|
291
|
-
const { pickerIndex, cancelIndex } = pendingCameraModalPayload
|
|
292
|
-
setPendingCameraModalPayload(null)
|
|
293
272
|
pickerDone(pickerIndex, cancelIndex, 'taken')
|
|
294
|
-
}, [
|
|
273
|
+
}, [pickerDone])
|
|
295
274
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
275
|
+
const handleCameraModalDone = useCallback(async (images = []) => {
|
|
276
|
+
// Handle images returned from CameraModal
|
|
277
|
+
console.log('SWSI Camera modal done, images:', images)
|
|
278
|
+
|
|
279
|
+
const pickerIndex = pendingPickerIndex
|
|
280
|
+
const cancelIndex = pendingCancelIndex
|
|
281
|
+
|
|
282
|
+
clearPendingCameraProcessTimeout()
|
|
283
|
+
setShowCameraModal(false)
|
|
284
|
+
resetActionSheet()
|
|
285
|
+
|
|
286
|
+
if (images && images.length > 0) {
|
|
287
|
+
if (pickerIndex !== null && cancelIndex !== null) {
|
|
288
|
+
pendingCameraProcessTimeoutRef.current = setTimeout(() => {
|
|
289
|
+
pendingCameraProcessTimeoutRef.current = null
|
|
290
|
+
processCameraModalImages(images, pickerIndex, cancelIndex)
|
|
291
|
+
}, 350)
|
|
292
|
+
} else {
|
|
293
|
+
console.log('SWSI Camera modal missing picker indices; skipping captured image handoff')
|
|
294
|
+
}
|
|
299
295
|
}
|
|
300
296
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
297
|
+
// Reset pending indices
|
|
298
|
+
setPendingPickerIndex(null)
|
|
299
|
+
setPendingCancelIndex(null)
|
|
300
|
+
}, [clearPendingCameraProcessTimeout, pendingCancelIndex, pendingPickerIndex, processCameraModalImages, resetActionSheet])
|
|
304
301
|
|
|
302
|
+
useEffect(() => {
|
|
305
303
|
return () => {
|
|
306
|
-
|
|
304
|
+
clearPendingCameraProcessTimeout()
|
|
307
305
|
}
|
|
308
|
-
}, [
|
|
306
|
+
}, [clearPendingCameraProcessTimeout])
|
|
309
307
|
|
|
310
308
|
const takeOnePicture = useCallback(async (
|
|
311
309
|
index,
|