@supportworks/multi-imagepicker 8.0.13 → 8.0.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supportworks/multi-imagepicker",
3
- "version": "8.0.13",
3
+ "version": "8.0.14",
4
4
  "description": "Android and iOS customized multiple image picker. For react-native >= 0.60.",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -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 ZOOM_SLIDER_STEP = ZOOM_LEVELS.length > 1 ? ZOOM_SLIDER_TRACK_LENGTH / (ZOOM_LEVELS.length - 1) : 0
52
- const DEFAULT_ZOOM: ZoomLevel = '1x'
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 getTopPositionForZoom = (zoom: ZoomLevel) => {
59
- if (ZOOM_SLIDER_STEP === 0) {
60
- return 0
61
- }
62
- const index = ZOOM_LEVELS.indexOf(zoom)
63
- if (index === -1) {
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 invertedIndex = ZOOM_LEVELS.length - 1 - index
68
- return invertedIndex * ZOOM_SLIDER_STEP
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): ZoomLevel => {
72
- if (ZOOM_SLIDER_STEP === 0) {
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 normalizedIndex = Math.round(clampedPosition / ZOOM_SLIDER_STEP)
78
- const zoomIndex = ZOOM_LEVELS.length - 1 - normalizedIndex
79
- return ZOOM_LEVELS[clamp(zoomIndex, 0, ZOOM_LEVELS.length - 1)]
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<ZoomLevel>(DEFAULT_ZOOM)
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 sliderDisabled = isFrontCamera
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: ZoomLevel) => {
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 = clamp(evt.nativeEvent.locationY - ZOOM_SLIDER_THUMB_SIZE / 2, 0, ZOOM_SLIDER_TRACK_LENGTH)
357
+ const tapOffset = getZoomOffsetFromEvent(evt)
279
358
  dragStartOffset.current = tapOffset
280
359
  knobTop.setValue(tapOffset)
360
+ handleZoomChange(getZoomForTopPosition(tapOffset))
281
361
  },
282
- onPanResponderMove: (_, gestureState) => {
283
- const next = clamp(dragStartOffset.current + gestureState.dy, 0, ZOOM_SLIDER_TRACK_LENGTH)
362
+ onPanResponderMove: (evt) => {
363
+ const next = getZoomOffsetFromEvent(evt)
284
364
  knobTop.setValue(next)
365
+ handleZoomChange(getZoomForTopPosition(next))
285
366
  },
286
- onPanResponderRelease: (_, gestureState) => {
287
- const next = clamp(dragStartOffset.current + gestureState.dy, 0, ZOOM_SLIDER_TRACK_LENGTH)
288
- const nextZoom = getZoomForTopPosition(next)
289
- handleZoomChange(nextZoom)
367
+ onPanResponderRelease: (evt) => {
368
+ const next = getZoomOffsetFromEvent(evt)
369
+ handleZoomChange(getZoomForTopPosition(next))
290
370
  },
291
- onPanResponderTerminate: (_, gestureState) => {
292
- const next = clamp(dragStartOffset.current + gestureState.dy, 0, ZOOM_SLIDER_TRACK_LENGTH)
293
- const nextZoom = getZoomForTopPosition(next)
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
- <CameraView
369
- ref={cameraRef}
370
- isDepthEnabled={isDepthEnabled}
371
- zoomLevel={currentZoom}
372
- onStatusChange={handleStatusChange}
373
- onPhotoCaptured={handlePhotoCaptured}
374
- style={styles.camera}
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
- <View pointerEvents="box-none" style={[styles.zoomSliderContainer, { left: 20 + insets.left }]}>
379
- <View style={[styles.zoomSlider, sliderDisabled && styles.zoomSliderDisabled]}>
380
- <View style={styles.zoomRailContainer} {...sliderPanResponder.panHandlers}>
381
- <View style={styles.zoomRail} />
382
- <Animated.View style={[styles.zoomThumb, { top: knobTop }]}>
383
- <Text style={styles.zoomThumbText}>{currentZoom}</Text>
384
- </Animated.View>
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
- </View>
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,