Skip to content

Commit 1f55531

Browse files
authored
sync camera improvements (duckduckgo#1785)
Task/Issue URL: https://app.asana.com/0/1201493110486074/1204739930808628/f Tech Design URL: CC: Description: Doesn't stop the camera when a code is scanned. Also adds some feedback if the code is not accepted.
1 parent 98a253f commit 1f55531

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

LocalPackages/SyncUI/Sources/SyncUI/Views/Internal/QRCodeScannerView.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ struct QRCodeScannerView: UIViewRepresentable {
2424

2525
let scanningQueue: ScanningQueue
2626

27-
var onCameraUnavailable: () -> Void
27+
let onCameraUnavailable: () -> Void
28+
let onInvalidCodeScanned: () -> Void
2829

29-
init(onQRCodeScanned: @escaping (String) async -> Bool, onCameraUnavailable: @escaping () -> Void) {
30+
init(onQRCodeScanned: @escaping (String) async -> Bool, onCameraUnavailable: @escaping () -> Void, onInvalidCodeScanned: @escaping () -> Void) {
3031
scanningQueue = ScanningQueue(onQRCodeScanned)
3132
self.onCameraUnavailable = onCameraUnavailable
33+
self.onInvalidCodeScanned = onInvalidCodeScanned
3234
}
3335

3436
func makeCoordinator() -> Coordinator {
@@ -107,10 +109,10 @@ struct QRCodeScannerView: UIViewRepresentable {
107109
let code = codeObject.stringValue else { return }
108110

109111
captureCodes = false
110-
Task {
111-
if await cameraView.scanningQueue.codeScanned(code) {
112-
stop()
113-
} else {
112+
Task { @MainActor in
113+
let codeAccepted = await cameraView.scanningQueue.codeScanned(code)
114+
if !codeAccepted {
115+
cameraView.onInvalidCodeScanned()
114116
captureCodes = true
115117
}
116118
}

LocalPackages/SyncUI/Sources/SyncUI/Views/ScanOrPasteCodeView.swift

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public struct ScanOrPasteCodeView: View {
2828
self.model = model
2929
}
3030

31+
@State var isInvalidCode = false
32+
3133
@ViewBuilder
3234
func fullscreenCameraBackground() -> some View {
3335
Group {
@@ -36,6 +38,14 @@ public struct ScanOrPasteCodeView: View {
3638
return await model.codeScanned($0)
3739
} onCameraUnavailable: {
3840
model.cameraUnavailable()
41+
} onInvalidCodeScanned: {
42+
withAnimation(.linear.delay(0.0)) {
43+
isInvalidCode = true
44+
}
45+
46+
withAnimation(.linear.delay(0.2)) {
47+
isInvalidCode = false
48+
}
3949
}
4050
} else {
4151
Rectangle()
@@ -162,7 +172,7 @@ public struct ScanOrPasteCodeView: View {
162172
ForEach([0.0, 90.0, 180.0, 270.0], id: \.self) { degrees in
163173
RoundedCorner()
164174
.stroke(lineWidth: 8)
165-
.foregroundColor(.white.opacity(0.8))
175+
.foregroundColor(isInvalidCode ? .red.opacity(0.6) : .white.opacity(0.8))
166176
.rotationEffect(.degrees(degrees), anchor: .center)
167177
.frame(width: 300, height: 300)
168178
}

0 commit comments

Comments
 (0)