Skip to content

Commit a0e4e0d

Browse files
committed
TNS 5 ios code refactor
1 parent 2120dfb commit a0e4e0d

File tree

1 file changed

+33
-19
lines changed

1 file changed

+33
-19
lines changed

drop-down.ios.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,21 @@ export class DropDown extends DropDownBase {
6262
private _doneButton: UIBarButtonItem;
6363
private _doneTapDelegate: TapHandler;
6464
private _accessoryViewVisible: boolean;
65+
66+
public createNativeView() {
67+
const dropDown = TNSDropDownLabel.initWithOwner(new WeakRef(this));
6568

66-
constructor() {
67-
super();
69+
dropDown.userInteractionEnabled = true;
6870

69-
const applicationFrame = utils.ios.getter(UIScreen, UIScreen.mainScreen).applicationFrame;
71+
return dropDown;
72+
}
7073

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+
7380
this._listPicker = UIPickerView.alloc().init();
7481

7582
this._dropDownDelegate = DropDownListPickerDelegateImpl.initWithOwner(new WeakRef(this));
@@ -86,16 +93,29 @@ export class DropDown extends DropDownBase {
8693
nsArray.addObject(this._flexToolbarSpace);
8794
nsArray.addObject(this._doneButton);
8895
this._toolbar.setItemsAnimated(nsArray, false);
96+
97+
nativeView.inputView = this._listPicker;
98+
this._accessoryViewVisible = true;
99+
this._showHideAccessoryView();
89100
}
90101

91102
public disposeNativeView() {
92103
this._doneTapDelegate = null;
93104
this._dropDownDelegate = null;
94105
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();
95115
}
96116

97117
get ios(): TNSDropDownLabel {
98-
return this.nativeView;
118+
return this.nativeViewProtected;
99119
}
100120

101121
get accessoryViewVisible(): boolean {
@@ -111,25 +131,19 @@ export class DropDown extends DropDownBase {
111131

112132
this._listPicker.delegate = this._dropDownDelegate;
113133
this._listPicker.dataSource = this._dropDownDataSource;
114-
115-
this.ios.inputView = this._listPicker;
116-
this._showHideAccessoryView();
117134
}
118135

119136
public onUnloaded() {
120137
this._listPicker.delegate = null;
121138
this._listPicker.dataSource = null;
122139

123-
this.ios.inputView = null;
124-
this.ios.inputAccessoryView = null;
125-
126140
super.onUnloaded();
127141
}
128142

129143
public open() {
130144
if (this.isEnabled) {
131145
this.ios.becomeFirstResponder();
132-
}
146+
}
133147
}
134148

135149
public close() {
@@ -152,7 +166,7 @@ export class DropDown extends DropDownBase {
152166
// HACK to fix #178
153167
setTimeout(() => {
154168
this._listPicker.selectRowInComponentAnimated(value, 0, true);
155-
}, 1);
169+
}, 1);
156170
}
157171

158172
this.ios.setText(this._getItemAsString(value));
@@ -190,7 +204,7 @@ export class DropDown extends DropDownBase {
190204
if (!value) {
191205
return;
192206
}
193-
207+
194208
const color = value instanceof Color ? value.ios : value;
195209

196210
this.nativeView.backgroundColor = color;
@@ -318,7 +332,7 @@ class DropDownListPickerDelegateImpl extends NSObject implements UIPickerViewDel
318332
const owner = this._owner.get();
319333
const style = owner.style;
320334
const label = TNSLabel.alloc().init();
321-
335+
322336
label.text = owner._getItemAsString(row);
323337

324338
// Copy Styles
@@ -485,14 +499,14 @@ class TNSDropDownLabel extends TNSLabel {
485499
}
486500

487501
@ObjCMethod()
488-
public tap( @ObjCParam(UITapGestureRecognizer) sender: UITapGestureRecognizer) {
502+
public tap(@ObjCParam(UITapGestureRecognizer) sender: UITapGestureRecognizer) {
489503
if (sender.state === UIGestureRecognizerState.Ended) {
490504
const owner = this._owner.get();
491505

492506
if (owner.isEnabled) {
493507
this.becomeFirstResponder();
494-
}
495-
}
508+
}
509+
}
496510
}
497511

498512
private _refreshColor() {

0 commit comments

Comments
 (0)