Skip to content

Commit

Permalink
(barcode): Fix for missing bounds in Android react-native-camera#683 (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
blankg authored and rt2zz committed Aug 19, 2017
1 parent 02eb51d commit e3fc277
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit e3fc277

Please sign in to comment.