Merge pull request #1201 from helloagain-dev/fix-multiple-start

Fixes that Camera is started multiple times
This commit is contained in:
Sibelius Seraphini 2018-02-01 15:39:24 -02:00 committed by GitHub
commit ec8027138e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -43,12 +43,16 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
public class RNCameraView extends CameraView implements LifecycleEventListener, BarCodeScannerAsyncTaskDelegate, FaceDetectorAsyncTaskDelegate {
private ThemedReactContext mThemedReactContext;
private Queue<Promise> mPictureTakenPromises = new ConcurrentLinkedQueue<>();
private Map<Promise, ReadableMap> mPictureTakenOptions = new ConcurrentHashMap<>();
private Map<Promise, File> mPictureTakenDirectories = new ConcurrentHashMap<>();
private Promise mVideoRecordedPromise;
private List<String> mBarCodeTypes = null;
private boolean mIsPaused = false;
private boolean mIsNew = true;
// Concurrency lock for scanners to avoid flooding the runtime
public volatile boolean barCodeScannerTaskLock = false;
public volatile boolean faceDetectorTaskLock = false;
@ -65,6 +69,7 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
public RNCameraView(ThemedReactContext themedReactContext) {
super(themedReactContext);
initBarcodeReader();
mThemedReactContext = themedReactContext;
mFaceDetector = new RNFaceDetector(themedReactContext);
setupFaceDetector();
themedReactContext.addLifecycleEventListener(this);
@ -286,9 +291,13 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
@Override
public void onHostResume() {
if (hasCameraPermissions()) {
if ((mIsPaused && !isCameraOpened()) || mIsNew) {
mIsPaused = false;
mIsNew = false;
if (!Build.FINGERPRINT.contains("generic")) {
start();
}
}
} else {
WritableMap error = Arguments.createMap();
error.putString("message", "Camera permissions not granted - component could not be rendered.");
@ -298,8 +307,11 @@ public class RNCameraView extends CameraView implements LifecycleEventListener,
@Override
public void onHostPause() {
if (!mIsPaused && isCameraOpened()) {
mIsPaused = true;
stop();
}
}
@Override
public void onHostDestroy() {