CarBode-Barcode-Scanner-For-SwiftUI icon indicating copy to clipboard operation
CarBode-Barcode-Scanner-For-SwiftUI copied to clipboard

Scanner instance persist in hierarchy even when pop VC from navigation

Open asar1 opened this issue 3 years ago • 0 comments

After getting back from this screen, Scanner still scanning in background

CBScanner(
                    supportBarcode: .constant(supportedCodeTypes()),
                    torchLightIsOn: $torchIsOn,
                    scanInterval: .constant(3.0)
                ){
                    print("BarCodeType =",$0.type.rawValue, "Value =",$0.value)
                    self.codeString = $0.value
                    self.vm.barcodeValue = self.codeString
                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
                        playSound()
                        self.result = GeneralResult.success
                        self.pushed = false
                    }
                }
                onDraw: {
                    print("Preview View Size = \($0.cameraPreviewView.bounds)")
                    print("Barcode Corners = \($0.corners)")
                    
                    //line width
                    let lineWidth = 2
                    
                    //line color
                    let lineColor = UIColor.red
                    
                    //Fill color with opacity
                    //You also can use UIColor.clear if you don't want to draw fill color
                    let fillColor = UIColor(red: 0, green: 1, blue: 0.2, alpha: 0.4)
                    
                    //Draw box
                    $0.draw(lineWidth: CGFloat(lineWidth), lineColor: lineColor, fillColor: fillColor)
                }
                .border(Color.black, width: 10)
                .cornerRadius(8)
                .padding()
                
                Image("frame")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: screenWidth / 2)
                
                VStack {
                    HStack {
                        Spacer()
                        ZStack {
                            Circle()
                                .fill()
                                .frame(width: 50, height: 50)
                                .foregroundColor(Color.gray.opacity(0.8))
                                .onTapGesture {
                                    self.torchIsOn.toggle()
                                    userDefaults.setValue(self.torchIsOn, forKey: Defaults.isTorchOn)
                                    userDefaults.synchronize()
                                }
                            Image(systemName: torchIsOn ? "lightbulb.fill" : "lightbulb")
                                .resizable()
                                .aspectRatio(contentMode: .fit)
                                .frame(width: 35, height: 35)
                                .foregroundColor(.white)
                                .allowsHitTesting(false)
                        }
                        .padding([.trailing, .top], 35)
                    }
                    Spacer()
                }

asar1 avatar Nov 07 '21 09:11 asar1