Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 384ac10

Browse files
committed
Added application resum camera handling.
1 parent 9e090fd commit 384ac10

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/mlkit/mlkit-cameraview.android.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
5353
}
5454

5555
createNativeView(): Object {
56+
console.log("lolik1");
5657
let nativeView = super.createNativeView();
5758

5859
if (this.hasCamera()) {
@@ -90,6 +91,15 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
9091
return nativeView;
9192
}
9293

94+
initNativeView(): void {
95+
console.log("initing view from init view");
96+
application.on("resume", arg => {
97+
console.log("resumed from death.");
98+
this.runCamera();
99+
} );
100+
super.initNativeView();
101+
}
102+
93103
private hasCamera() {
94104
return !!utils.ad
95105
.getApplicationContext()
@@ -101,11 +111,16 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
101111
// if (this.preferFrontCamera) {
102112
// this._reader.switchDeviceInput();
103113
// }
114+
console.log("initing view");
104115

105116
this.surfaceView = new android.view.SurfaceView(utils.ad.getApplicationContext());
106117
nativeView.addView(this.surfaceView);
107118

108119
// Note that surfaceview callbacks didn't seem to work, so using a good old timeout (https://github.com/firebase/quickstart-android/blob/0f4c86877fc5f771cac95797dffa8bd026dd9dc7/mlkit/app/src/main/java/com/google/firebase/samples/apps/mlkit/CameraSourcePreview.java#L47)
120+
this.runCamera();
121+
}
122+
123+
private runCamera(): void {
109124
setTimeout(() => {
110125
const surfaceHolder = this.surfaceView.getHolder();
111126
const cameraFacingRequested = android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK;
@@ -232,7 +247,7 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
232247
return new com.google.android.gms.tasks.OnFailureListener({
233248
onFailure: exception => console.log(exception.getMessage())
234249
});
235-
};
250+
}
236251

237252
private generateValidPreviewSizeList(camera): Array<SizePair> {
238253
let parameters = camera.getParameters();

0 commit comments

Comments
 (0)