QRCodeReader.swift icon indicating copy to clipboard operation
QRCodeReader.swift copied to clipboard

Improved match feedback

Open xinsight opened this issue 8 years ago • 5 comments

I wanted more feedback when a QR code is found. I added a system sound (a buzz) as well as highlight the bounds of the QR code. (I also added a delay property so that you can actually see the highlight before the view controller is dismissed.)

Let me know if you have any questions - thanks!

xinsight avatar Nov 29 '16 23:11 xinsight

Thank you for your contribution. I'm busy for the moment, I'll try to check your pull request tomorrow (in the worst case, this w-e).

The first feedback: why do you delay the delegate/completion block call while you can do that manually in your code? I have some use cases where I need to be reactive.

yannickl avatar Nov 30 '16 21:11 yannickl

I needed to add the delay somewhere - otherwise you can't see the highlighting before the view is dismissed. Since you provide both the view and the view controller, I wasn't sure where it would best go. I made it configurable, so the delay could be zero by default.

A question about the example app - is there a reason that the QR view controller is saved as a variable in the main view controller? I would prefer to recreate it each time - mainly so that the previous highlight area doesn't show up when the QR view controller is relaunched. (And I wouldn't have to worry about resetting the highlighted area.)

xinsight avatar Dec 01 '16 15:12 xinsight

You can add the delay in the callback methods (either with the block or either with the delegate):

func reader(_ reader: QRCodeReaderViewController, didScanResult result: QRCodeReaderResult) {
    reader.stopScanning()

    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1, execute: { [weak self] in
      self?.dismiss(animated: true) {
        // ...
      }
    })
}

Yes I use a variable because the creation of AVCaptureDevice is very expensive. So it's better to init it once.

About the highlight area each time the viewWillApear you can re-init it.

yannickl avatar Dec 01 '16 21:12 yannickl

I've moved the delay to the example app view controller.

I generally keep the Example app as simple as possible - so storing the QR view controller instance in the presenting controller feels like an unnecessary optimization. Anyways, I've left it as is, and added a workaround to remove the highlighting on subsequent view controller launches.

I also added a flag to enable/disable the highlighting.

xinsight avatar Dec 02 '16 17:12 xinsight

Hi guys any news on integration this PR?

hixfield avatar Jul 28 '18 08:07 hixfield