capacitor-community / capacitor-community/camera-preview
Support for barcode reading
- Dominant language
- Java
- Stars
- 227
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Add support for handling barcode/QR detection
**Describe the solution you'd like**
An additional configuration option to enable code detection.
```javascript
const cameraPreviewOptions: CameraPreviewOptions = {
codeDetection: true
};
CameraPreview.start(cameraPreviewOptions);
```
```javascript
CameraPreview.addListener('codeReceived', (codeInfo: any) => {
console.log('barcode info');
});
```
**Describe alternatives you've considered**
There's a [barcode scanner rep](https://github.com/capacitor-community/barcode-scanner)o in this org by @tafelnl which is great but it lacks some features and has a reasonable overlap. I'm happy to create a PR for the iOS side of this but it'd be good to get some thoughts on whether it should be added/merged in to here at all before I do.
**Additional context**
I had a quick look at the code and it looks like the changes required would be minimal for iOS.
**iOS change summary**
Change the configureOutput function to add the `AVCaptureMetadataOutput`. Something like
```swift
self.metadataOutput = AVCaptureMetadataOutput()
self.metadataOutput!.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
if captureSession.canAddOutput(self.metadataOutput!) {
captureSession.addOutput(self.metadataOutput!)
self.metadataOutput!.metadataObjectTypes = self.metadataOutput?.availableMetadataObjectTypes
}
```
Add the metadataOutput handle
```swift
extension CameraController: AVCaptureMetadataOutputObjectsDelegate {
public func metadataOutput(_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
// code to return a generic object
}
```
And add either a callback or trigger an event using `call.resolve` or `self.bridge.triggerJSEvent`
Contributor guide
Assessment
This issue has not been assessed yet.