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