Skip to content

Commit

Permalink
feat(android): parity for optionbar index (#13324)
Browse files Browse the repository at this point in the history
* feat(android): parity for optionbar index

* update docs and example
  • Loading branch information
m1ga authored Mar 25, 2022
1 parent 713f612 commit af7371b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ private void checkOption(int index)
((Checkable) view).setChecked(true);
this.isIgnoringCheckEvent = oldValue;
}
} else if (index == -1) {
// unselect all
getButtonGroup().clearChecked();
}
}
}
Expand Down Expand Up @@ -231,7 +234,6 @@ private void onButtonChecked(ViewGroup viewGroup, int viewId, boolean isChecked)
if (((Checkable) childView).isChecked()) {
// Update the proxy's "index" property.
this.proxy.setProperty(TiC.PROPERTY_INDEX, index);

// Fire a "click" event for selected option.
if (!this.isIgnoringCheckEvent) {
KrollDict data = new KrollDict();
Expand Down
11 changes: 10 additions & 1 deletion apidoc/Titanium/UI/OptionBar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ events:
properties:
- name: index
summary: Index of the currently selected option.
description: |
Index of the currently selected option. Setting this to `-1` will deselect all options.
type: Number

- name: labels
Expand Down Expand Up @@ -64,10 +66,17 @@ examples:
const optionBar = Ti.UI.createOptionBar({
labels: [ 'Option 1', 'Option 2', 'Option 3' ]
});
const btn = Ti.UI.createButton({
title:"reset", bottom: 10
})
optionBar.addEventListener('click', (e) => {
Ti.API.info(`Option ${e.index} was selected.`);
});
win.add(optionBar);
btn.addEventListener('click', (e) => {
optionBar.index = -1;
});
win.add([optionBar,btn]);
win.open();
```
Expand Down

0 comments on commit af7371b

Please sign in to comment.