Skip to content

Commit fda32c2

Browse files
committed
Fix bug in select() and add getIndex()
A bug in select() didn't deselect previous values New getIndex() function to retrieve current value
1 parent 80bfeac commit fda32c2

File tree

1 file changed

+15
-6
lines changed
  • app/widgets/com.skypanther.segmentedcontrol/controllers

1 file changed

+15
-6
lines changed

app/widgets/com.skypanther.segmentedcontrol/controllers/widget.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ if (OS_ANDROID) {
2828
$.segCtrlButtonContainer.height = Ti.UI.FILL;
2929

3030
var callback = function () {}; // empty function as placeholder
31+
var selectedIndex = 0; // Stores the current selected index
3132

3233
var buttons = [];
3334
exports.init = function (labels, cb) {
@@ -138,6 +139,10 @@ exports.init = function (labels, cb) {
138139
}
139140
}
140141
});
142+
143+
// Save current value
144+
selectedIndex = clickedButton;
145+
141146
callback({
142147
index: clickedButton,
143148
source: {
@@ -161,14 +166,18 @@ function _unhighlight(btn) {
161166
}
162167
}
163168

169+
// Is an alias function
164170
exports.select = function (num) {
165-
var btnNumber = parseInt(num) || 0;
166-
_highlight(buttons[btnNumber]);
171+
exports.setIndex(num);
172+
};
173+
exports.getIndex = function () {
174+
return selectedIndex;
167175
};
168176
exports.setIndex = function (num) {
169-
var btnNumber = parseInt(num) || 0;
170-
exports.deselectAll();
171-
_highlight(buttons[btnNumber]);
177+
var btnNumber = parseInt(num) || 0;
178+
exports.deselectAll();
179+
_highlight(buttons[btnNumber]);
180+
selectedIndex = num;
172181
};
173182
exports.deselect = function (num) {
174183
var btnNumber = parseInt(num) || 0;
@@ -238,4 +247,4 @@ exports.enableAllButtons = function () {
238247
function onThreeDPDevice() {
239248
//if we are on a 3DP device (6+ or 6s+) we need to slightly adjust the button width
240249
return OS_IOS && parseInt(Ti.Platform.displayCaps.logicalDensityFactor) === 3;
241-
}
250+
}

0 commit comments

Comments
 (0)