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

Commit 7c5651c

Browse files
author
Nicolò Caruso
committed
Allow mlkit textrecognition to work in landscape mode on iOS
1 parent 27a0ef2 commit 7c5651c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/mlkit/mlkit-cameraview.ios.ts

+17
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
9797
// this orientation is how the captured image is rotated (and shown)
9898
if (this.rotateRecording()) {
9999
this.cameraView.imageOrientation = UIImageOrientation.Right;
100+
} else {
101+
if (UIDevice.currentDevice.orientation === UIDeviceOrientation.LandscapeLeft) {
102+
this.cameraView.imageOrientation = UIImageOrientation.Up;
103+
} else {
104+
this.cameraView.imageOrientation = UIImageOrientation.Down;
105+
}
100106
}
101107

102108
this.cameraView.delegate = TNSMLKitCameraViewDelegateImpl.createWithOwnerResultCallbackAndOptions(
@@ -116,6 +122,17 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
116122
this.previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.Portrait;
117123
}
118124
}
125+
126+
// this orientation is how the captured image is rotated (and shown)
127+
if (this.rotateRecording()) {
128+
this.cameraView.imageOrientation = UIImageOrientation.Right;
129+
} else {
130+
if (UIDevice.currentDevice.orientation === UIDeviceOrientation.LandscapeLeft) {
131+
this.cameraView.imageOrientation = UIImageOrientation.Up;
132+
} else {
133+
this.cameraView.imageOrientation = UIImageOrientation.Down;
134+
}
135+
}
119136
}
120137

121138
public onLayout(left: number, top: number, right: number, bottom: number): void {

src/mlkit/textrecognition/index.ios.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ios as iosUtils } from "tns-core-modules/utils/utils";
12
import { ImageSource } from "tns-core-modules/image-source";
23
import { MLKitVisionOptions } from "../";
34
import { MLKitRecognizeTextCloudOptions, MLKitRecognizeTextOnDeviceOptions, MLKitRecognizeTextResult } from "./";
@@ -25,6 +26,9 @@ export class MLKitTextRecognition extends MLKitTextRecognitionBase {
2526
}
2627

2728
protected rotateRecording(): boolean {
29+
if (iosUtils.isLandscape()) {
30+
return false;
31+
}
2832
return true;
2933
}
3034
}

0 commit comments

Comments
 (0)