Created
May 3, 2017 11:02
-
-
Save ralfstx/a3d393a134d323fb8a4ba8a9837846ea to your computer and use it in GitHub Desktop.
Tabris 1.x compatible Picker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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