tns-core-modules
Version:
Telerik NativeScript Core Modules
88 lines (87 loc) • 3.4 kB
JavaScript
var common = require("./list-picker-common");
var types = require("utils/types");
global.moduleMerge(common, exports);
var ListPicker = (function (_super) {
__extends(ListPicker, _super);
function ListPicker() {
_super.call(this);
this._ios = new UIPickerView();
this._ios.dataSource = this._dataSource = ListPickerDataSource.initWithOwner(new WeakRef(this));
this._delegate = ListPickerDelegateImpl.initWithOwner(new WeakRef(this));
}
ListPicker.prototype.onLoaded = function () {
_super.prototype.onLoaded.call(this);
this._ios.delegate = this._delegate;
};
ListPicker.prototype.onUnloaded = function () {
this._ios.delegate = null;
_super.prototype.onUnloaded.call(this);
};
Object.defineProperty(ListPicker.prototype, "ios", {
get: function () {
return this._ios;
},
enumerable: true,
configurable: true
});
ListPicker.prototype._onSelectedIndexPropertyChanged = function (data) {
_super.prototype._onSelectedIndexPropertyChanged.call(this, data);
if (this.ios && types.isNumber(data.newValue)) {
this.ios.selectRowInComponentAnimated(data.newValue, 0, false);
}
};
ListPicker.prototype._onItemsPropertyChanged = function (data) {
if (this.ios) {
this.ios.reloadAllComponents();
}
this._updateSelectedIndexOnItemsPropertyChanged(data.newValue);
};
return ListPicker;
}(common.ListPicker));
exports.ListPicker = ListPicker;
var ListPickerDataSource = (function (_super) {
__extends(ListPickerDataSource, _super);
function ListPickerDataSource() {
_super.apply(this, arguments);
}
ListPickerDataSource.initWithOwner = function (owner) {
var dataSource = ListPickerDataSource.new();
dataSource._owner = owner;
return dataSource;
};
ListPickerDataSource.prototype.numberOfComponentsInPickerView = function (pickerView) {
return 1;
};
ListPickerDataSource.prototype.pickerViewNumberOfRowsInComponent = function (pickerView, component) {
var owner = this._owner.get();
return (owner && owner.items) ? owner.items.length : 0;
};
ListPickerDataSource.ObjCProtocols = [UIPickerViewDataSource];
return ListPickerDataSource;
}(NSObject));
var ListPickerDelegateImpl = (function (_super) {
__extends(ListPickerDelegateImpl, _super);
function ListPickerDelegateImpl() {
_super.apply(this, arguments);
}
ListPickerDelegateImpl.initWithOwner = function (owner) {
var delegate = ListPickerDelegateImpl.new();
delegate._owner = owner;
return delegate;
};
ListPickerDelegateImpl.prototype.pickerViewTitleForRowForComponent = function (pickerView, row, component) {
var owner = this._owner.get();
if (owner) {
return owner._getItemAsString(row);
}
return row.toString();
};
ListPickerDelegateImpl.prototype.pickerViewDidSelectRowInComponent = function (pickerView, row, component) {
var owner = this._owner.get();
if (owner) {
owner._onPropertyChangedFromNative(common.ListPicker.selectedIndexProperty, row);
}
};
ListPickerDelegateImpl.ObjCProtocols = [UIPickerViewDelegate];
return ListPickerDelegateImpl;
}(NSObject));