@@ -18,38 +18,46 @@ import {
18
18
capitalizationType ,
19
19
fromObject ,
20
20
getCurrentPage ,
21
- inputType ,
21
+ inputType
22
22
} from '@nativescript/core' ;
23
23
import { LoginOptions , MDCAlertControlerOptions , PromptOptions } from './dialogs' ;
24
24
import { isDialogOptions } from './dialogs-common' ;
25
25
26
26
export { capitalizationType , inputType } ;
27
27
28
- const UIViewAutoSizeUIViewAutoSize = ( UIView as any ) . extend ( {
28
+ @NativeClass
29
+ class UIViewAutoSizeUIViewAutoSize extends UIView {
30
+ _view : View ;
29
31
systemLayoutSizeFittingSizeWithHorizontalFittingPriorityVerticalFittingPriority ( boundsSize : CGSize ) {
32
+ const view = this . _view ;
33
+ if ( ! view ) {
34
+ return CGSizeZero ;
35
+ }
30
36
const actualWidth = Math . min ( boundsSize . width , Screen . mainScreen . widthPixels ) ;
31
37
const widthSpec = Utils . layout . makeMeasureSpec ( Utils . layout . toDevicePixels ( actualWidth ) , Utils . layout . EXACTLY ) ;
32
38
const heighthSpec = Utils . layout . makeMeasureSpec ( Utils . layout . toDevicePixels ( boundsSize . height ) , Utils . layout . UNSPECIFIED ) ;
33
- const view = this . _view as View ;
34
39
const measuredSize = View . measureChild ( null , view , widthSpec , heighthSpec ) ;
35
40
const newWidth = Utils . layout . toDevicePixels ( actualWidth ) ;
36
41
view . setMeasuredDimension ( newWidth , measuredSize . measuredHeight ) ;
37
42
const size = CGSizeMake ( Utils . layout . toDeviceIndependentPixels ( measuredSize . measuredWidth ) , Utils . layout . toDeviceIndependentPixels ( measuredSize . measuredHeight ) ) ;
38
43
return size ;
39
- } ,
44
+ }
40
45
layoutSubviews ( ) {
41
- const view = this . _view as View ;
46
+ const view = this . _view ;
47
+ if ( ! view ) {
48
+ return ;
49
+ }
42
50
const size = this . frame . size ;
43
51
View . layoutChild ( null , view , 0 , 0 , Utils . layout . toDevicePixels ( size . width ) , Utils . layout . toDevicePixels ( size . height ) ) ;
44
- } ,
45
- } ) ;
52
+ }
53
+ }
46
54
47
55
function createUIViewAutoSizeUIViewAutoSize ( view : View ) {
48
- const self = UIViewAutoSizeUIViewAutoSize . new ( ) as UIView ;
56
+ const self = UIViewAutoSizeUIViewAutoSize . new ( ) as UIViewAutoSizeUIViewAutoSize ;
49
57
view . _setupAsRootView ( { } ) ;
50
58
view . _isAddedToNativeVisualTree = true ;
51
59
view . callLoaded ( ) ;
52
- ( self as any ) . _view = view ;
60
+ self . _view = view ;
53
61
self . addSubview ( view . nativeViewProtected ) ;
54
62
( view . nativeViewProtected as UIView ) . autoresizingMask = UIViewAutoresizing . FlexibleWidth | UIViewAutoresizing . FlexibleHeight ;
55
63
return self ;
@@ -71,55 +79,36 @@ class MDCDialogPresentationControllerDelegateImpl extends NSObject {
71
79
}
72
80
}
73
81
}
74
- declare class IMDCAlertControllerImpl extends MDCAlertController {
82
+ @NativeClass
83
+ class MDCAlertControllerImpl extends MDCAlertController {
75
84
autoFocusTextField ?: TextField ;
76
- customContentView ?: View ;
77
- // _customContentViewContext?: any;
78
85
_resolveFunction ?: Function ;
79
- actions : NSArray < any > ;
80
86
_disableContentInsets : boolean ;
81
- }
82
- const MDCAlertControllerImpl = ( MDCAlertController as any ) . extend ( {
83
- viewDidAppear ( ) {
87
+ viewDidAppear ( animated : boolean ) {
88
+ super . viewDidAppear ( animated ) ;
84
89
if ( this . autoFocusTextField ) {
85
90
this . autoFocusTextField . requestFocus ( ) ;
86
91
this . view . setNeedsLayout ( ) ;
87
92
this . autoFocusTextField = null ;
88
93
}
89
- } ,
90
- traitCollectionDidChange ( previousTraitCollection : UITraitCollection ) : void {
91
- try {
92
- this . super . traitCollectionDidChange ( previousTraitCollection ) ;
93
- } catch ( err ) {
94
- console . error ( 'error' , err ) ;
95
- }
96
- } ,
97
- viewDidDisappear ( animated : boolean ) {
98
- this . super . viewDidDisappear ( animated ) ;
99
- if ( this . customContentView ) {
100
- this . customContentView . callUnloaded ( ) ;
101
- this . customContentView . _tearDownUI ( true ) ;
102
- this . customContentView . _isAddedToNativeVisualTree = false ;
103
- this . customContentView = null ;
104
- }
105
- } ,
94
+ }
106
95
viewDidLoad ( ) {
107
- this . super . viewDidLoad ( ) ;
96
+ super . viewDidLoad ( ) ;
108
97
if ( this . _disableContentInsets ) {
109
- console . log ( 'removing contentInsets' ) ;
110
98
( this . view as MDCAlertControllerView ) . contentInsets = UIEdgeInsetsZero ;
111
99
}
112
- } ,
100
+ }
113
101
viewDidUnload ( ) {
114
- this . super . viewDidUnload ( ) ;
115
- if ( this . customContentView ) {
116
- this . customContentView . callUnloaded ( ) ;
117
- this . customContentView . _tearDownUI ( true ) ;
118
- this . customContentView . _isAddedToNativeVisualTree = false ;
119
- this . customContentView = null ;
102
+ super . viewDidUnload ( ) ;
103
+ if ( this . accessoryView instanceof UIViewAutoSizeUIViewAutoSize ) {
104
+ const view = this . accessoryView . _view ;
105
+ view . callUnloaded ( ) ;
106
+ view . _tearDownUI ( true ) ;
107
+ view . _isAddedToNativeVisualTree = false ;
108
+ this . accessoryView . _view = null ;
120
109
}
121
- } ,
122
- } ) ;
110
+ }
111
+ }
123
112
124
113
function addButtonsToAlertController ( alertController : MDCAlertController , options : ConfirmOptions & MDCAlertControlerOptions , callback ?: Function , validationArgs ?: ( r ) => any ) : void {
125
114
if ( ! options ) {
@@ -165,7 +154,7 @@ function addButtonsToAlertController(alertController: MDCAlertController, option
165
154
}
166
155
167
156
function createAlertController ( options : DialogOptions & MDCAlertControlerOptions , resolve ?: Function ) {
168
- const alertController = MDCAlertControllerImpl . alloc ( ) . init ( ) as IMDCAlertControllerImpl ;
157
+ const alertController = MDCAlertControllerImpl . alloc ( ) . init ( ) as MDCAlertControllerImpl ;
169
158
alertController . mdc_adjustsFontForContentSizeCategory = true ;
170
159
171
160
if ( options . title ) {
@@ -234,14 +223,13 @@ function createAlertController(options: DialogOptions & MDCAlertControlerOptions
234
223
options . view instanceof View
235
224
? options . view
236
225
: Builder . createViewFromEntry ( {
237
- moduleName : options . view as string ,
226
+ moduleName : options . view as string
238
227
} ) ;
239
228
240
229
view . cssClasses . add ( CSSUtils . MODAL_ROOT_VIEW_CSS_CLASS ) ;
241
230
const modalRootViewCssClasses = CSSUtils . getSystemCssClasses ( ) ;
242
231
modalRootViewCssClasses . forEach ( ( c ) => view . cssClasses . add ( c ) ) ;
243
232
244
- alertController . customContentView = view ;
245
233
alertController . _resolveFunction = resolve ;
246
234
const context = options . context || { } ;
247
235
context . closeCallback = function ( ...originalArgs ) {
@@ -286,7 +274,7 @@ export function alert(arg: any): Promise<void> {
286
274
try {
287
275
const defaultOptions = {
288
276
// title: ALERT,
289
- okButtonText : DialogStrings . OK ,
277
+ okButtonText : DialogStrings . OK
290
278
} ;
291
279
const options = ! isDialogOptions ( arg ) ? Object . assign ( defaultOptions , { message : arg + '' } ) : Object . assign ( defaultOptions , arg ) ;
292
280
const alertController = createAlertController ( options , resolve ) ;
@@ -328,11 +316,11 @@ export function confirm(arg: any): Promise<boolean> {
328
316
const defaultOptions = {
329
317
// title: CONFIRM,
330
318
okButtonText : DialogStrings . OK ,
331
- cancelButtonText : DialogStrings . CANCEL ,
319
+ cancelButtonText : DialogStrings . CANCEL
332
320
} ;
333
321
const options = ! isDialogOptions ( arg )
334
322
? Object . assign ( defaultOptions , {
335
- message : arg + '' ,
323
+ message : arg + ''
336
324
} )
337
325
: Object . assign ( defaultOptions , arg ) ;
338
326
const alertController = createAlertController ( options , resolve ) ;
@@ -355,7 +343,7 @@ export function prompt(arg: any): Promise<PromptResult> {
355
343
// title: PROMPT,
356
344
okButtonText : DialogStrings . OK ,
357
345
cancelButtonText : DialogStrings . CANCEL ,
358
- inputType : inputType . text ,
346
+ inputType : inputType . text
359
347
} ;
360
348
361
349
if ( arguments . length === 1 ) {
@@ -444,7 +432,7 @@ export function login(arg: any): Promise<LoginResult> {
444
432
445
433
const defaultOptions = {
446
434
okButtonText : DialogStrings . OK ,
447
- cancelButtonText : DialogStrings . CANCEL ,
435
+ cancelButtonText : DialogStrings . CANCEL
448
436
} ;
449
437
450
438
if ( arguments . length === 1 ) {
@@ -500,7 +488,7 @@ export function login(arg: any): Promise<LoginResult> {
500
488
resolve ( {
501
489
result : r ,
502
490
userName : userNameTextField . text ,
503
- password : passwordTextField . text ,
491
+ password : passwordTextField . text
504
492
} ) ;
505
493
} ,
506
494
( r ) => ( { result : r , userName : userNameTextField . text , password : passwordTextField . text } )
@@ -557,7 +545,7 @@ export function action(): Promise<string> {
557
545
558
546
const defaultOptions = {
559
547
// title: null,
560
- cancelButtonText : DialogStrings . CANCEL ,
548
+ cancelButtonText : DialogStrings . CANCEL
561
549
} ;
562
550
563
551
if ( arguments . length === 1 ) {
0 commit comments