@@ -62,14 +62,21 @@ export class DropDown extends DropDownBase {
62
62
private _doneButton : UIBarButtonItem ;
63
63
private _doneTapDelegate : TapHandler ;
64
64
private _accessoryViewVisible : boolean ;
65
+
66
+ public createNativeView ( ) {
67
+ const dropDown = TNSDropDownLabel . initWithOwner ( new WeakRef ( this ) ) ;
65
68
66
- constructor ( ) {
67
- super ( ) ;
69
+ dropDown . userInteractionEnabled = true ;
68
70
69
- const applicationFrame = utils . ios . getter ( UIScreen , UIScreen . mainScreen ) . applicationFrame ;
71
+ return dropDown ;
72
+ }
70
73
71
- this . nativeView = TNSDropDownLabel . initWithOwner ( new WeakRef ( this ) ) ;
72
- this . nativeView . userInteractionEnabled = true ;
74
+ public initNativeView ( ) {
75
+ super . initNativeView ( ) ;
76
+
77
+ const nativeView : TNSDropDownLabel = this . nativeViewProtected ;
78
+ const applicationFrame = utils . ios . getter ( UIScreen , UIScreen . mainScreen ) . applicationFrame ;
79
+
73
80
this . _listPicker = UIPickerView . alloc ( ) . init ( ) ;
74
81
75
82
this . _dropDownDelegate = DropDownListPickerDelegateImpl . initWithOwner ( new WeakRef ( this ) ) ;
@@ -86,16 +93,29 @@ export class DropDown extends DropDownBase {
86
93
nsArray . addObject ( this . _flexToolbarSpace ) ;
87
94
nsArray . addObject ( this . _doneButton ) ;
88
95
this . _toolbar . setItemsAnimated ( nsArray , false ) ;
96
+
97
+ nativeView . inputView = this . _listPicker ;
98
+ this . _accessoryViewVisible = true ;
99
+ this . _showHideAccessoryView ( ) ;
89
100
}
90
101
91
102
public disposeNativeView ( ) {
92
103
this . _doneTapDelegate = null ;
93
104
this . _dropDownDelegate = null ;
94
105
this . _dropDownDataSource = null ;
106
+
107
+ this . ios . inputView = null ;
108
+ this . ios . inputAccessoryView = null ;
109
+
110
+ this . _listPicker = null ;
111
+ this . _toolbar = null ;
112
+ this . _doneButton = null ;
113
+
114
+ super . disposeNativeView ( ) ;
95
115
}
96
116
97
117
get ios ( ) : TNSDropDownLabel {
98
- return this . nativeView ;
118
+ return this . nativeViewProtected ;
99
119
}
100
120
101
121
get accessoryViewVisible ( ) : boolean {
@@ -111,25 +131,19 @@ export class DropDown extends DropDownBase {
111
131
112
132
this . _listPicker . delegate = this . _dropDownDelegate ;
113
133
this . _listPicker . dataSource = this . _dropDownDataSource ;
114
-
115
- this . ios . inputView = this . _listPicker ;
116
- this . _showHideAccessoryView ( ) ;
117
134
}
118
135
119
136
public onUnloaded ( ) {
120
137
this . _listPicker . delegate = null ;
121
138
this . _listPicker . dataSource = null ;
122
139
123
- this . ios . inputView = null ;
124
- this . ios . inputAccessoryView = null ;
125
-
126
140
super . onUnloaded ( ) ;
127
141
}
128
142
129
143
public open ( ) {
130
144
if ( this . isEnabled ) {
131
145
this . ios . becomeFirstResponder ( ) ;
132
- }
146
+ }
133
147
}
134
148
135
149
public close ( ) {
@@ -152,7 +166,7 @@ export class DropDown extends DropDownBase {
152
166
// HACK to fix #178
153
167
setTimeout ( ( ) => {
154
168
this . _listPicker . selectRowInComponentAnimated ( value , 0 , true ) ;
155
- } , 1 ) ;
169
+ } , 1 ) ;
156
170
}
157
171
158
172
this . ios . setText ( this . _getItemAsString ( value ) ) ;
@@ -190,7 +204,7 @@ export class DropDown extends DropDownBase {
190
204
if ( ! value ) {
191
205
return ;
192
206
}
193
-
207
+
194
208
const color = value instanceof Color ? value . ios : value ;
195
209
196
210
this . nativeView . backgroundColor = color ;
@@ -318,7 +332,7 @@ class DropDownListPickerDelegateImpl extends NSObject implements UIPickerViewDel
318
332
const owner = this . _owner . get ( ) ;
319
333
const style = owner . style ;
320
334
const label = TNSLabel . alloc ( ) . init ( ) ;
321
-
335
+
322
336
label . text = owner . _getItemAsString ( row ) ;
323
337
324
338
// Copy Styles
@@ -485,14 +499,14 @@ class TNSDropDownLabel extends TNSLabel {
485
499
}
486
500
487
501
@ObjCMethod ( )
488
- public tap ( @ObjCParam ( UITapGestureRecognizer ) sender : UITapGestureRecognizer ) {
502
+ public tap ( @ObjCParam ( UITapGestureRecognizer ) sender : UITapGestureRecognizer ) {
489
503
if ( sender . state === UIGestureRecognizerState . Ended ) {
490
504
const owner = this . _owner . get ( ) ;
491
505
492
506
if ( owner . isEnabled ) {
493
507
this . becomeFirstResponder ( ) ;
494
- }
495
- }
508
+ }
509
+ }
496
510
}
497
511
498
512
private _refreshColor ( ) {
0 commit comments