From 6939734ba3024bbc7f91d6d55aeb2495f157e732 Mon Sep 17 00:00:00 2001 From: Simon Ermler Date: Mon, 26 Mar 2018 23:15:59 +0200 Subject: [PATCH] add bounds to barcodeReadEvent --- .../camera/events/BarCodeReadEvent.java | 12 +++++++++++- ios/RN/RNCamera.m | 14 ++++++++++++-- types/index.d.ts | 7 ++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/org/reactnative/camera/events/BarCodeReadEvent.java b/android/src/main/java/org/reactnative/camera/events/BarCodeReadEvent.java index 9b090f8..7d33349 100644 --- a/android/src/main/java/org/reactnative/camera/events/BarCodeReadEvent.java +++ b/android/src/main/java/org/reactnative/camera/events/BarCodeReadEvent.java @@ -4,10 +4,12 @@ import android.support.v4.util.Pools; import org.reactnative.camera.CameraViewManager; import com.facebook.react.bridge.Arguments; +import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.RCTEventEmitter; import com.google.zxing.Result; +import com.google.zxing.ResultPoint; import java.util.Date; @@ -62,7 +64,15 @@ public class BarCodeReadEvent extends Event { event.putInt("target", getViewTag()); event.putString("data", mBarCode.getText()); event.putString("type", mBarCode.getBarcodeFormat().toString()); - + WritableArray resultPoints = Arguments.createArray(); + ResultPoint[] points = mBarCode.getResultPoints(); + for (ResultPoint point: points) { + WritableMap newPoint = Arguments.createMap(); + newPoint.putString("x", String.valueOf(point.getX())); + newPoint.putString("y", String.valueOf(point.getY())); + resultPoints.pushMap(newPoint); + } + event.putArray("bounds",resultPoints); return event; } } diff --git a/ios/RN/RNCamera.m b/ios/RN/RNCamera.m index ae9b790..a0037eb 100644 --- a/ios/RN/RNCamera.m +++ b/ios/RN/RNCamera.m @@ -702,10 +702,20 @@ static NSDictionary *defaultFaceDetectorOptions = nil; AVMetadataMachineReadableCodeObject *codeMetadata = (AVMetadataMachineReadableCodeObject *) metadata; for (id barcodeType in self.barCodeTypes) { if ([metadata.type isEqualToString:barcodeType]) { - + AVMetadataMachineReadableCodeObject *transformed = (AVMetadataMachineReadableCodeObject *)[_previewLayer transformedMetadataObjectForMetadataObject:metadata]; NSDictionary *event = @{ @"type" : codeMetadata.type, - @"data" : codeMetadata.stringValue + @"data" : codeMetadata.stringValue, + @"bounds": @{ + @"origin": @{ + @"x": [NSString stringWithFormat:@"%f", transformed.bounds.origin.x], + @"y": [NSString stringWithFormat:@"%f", transformed.bounds.origin.y] + }, + @"size": @{ + @"height": [NSString stringWithFormat:@"%f", transformed.bounds.size.height], + @"width": [NSString stringWithFormat:@"%f", transformed.bounds.size.width] + } + } }; [self onCodeRead:event]; diff --git a/types/index.d.ts b/types/index.d.ts index b1b6b4c..ed7507b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -57,10 +57,11 @@ export interface RNCameraProps { // -- BARCODE PROPS barCodeTypes?: Array; onBarCodeRead?(event: { - data: string - type: keyof BarCodeType + data: string, + type: keyof BarCodeType, + bounds:[{x:string,y:string}]|{origin:{x:string,y:string},size:{height:string,width:string}} }): void; - + // -- FACE DETECTION PROPS onFacesDetected?(response: { faces: Face[] }): void;