From 780a6c70c95de269bc37c239eec10c88a688432a Mon Sep 17 00:00:00 2001 From: Lee Packham Date: Sat, 23 Sep 2017 23:17:54 +0100 Subject: [PATCH] Disallow capture when Camera is null (Android) If a user of the library called `capture` too early then it tries to get the device orientation from the RCTCamera instance... which doesn't yet exist. Instead of adding anything clever in the library, just call promise.reject() so that the host application can decide what to do with this issue (probably wait, retry in a bit). This mainly effects slower Android devices where the camera can take a long time to initialize. --- .../main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java index 9247b6b..1c119d5 100644 --- a/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java +++ b/android/src/main/java/com/lwansbrough/RCTCamera/RCTCameraModule.java @@ -486,6 +486,11 @@ public class RCTCameraModule extends ReactContextBaseJavaModule @ReactMethod public void capture(final ReadableMap options, final Promise promise) { + if (RCTCamera.getInstance() == null) { + promise.reject("Camera is not ready yet."); + return; + } + int orientation = options.hasKey("orientation") ? options.getInt("orientation") : RCTCamera.getInstance().getOrientation(); if (orientation == RCT_CAMERA_ORIENTATION_AUTO) { _sensorOrientationChecker.onResume();