1 | import { ListPickerBase, selectedIndexProperty, itemsProperty } from './list-picker-common';
|
2 | import { Color } from '../../color';
|
3 | import { colorProperty } from '../styling/style-properties';
|
4 | export * from './list-picker-common';
|
5 | export class ListPicker extends ListPickerBase {
|
6 | createNativeView() {
|
7 | return UIPickerView.new();
|
8 | }
|
9 | initNativeView() {
|
10 | super.initNativeView();
|
11 | this.nativeViewProtected.dataSource = this._dataSource = ListPickerDataSource.initWithOwner(new WeakRef(this));
|
12 | this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this));
|
13 | this.nativeViewProtected.delegate = this._delegate;
|
14 | }
|
15 | disposeNativeView() {
|
16 | this._dataSource = null;
|
17 | this._delegate = null;
|
18 | super.disposeNativeView();
|
19 | }
|
20 |
|
21 | get ios() {
|
22 | return this.nativeViewProtected;
|
23 | }
|
24 | [selectedIndexProperty.getDefault]() {
|
25 | return -1;
|
26 | }
|
27 | [selectedIndexProperty.setNative](value) {
|
28 | if (value >= 0) {
|
29 | this.ios.selectRowInComponentAnimated(value, 0, false);
|
30 | }
|
31 | }
|
32 | [itemsProperty.getDefault]() {
|
33 | return null;
|
34 | }
|
35 | [itemsProperty.setNative](value) {
|
36 | this.ios.reloadAllComponents();
|
37 |
|
38 | selectedIndexProperty.coerce(this);
|
39 | }
|
40 | [colorProperty.getDefault]() {
|
41 | return this.ios.tintColor;
|
42 | }
|
43 | [colorProperty.setNative](value) {
|
44 | this.ios.tintColor = value instanceof Color ? value.ios : value;
|
45 | }
|
46 | }
|
47 | var ListPickerDataSource = (function (_super) {
|
48 | __extends(ListPickerDataSource, _super);
|
49 | function ListPickerDataSource() {
|
50 | return _super !== null && _super.apply(this, arguments) || this;
|
51 | }
|
52 | ListPickerDataSource.initWithOwner = function (owner) {
|
53 | var dataSource = ListPickerDataSource.new();
|
54 | dataSource._owner = owner;
|
55 | return dataSource;
|
56 | };
|
57 | ListPickerDataSource.prototype.numberOfComponentsInPickerView = function (pickerView) {
|
58 | return 1;
|
59 | };
|
60 | ListPickerDataSource.prototype.pickerViewNumberOfRowsInComponent = function (pickerView, component) {
|
61 | var _a;
|
62 | var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.deref();
|
63 | return owner && owner.items ? owner.items.length : 0;
|
64 | };
|
65 | ListPickerDataSource.ObjCProtocols = [UIPickerViewDataSource];
|
66 | return ListPickerDataSource;
|
67 | }(NSObject));
|
68 | var ListPickerDelegateImpl = (function (_super) {
|
69 | __extends(ListPickerDelegateImpl, _super);
|
70 | function ListPickerDelegateImpl() {
|
71 | return _super !== null && _super.apply(this, arguments) || this;
|
72 | }
|
73 | ListPickerDelegateImpl.initWithOwner = function (owner) {
|
74 | var delegate = ListPickerDelegateImpl.new();
|
75 | delegate._owner = owner;
|
76 | return delegate;
|
77 | };
|
78 | ListPickerDelegateImpl.prototype.pickerViewAttributedTitleForRowForComponent = function (pickerView, row, component) {
|
79 | var _a, _b;
|
80 | var _c;
|
81 | var owner = (_c = this._owner) === null || _c === void 0 ? void 0 : _c.deref();
|
82 | if (owner) {
|
83 | var title = NSAttributedString.alloc().initWithStringAttributes(owner._getItemAsString(row), (_a = {}, _a[NSForegroundColorAttributeName] = pickerView.tintColor, _a));
|
84 | return title;
|
85 | }
|
86 | return NSAttributedString.alloc().initWithStringAttributes(row.toString(), (_b = {}, _b[NSForegroundColorAttributeName] = pickerView.tintColor, _b));
|
87 | };
|
88 | ListPickerDelegateImpl.prototype.pickerViewDidSelectRowInComponent = function (pickerView, row, component) {
|
89 | var _a;
|
90 | var owner = (_a = this._owner) === null || _a === void 0 ? void 0 : _a.deref();
|
91 | if (owner) {
|
92 | selectedIndexProperty.nativeValueChange(owner, row);
|
93 | owner.updateSelectedValue(row);
|
94 | }
|
95 | };
|
96 | ListPickerDelegateImpl.ObjCProtocols = [UIPickerViewDelegate];
|
97 | return ListPickerDelegateImpl;
|
98 | }(NSObject));
|
99 |
|
\ | No newline at end of file |