Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to continuously scan by ignoring specific codes #130

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Sources/CodeScanner/CodeScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,20 @@ public enum ScanMode {
/// Keep scanning all codes until dismissed.
case continuous

/// Keep scanning all codes - except the ones from the ignored list - until dismissed.
case continuousExcept(ignoredList: Set<String>)

/// Scan only when capture button is tapped.
case manual

var isManual: Bool {
switch self {
case .manual:
return true
case .once, .oncePerCode, .continuous, .continuousExcept:
return false
}
}
}

/// A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
Expand Down Expand Up @@ -114,7 +126,7 @@ public struct CodeScannerView: UIViewControllerRepresentable {
uiViewController.updateViewController(
isTorchOn: isTorchOn,
isGalleryPresented: isGalleryPresented.wrappedValue,
isManualCapture: scanMode == .manual,
isManualCapture: scanMode.isManual,
isManualSelect: manualSelect
)
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/CodeScanner/ScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ extension CodeScannerView {
}

public func readyManualCapture() {
guard parentView.scanMode == .manual else { return }
guard parentView.scanMode.isManual else { return }
self.reset()
lastTime = Date()
}
Expand Down Expand Up @@ -465,6 +465,11 @@ extension CodeScannerView.ScannerViewController: AVCaptureMetadataOutputObjectsD
if isPastScanInterval() {
found(result)
}

case .continuousExcept(let ignoredList):
if isPastScanInterval() && !ignoredList.contains(stringValue) {
found(result)
}
}
}

Expand Down
Loading