@@ -74,26 +74,28 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
7474 application . off ( "orientationChanged" ) ; // just making sure it was off
7575 application . on ( "orientationChanged" , this . rotateOnOrientationChange . bind ( this ) ) ;
7676
77- if ( this . ios ) {
78- this . ios . layer . addSublayer ( this . previewLayer ) ;
79- }
77+ setTimeout ( ( ) => {
78+ if ( this . ios ) {
79+ this . ios . layer . addSublayer ( this . previewLayer ) ;
80+ }
8081
81- if ( ! this . pause ) {
82- this . captureSession . startRunning ( ) ;
83- }
82+ if ( ! this . pause ) {
83+ this . captureSession . startRunning ( ) ;
84+ }
8485
85- this . cameraView = TNSMLKitCameraView . alloc ( ) . initWithCaptureSession ( this . captureSession ) ;
86- this . cameraView . processEveryXFrames = this . processEveryNthFrame ;
86+ this . cameraView = TNSMLKitCameraView . alloc ( ) . initWithCaptureSession ( this . captureSession ) ;
87+ this . cameraView . processEveryXFrames = this . processEveryNthFrame ;
8788
88- // this orientation is how the captured image is rotated (and shown)
89- if ( this . rotateRecording ( ) ) {
90- this . cameraView . imageOrientation = UIImageOrientation . Right ;
91- }
89+ // this orientation is how the captured image is rotated (and shown)
90+ if ( this . rotateRecording ( ) ) {
91+ this . cameraView . imageOrientation = UIImageOrientation . Right ;
92+ }
9293
93- this . cameraView . delegate = TNSMLKitCameraViewDelegateImpl . createWithOwnerResultCallbackAndOptions (
94- new WeakRef ( this ) ,
95- data => { } ,
96- { } ) ;
94+ this . cameraView . delegate = TNSMLKitCameraViewDelegateImpl . createWithOwnerResultCallbackAndOptions (
95+ new WeakRef ( this ) ,
96+ data => { } ,
97+ { } ) ;
98+ } , 0 ) ;
9799 }
98100
99101 private rotateOnOrientationChange ( args : OrientationChangedEventData ) : void {
@@ -109,7 +111,7 @@ export abstract class MLKitCameraView extends MLKitCameraViewBase {
109111
110112 public onLayout ( left : number , top : number , right : number , bottom : number ) : void {
111113 super . onLayout ( left , top , right , bottom ) ;
112- if ( this . ios && this . canUseCamera ( ) ) {
114+ if ( this . previewLayer && this . ios && this . canUseCamera ( ) ) {
113115 this . previewLayer . frame = this . ios . layer . bounds ;
114116 }
115117 }
0 commit comments