Skip to content

Instantly share code, notes, and snippets.

@ralfstx
Created May 3, 2017 11:02
Show Gist options
  • Save ralfstx/a3d393a134d323fb8a4ba8a9837846ea to your computer and use it in GitHub Desktop.
Save ralfstx/a3d393a134d323fb8a4ba8a9837846ea to your computer and use it in GitHub Desktop.
Tabris 1.x compatible Picker
const tabris = require('tabris');
/**
* Tabris 1.x compatible Picker
* Does not include compatibility for events
*/
class Picker_1 extends tabris.Picker {
constructor(properties) {
super(Object.assign({
items: [],
itemText: item => item
}, properties));
console.log('itemText', this.itemText);
this.on('select', (event) => {
event.selection = this._items[event.index];
});
}
set itemText(itemText) {
this._itemText = (index) => itemText(this._items[index]);
}
get itemText() {
return this._itemText;
}
set items(items) {
this._items = items;
this.itemCount = items.length;
}
get items() {
return this._items;
}
set selection(selection) {
this.selectionIndex = Math.max(0, this._items.indexOf(selection));
}
get selection() {
return this._items[this.selectionIndex];
}
}
tabris.Picker_1 = Picker_1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment