Skip to content

Commit 30345c6

Browse files
committed
Small change.
1 parent 579303e commit 30345c6

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ You can provide a variety of extra customization options to `CodeScannerView` in
3232

3333
- `scanMode` can be `.once` to scan a single code, `.oncePerCode` to scan many codes but only trigger finding each unique code once, and `.continuous` will keep finding codes until you dismiss the scanner. Default: `.once`.
3434
- `scanInterval` controls how fast individual codes should be scanned (in seconds) when running in `.continuous` scan mode.
35+
- `zoomFactor` controls zoom of used capture device. By default it is nil to not interfere with videoCaptureDevice.
3536
- `showViewfinder` determines whether to show a box-like viewfinder over the UI. Default: false.
3637
- `simulatedData` allows you to provide some test data to use in Simulator, when real scanning isn’t available. Default: an empty string.
3738
- `shouldVibrateOnSuccess` allows you to determine whether device should vibrate when a code is found. Default: true.

Sources/CodeScanner/CodeScanner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
8181
public let scanMode: ScanMode
8282
public let manualSelect: Bool
8383
public let scanInterval: Double
84-
public let zoomFactor: CGFloat
84+
public let zoomFactor: CGFloat?
8585
public let showViewfinder: Bool
8686
public let useViewfinderAsRectOfInterest: Bool
8787
public let requiresPhotoOutput: Bool
@@ -99,7 +99,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
9999
scanMode: ScanMode = .once,
100100
manualSelect: Bool = false,
101101
scanInterval: Double = 2.0,
102-
zoomFactor: CGFloat = 1,
102+
zoomFactor: CGFloat? = nil,
103103
showViewfinder: Bool = false,
104104
useViewfinderAsRectOfInterest: Bool = false,
105105
requiresPhotoOutput: Bool = true,

Sources/CodeScanner/ScannerViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ extension CodeScannerView {
401401
}
402402
#endif
403403

404-
func updateViewController(isTorchOn: Bool, zoomFactor: CGFloat, isGalleryPresented: Bool, isManualCapture: Bool, isManualSelect: Bool) {
404+
func updateViewController(isTorchOn: Bool, zoomFactor: CGFloat?, isGalleryPresented: Bool, isManualCapture: Bool, isManualSelect: Bool) {
405405
guard let videoCaptureDevice = parentView.videoCaptureDevice ?? fallbackVideoCaptureDevice else {
406406
return
407407
}
@@ -415,7 +415,7 @@ extension CodeScannerView {
415415
showManualSelectButton(isManualSelect)
416416
#endif
417417

418-
let needsZoomUpdate = videoCaptureDevice.videoZoomFactor != zoomFactor
418+
let needsZoomUpdate = zoomFactor != nil && videoCaptureDevice.videoZoomFactor != zoomFactor
419419

420420
guard videoCaptureDevice.hasTorch || needsZoomUpdate else { return }
421421

@@ -425,7 +425,7 @@ extension CodeScannerView {
425425
videoCaptureDevice.torchMode = isTorchOn ? .on : .off
426426
}
427427

428-
if needsZoomUpdate {
428+
if needsZoomUpdate, let zoomFactor {
429429
let newFactor = max(
430430
videoCaptureDevice.minAvailableVideoZoomFactor,
431431
min(videoCaptureDevice.maxAvailableVideoZoomFactor, zoomFactor)

0 commit comments

Comments
 (0)