From e3fc27711c9336867607eefc0ed1299e0fc51749 Mon Sep 17 00:00:00 2001 From: Guy Blank Date: Sun, 20 Aug 2017 01:19:18 +0300 Subject: [PATCH] (barcode): Fix for missing bounds in Android #683 (#845) --- .../lwansbrough/RCTCamera/RCTCameraViewFinder.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraViewFinder.java b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraViewFinder.java index 75615897e..e308474d3 100644 --- a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraViewFinder.java +++ b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraViewFinder.java @@ -14,6 +14,7 @@ import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReactContext; +import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.WritableMap; import com.facebook.react.modules.core.DeviceEventManagerModule; @@ -28,6 +29,7 @@ import com.google.zxing.MultiFormatReader; import com.google.zxing.PlanarYUVLuminanceSource; import com.google.zxing.Result; +import com.google.zxing.ResultPoint; import com.google.zxing.common.HybridBinarizer; class RCTCameraViewFinder extends TextureView implements TextureView.SurfaceTextureListener, Camera.PreviewCallback { @@ -329,6 +331,18 @@ protected Void doInBackground(Void... ignored) { ReactContext reactContext = RCTCameraModule.getReactContextSingleton(); WritableMap event = Arguments.createMap(); + WritableArray resultPoints = Arguments.createArray(); + ResultPoint[] points = result.getResultPoints(); + if(points != null) { + 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); event.putString("data", result.getText()); event.putString("type", result.getBarcodeFormat().toString()); reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("CameraBarCodeReadAndroid", event);