UNPKG

@radworks/nativescript-multi-select

Version:

NativeScript 7.0.6 multi select dialog

123 lines 6.02 kB
import { Application, Color } from '@nativescript/core'; export class MultiSelect { constructor() { this._selectedItems = new Array(); } show(options) { this._selectedIds = new java.util.ArrayList(); if (options.selectedItems && options.selectedItems instanceof Array) { this._selectedItems = options.selectedItems.filter(() => true); } const lists = this.lists(options.items.filter(() => true), options.displayLabel, options.bindValue); const MSSelect = new com.abdeveloper.library.MultiSelectDialog() .title(options.title) .titleSize(options.android ? options.android.titleSize ? options.android.titleSize : 25 : 25) .positiveText(options.confirmButtonText ? options.confirmButtonText : 'confirm') .positiveTextColor(options.android ? options.android.confirmButtonTextColor ? new Color(options.android.confirmButtonTextColor) .android : null : null) .negativeText(options.cancelButtonText ? options.cancelButtonText : 'cancel') .negativeTextColor(options.android ? options.android.cancelButtonTextColor ? new Color(options.android.cancelButtonTextColor) .android : null : null) .setMinSelectionLimit(0) .setMaxSelectionLimit(lists.size()) .preSelectIDsList(this._selectedIds) .multiSelectList(lists) .onSubmit(new com.abdeveloper.library.MultiSelectDialog.SubmitCallbackListener({ onSelected: (selectedIds, selectedNames, dataString) => { const items = new Array(); for (let i = 0; i < selectedIds.size(); i++) { let id = selectedIds.get(i); items.push(options.bindValue ? options.items[id][options.bindValue] : options.items[id]); } options.onConfirm(items); }, onCancel: () => { options.onCancel(); }, onItemSelected: (selectedId, name) => { const item = options.bindValue ? options.items[selectedId][options.bindValue] : options.items[selectedId]; options.onItemSelected(item); }, })); MSSelect.show(Application.android.startActivity.getSupportFragmentManager(), 'multiSelectDialog'); } lists(items, displayValue, bindValue) { const lists = new java.util.ArrayList(); items.forEach((item, index) => { let title; if (typeof item === 'string') { title = item; } else if (item instanceof Object) { title = item[displayValue]; } const id = new java.lang.Integer(index); const model = new com.abdeveloper.library.MultiSelectModel(id, title); lists.add(model); 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) { this._selectedIds.add(new java.lang.Integer(index)); } } }); return lists; } } 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.android.js.map