Skip to content

Commit 6124b72

Browse files
committed
Ability to continuously scan by ignoring specific codes
1 parent 0af227c commit 6124b72

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Sources/CodeScanner/CodeScanner.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ public enum ScanMode {
5353
/// Keep scanning all codes until dismissed.
5454
case continuous
5555

56+
/// Keep scanning all codes - except the ones from the ignored list - until dismissed.
57+
case continuousExcept(ignoredList: Set<String>)
58+
5659
/// Scan only when capture button is tapped.
5760
case manual
61+
62+
var isManual: Bool {
63+
switch self {
64+
case .manual:
65+
return true
66+
case .once, .oncePerCode, .continuous, .continuousExcept:
67+
return false
68+
}
69+
}
5870
}
5971

6072
/// A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
@@ -114,7 +126,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
114126
uiViewController.updateViewController(
115127
isTorchOn: isTorchOn,
116128
isGalleryPresented: isGalleryPresented.wrappedValue,
117-
isManualCapture: scanMode == .manual,
129+
isManualCapture: scanMode.isManual,
118130
isManualSelect: manualSelect
119131
)
120132
}

Sources/CodeScanner/ScannerViewController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ extension CodeScannerView {
400400
}
401401

402402
public func readyManualCapture() {
403-
guard parentView.scanMode == .manual else { return }
403+
guard parentView.scanMode.isManual else { return }
404404
self.reset()
405405
lastTime = Date()
406406
}
@@ -465,6 +465,11 @@ extension CodeScannerView.ScannerViewController: AVCaptureMetadataOutputObjectsD
465465
if isPastScanInterval() {
466466
found(result)
467467
}
468+
469+
case .continuousExcept(let ignoredList):
470+
if isPastScanInterval() && !ignoredList.contains(stringValue) {
471+
found(result)
472+
}
468473
}
469474
}
470475

0 commit comments

Comments
 (0)