Skip to content

Commit

Permalink
(hotfix) Use indexOf instead of latest item for cancel action. Refact…
Browse files Browse the repository at this point in the history
…orized action press callback
  • Loading branch information
brunocascio committed Apr 6, 2018
1 parent ecc5ca9 commit c0add09
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/Actions.js
Expand Up @@ -13,25 +13,20 @@ export default class Actions extends React.Component {
}

onActionsPress() {
const options = Object.keys(this.props.options);
const cancelButtonIndex = Object.keys(this.props.options).length - 1;
const { options } = this.props;
const optionKeys = Object.keys(options);
const cancelButtonIndex = optionKeys.indexOf('Cancel');
this.context.actionSheet().showActionSheetWithOptions(
{
options,
options: optionKeys,
cancelButtonIndex,
tintColor: this.props.optionTintColor,
},
(buttonIndex) => {
let i = 0;
Object.keys(this.props.options).forEach((key) => {
if (this.props.options[key]) {
if (buttonIndex === i) {
this.props.options[key](this.props);
return;
}
i += 1;
}
});
const key = optionKeys[buttonIndex];
if (key) {
options[key](this.props);
}
},
);
}
Expand Down

2 comments on commit c0add09

@SBIWebteam
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any plans on releasing this fix?

@keith-kurak
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, just ran into this, too, on latest - causes all of my menu options to be executed at once. If you could release it sometime, that'd be awesome. Thanks!

Please sign in to comment.