1
1
import { ImageSource , Utils } from '@nativescript/core' ;
2
- import { BarcodeFormats , barcodeFormatsProperty , CameraPosition , cameraPositionProperty , DetectionType , detectionTypeProperty , faceDetectionMinFaceSizeProperty , faceDetectionPerformanceModeProperty , faceDetectionTrackingEnabledProperty , imageLabelerConfidenceThresholdProperty , MLKitViewBase , objectDetectionClassifyProperty , objectDetectionMultipleProperty , pauseProperty , processEveryNthFrameProperty , torchOnProperty } from './common' ;
2
+ import { BarcodeFormats , barcodeFormatsProperty , CameraPosition , cameraPositionProperty , DetectionType , detectionTypeProperty , faceDetectionMinFaceSizeProperty , faceDetectionPerformanceModeProperty , faceDetectionTrackingEnabledProperty , imageLabelerConfidenceThresholdProperty , MLKitViewBase , objectDetectionClassifyProperty , objectDetectionMultipleProperty , pauseProperty , processEveryNthFrameProperty , torchOnProperty , aspectRatioProperty } from './common' ;
3
3
import '@nativescript/core' ;
4
4
import lazy from '@nativescript/core/utils/lazy' ;
5
5
import { DetectionEvent , StillImageDetectionOptions } from '.' ;
@@ -17,6 +17,18 @@ export { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionP
17
17
18
18
declare const TNSMLKitHelper , TNSMLKitHelperCameraPosition ;
19
19
20
+ function getGravity ( value ) {
21
+ switch ( value ) {
22
+ case 'fill' :
23
+ return AVLayerVideoGravityResize ;
24
+ case 'aspectFill' :
25
+ return AVLayerVideoGravityResizeAspectFill ;
26
+ case 'aspect' :
27
+ return AVLayerVideoGravityResizeAspect ;
28
+ }
29
+ return null ;
30
+ }
31
+
20
32
export class MLKitView extends MLKitViewBase {
21
33
#device: AVCaptureDevice ;
22
34
#preview: AVCaptureVideoPreviewLayer ;
@@ -68,7 +80,7 @@ export class MLKitView extends MLKitViewBase {
68
80
createNativeView ( ) {
69
81
const nativeView = UIView . new ( ) ;
70
82
this . #preview = AVCaptureVideoPreviewLayer . layerWithSession ( this . #mlkitHelper. session ) ;
71
- this . #preview. videoGravity = AVLayerVideoGravityResizeAspect ;
83
+ this . #preview. videoGravity = getGravity ( this . aspectRatio ) ?? AVLayerVideoGravityResizeAspect ;
72
84
nativeView . layer . insertSublayerAtIndex ( this . #preview, 0 ) ;
73
85
return nativeView ;
74
86
}
@@ -145,6 +157,18 @@ export class MLKitView extends MLKitViewBase {
145
157
return this . #selfieSegmentor;
146
158
}
147
159
160
+ [ aspectRatioProperty . setNative ] ( ratio ) {
161
+ if ( this . #preview) {
162
+ switch ( ratio ) {
163
+ case 'fill' :
164
+ case 'aspectFill' :
165
+ case 'aspect' :
166
+ this . #preview. videoGravity = getGravity ( ratio ) ;
167
+ break ;
168
+ }
169
+ }
170
+ }
171
+
148
172
[ cameraPositionProperty . setNative ] ( value : CameraPosition ) {
149
173
switch ( value ) {
150
174
case CameraPosition . FRONT :
0 commit comments