Fixed issue where Android camera would crash the application if the user attempted to capture too many pictures in a short timeframe. (#553)

This commit is contained in:
Rob Stemen 2017-01-22 21:33:17 -06:00 committed by Zack Story
parent d116d52442
commit 12afd8443a
1 changed files with 15 additions and 2 deletions

View File

@ -87,6 +87,7 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
private Camera mCamera = null; private Camera mCamera = null;
private Promise mRecordingPromise = null; private Promise mRecordingPromise = null;
private ReadableMap mRecordingOptions; private ReadableMap mRecordingOptions;
private Boolean mSafeToCapture = true;
public RCTCameraModule(ReactApplicationContext reactContext) { public RCTCameraModule(ReactApplicationContext reactContext) {
super(reactContext); super(reactContext);
@ -657,7 +658,8 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
RCTCamera.getInstance().adjustCameraRotationToDeviceOrientation(options.getInt("type"), deviceOrientation); RCTCamera.getInstance().adjustCameraRotationToDeviceOrientation(options.getInt("type"), deviceOrientation);
camera.setPreviewCallback(null); camera.setPreviewCallback(null);
camera.takePicture(null, null, new Camera.PictureCallback() {
Camera.PictureCallback captureCallback = new Camera.PictureCallback() {
@Override @Override
public void onPictureTaken(byte[] data, Camera camera) { public void onPictureTaken(byte[] data, Camera camera) {
@ -734,8 +736,19 @@ public class RCTCameraModule extends ReactContextBaseJavaModule
break; break;
} }
} }
mSafeToCapture = true;
} }
}); };
if(mSafeToCapture) {
try {
camera.takePicture(null, null, captureCallback);
mSafeToCapture = false;
} catch(RuntimeException ex) {
Log.e(TAG, "Couldn't capture photo.", ex);
}
}
} }
@ReactMethod @ReactMethod