@radworks/nativescript-multi-select
Version:
NativeScript 7.0.6 multi select dialog
138 lines • 6.79 kB
JavaScript
import { Color } from "@nativescript/core";
export class MultiSelect {
constructor() {
this._selectedItems = new Array();
}
show(options) {
const self = rootVC();
this.MSSelect = AAMultiSelectViewController.alloc().init();
this.MSSelect.titleText = options.title;
this.MSSelect.view.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame) * .9, CGRectGetHeight(self.view.frame) * .9);
if (options.confirmButtonText) {
this.MSSelect.confirmButtonTitleText = options.confirmButtonText;
}
if (options.cancelButtonText) {
this.MSSelect.cancelButtonTitleText = options.cancelButtonText;
}
if (options.selectedItems && options.selectedItems instanceof Array) {
this._selectedItems = options.selectedItems.filter(() => true);
}
this.MSSelect.dataArray = this.dataArray(options.items.filter(() => true), options.displayLabel, options.bindValue);
this.MSSelect.confirmBlock = (selectedItems) => {
const items = new Array();
for (let i = 0; i < selectedItems.count; i++) {
let item = selectedItems.objectAtIndex(i);
items.push(options.bindValue ? options.items[item.multiSelectId][options.bindValue] : options.items[item.multiSelectId]);
}
options.onConfirm(items);
};
if (options.onItemSelected) {
this.MSSelect.selectedBlock = (item) => {
options.onItemSelected(options.bindValue ? options.items[item.multiSelectId][options.bindValue] : options.items[item.multiSelectId]);
};
}
if (options.onCancel) {
this.MSSelect.cancelBlock = (p1) => {
const mutableArray = NSMutableArray.array();
options.items.forEach((item, index) => {
const model = AAMultiSelectModel.new();
model.title = item;
model.isSelected = false;
model.multiSelectId = index;
mutableArray.addObject(model);
});
this.MSSelect.dataArray = mutableArray;
options.onCancel();
};
}
if (options.ios) {
const _ios = options.ios;
if (_ios.itemColor) {
this.MSSelect.itemTitleColor = new Color(_ios.itemColor).ios;
}
if (_ios.cancelButtonBgColor) {
this.MSSelect.cancelButtonBackgroudColor = new Color(_ios.cancelButtonBgColor).ios;
}
if (_ios.confirmButtonBgColor) {
this.MSSelect.confirmButtonBackgroudColor = new Color(_ios.confirmButtonBgColor).ios;
}
if (_ios.cancelButtonTextColor) {
this.MSSelect.cancelButtonTitleColor = new Color(_ios.cancelButtonTextColor).ios;
}
if (_ios.confirmButtonTextColor) {
this.MSSelect.confirmButtonTitleColor = new Color(_ios.confirmButtonTextColor).ios;
}
if (_ios.showType) {
this.MSSelect.popupShowType = _ios.showType;
}
if (_ios.dismissType) {
this.MSSelect.popupDismissType = _ios.dismissType;
}
}
this.MSSelect.show();
}
dataArray(items, displayValue, bindValue) {
const mutableArray = NSMutableArray.array();
items.forEach((item, index) => {
const model = AAMultiSelectModel.new();
if (typeof item === "string") {
model.title = item;
}
else if (item instanceof Object) {
model.title = item[displayValue];
}
if (this._selectedItems) {
let index;
if (bindValue) {
index = this._selectedItems.findIndex(sItem => sItem === item[bindValue]);
}
else {
index = this._selectedItems.findIndex(sItem => JSON.stringify(sItem) === JSON.stringify(item));
}
if (index >= 0) {
model.isSelected = true;
}
}
model.multiSelectId = index;
mutableArray.addObject(model);
});
return mutableArray;
}
}
const rootVC = function () {
let appwindow = UIApplication.sharedApplication.keyWindow;
return appwindow.rootViewController;
};
export var AShowType;
(function (AShowType) {
AShowType[AShowType["TypeNone"] = 0] = "TypeNone";
AShowType[AShowType["TypeFadeIn"] = 1] = "TypeFadeIn";
AShowType[AShowType["TypeGrowIn"] = 2] = "TypeGrowIn";
AShowType[AShowType["TypeShrinkIn"] = 3] = "TypeShrinkIn";
AShowType[AShowType["TypeSlideInFromTop"] = 4] = "TypeSlideInFromTop";
AShowType[AShowType["TypeSlideInFromBottom"] = 5] = "TypeSlideInFromBottom";
AShowType[AShowType["TypeSlideInFromLeft"] = 6] = "TypeSlideInFromLeft";
AShowType[AShowType["TypeSlideInFromRight"] = 7] = "TypeSlideInFromRight";
AShowType[AShowType["TypeBounceIn"] = 8] = "TypeBounceIn";
AShowType[AShowType["TypeBounceInFromTop"] = 9] = "TypeBounceInFromTop";
AShowType[AShowType["TypeBounceInFromBottom"] = 10] = "TypeBounceInFromBottom";
AShowType[AShowType["TypeBounceInFromLeft"] = 11] = "TypeBounceInFromLeft";
AShowType[AShowType["TypeBounceInFromRight"] = 12] = "TypeBounceInFromRight";
})(AShowType || (AShowType = {}));
export var ADismissType;
(function (ADismissType) {
ADismissType[ADismissType["TypeNone"] = 0] = "TypeNone";
ADismissType[ADismissType["TypeFadeOut"] = 1] = "TypeFadeOut";
ADismissType[ADismissType["TypeGrowOut"] = 2] = "TypeGrowOut";
ADismissType[ADismissType["TypeShrinkOut"] = 3] = "TypeShrinkOut";
ADismissType[ADismissType["TypeSlideOutToTop"] = 4] = "TypeSlideOutToTop";
ADismissType[ADismissType["TypeSlideOutToBottom"] = 5] = "TypeSlideOutToBottom";
ADismissType[ADismissType["TypeSlideOutToLeft"] = 6] = "TypeSlideOutToLeft";
ADismissType[ADismissType["TypeSlideOutToRight"] = 7] = "TypeSlideOutToRight";
ADismissType[ADismissType["TypeBounceOut"] = 8] = "TypeBounceOut";
ADismissType[ADismissType["TypeBounceOutToTop"] = 9] = "TypeBounceOutToTop";
ADismissType[ADismissType["TypeBounceOutToBottom"] = 10] = "TypeBounceOutToBottom";
ADismissType[ADismissType["TypeBounceOutToLeft"] = 11] = "TypeBounceOutToLeft";
ADismissType[ADismissType["TypeBounceOutToRight"] = 12] = "TypeBounceOutToRight";
})(ADismissType || (ADismissType = {}));
//# sourceMappingURL=multi-select.ios.js.map