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

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mlkit textrecognition to work in landscape mode on iOS
Browse files Browse the repository at this point in the history
Nicolò Caruso committed Mar 20, 2020
1 parent 27a0ef2 commit 1671a53
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/mlkit/mlkit-cameraview.ios.ts
Original file line number Diff line number Diff line change
@@ -97,6 +97,12 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
// this orientation is how the captured image is rotated (and shown)
if (this.rotateRecording()) {
this.cameraView.imageOrientation = UIImageOrientation.Right;
} else {
if (UIDevice.currentDevice.orientation === AVCaptureVideoOrientation.LandscapeLeft) {
this.cameraView.imageOrientation = UIImageOrientation.Up;
} else {
this.cameraView.imageOrientation = UIImageOrientation.Down;
}
}

this.cameraView.delegate = TNSMLKitCameraViewDelegateImpl.createWithOwnerResultCallbackAndOptions(
@@ -116,6 +122,17 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
this.previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.Portrait;
}
}

// this orientation is how the captured image is rotated (and shown)
if (this.rotateRecording()) {
this.cameraView.imageOrientation = UIImageOrientation.Right;
} else {
if (UIDevice.currentDevice.orientation === AVCaptureVideoOrientation.LandscapeLeft) {
this.cameraView.imageOrientation = UIImageOrientation.Up;
} else {
this.cameraView.imageOrientation = UIImageOrientation.Down;
}
}
}

public onLayout(left: number, top: number, right: number, bottom: number): void {
4 changes: 4 additions & 0 deletions src/mlkit/textrecognition/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ios as iosUtils } from "tns-core-modules/utils/utils";
import { ImageSource } from "tns-core-modules/image-source";
import { MLKitVisionOptions } from "../";
import { MLKitRecognizeTextCloudOptions, MLKitRecognizeTextOnDeviceOptions, MLKitRecognizeTextResult } from "./";
@@ -25,6 +26,9 @@ export class MLKitTextRecognition extends MLKitTextRecognitionBase {
}

protected rotateRecording(): boolean {
if (iosUtils.isLandscape()) {
return false;
}
return true;
}
}

0 comments on commit 1671a53

Please sign in to comment.